Changeset View
Changeset View
Standalone View
Standalone View
head/sbin/ifconfig/ifconfig.c
Show First 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | |||||
/* Formatter Strings */ | /* Formatter Strings */ | ||||
char *f_inet, *f_inet6, *f_ether, *f_addr; | char *f_inet, *f_inet6, *f_ether, *f_addr; | ||||
static int ifconfig(int argc, char *const *argv, int iscreate, | static int ifconfig(int argc, char *const *argv, int iscreate, | ||||
const struct afswtch *afp); | const struct afswtch *afp); | ||||
static void status(const struct afswtch *afp, const struct sockaddr_dl *sdl, | static void status(const struct afswtch *afp, const struct sockaddr_dl *sdl, | ||||
struct ifaddrs *ifa); | struct ifaddrs *ifa); | ||||
static void tunnel_status(int s); | static void tunnel_status(int s); | ||||
static void usage(void); | static void usage(void) _Noreturn; | ||||
static struct afswtch *af_getbyname(const char *name); | static struct afswtch *af_getbyname(const char *name); | ||||
static struct afswtch *af_getbyfamily(int af); | static struct afswtch *af_getbyfamily(int af); | ||||
static void af_other_status(int); | static void af_other_status(int); | ||||
void printifnamemaybe(void); | void printifnamemaybe(void); | ||||
static struct option *opts = NULL; | static struct option *opts = NULL; | ||||
▲ Show 20 Lines • Show All 679 Lines • ▼ Show 20 Lines | while (argc > 0) { | ||||
} | } | ||||
if (p == NULL) { | if (p == NULL) { | ||||
/* | /* | ||||
* Not a recognized command, choose between setting | * Not a recognized command, choose between setting | ||||
* the interface address and the dst address. | * the interface address and the dst address. | ||||
*/ | */ | ||||
p = (setaddr ? &setifdstaddr_cmd : &setifaddr_cmd); | p = (setaddr ? &setifdstaddr_cmd : &setifaddr_cmd); | ||||
} | } | ||||
if (p->c_u.c_func || p->c_u.c_func2) { | if (p->c_parameter == NEXTARG && p->c_u.c_func) { | ||||
if (p->c_parameter == NEXTARG) { | |||||
if (argv[1] == NULL) | if (argv[1] == NULL) | ||||
errx(1, "'%s' requires argument", | errx(1, "'%s' requires argument", | ||||
p->c_name); | p->c_name); | ||||
p->c_u.c_func(argv[1], 0, s, afp); | p->c_u.c_func(argv[1], 0, s, afp); | ||||
argc--, argv++; | argc--, argv++; | ||||
} else if (p->c_parameter == OPTARG) { | } else if (p->c_parameter == OPTARG && p->c_u.c_func) { | ||||
p->c_u.c_func(argv[1], 0, s, afp); | p->c_u.c_func(argv[1], 0, s, afp); | ||||
if (argv[1] != NULL) | if (argv[1] != NULL) | ||||
argc--, argv++; | argc--, argv++; | ||||
} else if (p->c_parameter == NEXTARG2) { | } else if (p->c_parameter == NEXTARG2 && p->c_u.c_func2) { | ||||
if (argc < 3) | if (argc < 3) | ||||
errx(1, "'%s' requires 2 arguments", | errx(1, "'%s' requires 2 arguments", | ||||
p->c_name); | p->c_name); | ||||
p->c_u.c_func2(argv[1], argv[2], s, afp); | p->c_u.c_func2(argv[1], argv[2], s, afp); | ||||
argc -= 2, argv += 2; | argc -= 2, argv += 2; | ||||
} else | } else if (p->c_u.c_func) | ||||
p->c_u.c_func(*argv, p->c_parameter, s, afp); | p->c_u.c_func(*argv, p->c_parameter, s, afp); | ||||
} | |||||
argc--, argv++; | argc--, argv++; | ||||
} | } | ||||
/* | /* | ||||
* Do any post argument processing required by the address family. | * Do any post argument processing required by the address family. | ||||
*/ | */ | ||||
if (afp->af_postproc != NULL) | if (afp->af_postproc != NULL) | ||||
afp->af_postproc(s, afp); | afp->af_postproc(s, afp); | ||||
▲ Show 20 Lines • Show All 459 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
int i, any = 0; | int i, any = 0; | ||||
char c; | char c; | ||||
if (bits && *bits == 8) | if (bits && *bits == 8) | ||||
printf("%s=%o", s, v); | printf("%s=%o", s, v); | ||||
else | else | ||||
printf("%s=%x", s, v); | printf("%s=%x", s, v); | ||||
bits++; | |||||
if (bits) { | if (bits) { | ||||
bits++; | |||||
putchar('<'); | putchar('<'); | ||||
while ((i = *bits++) != '\0') { | while ((i = *bits++) != '\0') { | ||||
if (v & (1 << (i-1))) { | if (v & (1 << (i-1))) { | ||||
if (any) | if (any) | ||||
putchar(','); | putchar(','); | ||||
any = 1; | any = 1; | ||||
for (; (c = *bits) > 32; bits++) | for (; (c = *bits) > 32; bits++) | ||||
putchar(c); | putchar(c); | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | for (modid = kldfirstmod(fileid); modid > 0; | ||||
/* already loaded? */ | /* already loaded? */ | ||||
if (strcmp(ifname, cp) == 0 || | if (strcmp(ifname, cp) == 0 || | ||||
strcmp(ifkind, cp) == 0) | strcmp(ifkind, cp) == 0) | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
/* not present, we should try to load it */ | /* not present, we should try to load it */ | ||||
kldload(ifkind); | if (kldload(ifkind) < 0) | ||||
err(1, "kldload(%s)", ifkind); | |||||
} | } | ||||
static struct cmd basic_cmds[] = { | static struct cmd basic_cmds[] = { | ||||
DEF_CMD("up", IFF_UP, setifflags), | DEF_CMD("up", IFF_UP, setifflags), | ||||
DEF_CMD("down", -IFF_UP, setifflags), | DEF_CMD("down", -IFF_UP, setifflags), | ||||
DEF_CMD("arp", -IFF_NOARP, setifflags), | DEF_CMD("arp", -IFF_NOARP, setifflags), | ||||
DEF_CMD("-arp", IFF_NOARP, setifflags), | DEF_CMD("-arp", IFF_NOARP, setifflags), | ||||
DEF_CMD("debug", IFF_DEBUG, setifflags), | DEF_CMD("debug", IFF_DEBUG, setifflags), | ||||
▲ Show 20 Lines • Show All 84 Lines • Show Last 20 Lines |