Changeset View
Changeset View
Standalone View
Standalone View
sbin/ifconfig/ifconfig.c
Show All 36 Lines | |||||
static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94"; | static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94"; | ||||
#endif | #endif | ||||
static const char rcsid[] = | static const char rcsid[] = | ||||
"$FreeBSD$"; | "$FreeBSD$"; | ||||
#endif /* not lint */ | #endif /* not lint */ | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/ioctl.h> | #include <sys/ioctl.h> | ||||
#ifdef JAIL | |||||
#include <sys/jail.h> | |||||
#endif | |||||
#include <sys/module.h> | #include <sys/module.h> | ||||
#include <sys/linker.h> | #include <sys/linker.h> | ||||
#include <sys/nv.h> | #include <sys/nv.h> | ||||
#include <sys/queue.h> | #include <sys/queue.h> | ||||
#include <sys/socket.h> | #include <sys/socket.h> | ||||
#include <sys/time.h> | #include <sys/time.h> | ||||
#include <net/ethernet.h> | #include <net/ethernet.h> | ||||
▲ Show 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | usage(void) | ||||
/* XXX not right but close enough for now */ | /* XXX not right but close enough for now */ | ||||
options[0] = '\0'; | options[0] = '\0'; | ||||
for (p = opts; p != NULL; p = p->next) { | for (p = opts; p != NULL; p = p->next) { | ||||
strlcat(options, p->opt_usage, sizeof(options)); | strlcat(options, p->opt_usage, sizeof(options)); | ||||
strlcat(options, " ", sizeof(options)); | strlcat(options, " ", sizeof(options)); | ||||
} | } | ||||
fprintf(stderr, | fprintf(stderr, | ||||
"usage: ifconfig [-f type:format] %sinterface address_family\n" | "usage: ifconfig [-j jail] [-f type:format] %sinterface address_family\n" | ||||
" [address [dest_address]] [parameters]\n" | " [address [dest_address]] [parameters]\n" | ||||
" ifconfig interface create\n" | " ifconfig [-j jail] interface create\n" | ||||
" ifconfig -a %s[-d] [-m] [-u] [-v] [address_family]\n" | " ifconfig [-j jail] -a %s[-d] [-m] [-u] [-v] [address_family]\n" | ||||
" ifconfig -l [-d] [-u] [address_family]\n" | " ifconfig [-j jail] -l [-d] [-u] [address_family]\n" | ||||
" ifconfig %s[-d] [-m] [-u] [-v]\n", | " ifconfig [-j jail] %s[-d] [-m] [-u] [-v]\n", | ||||
options, options, options); | options, options, options); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
void | void | ||||
ioctl_ifcreate(int s, struct ifreq *ifr) | ioctl_ifcreate(int s, struct ifreq *ifr) | ||||
{ | { | ||||
if (ioctl(s, SIOCIFCREATE2, ifr) < 0) { | if (ioctl(s, SIOCIFCREATE2, ifr) < 0) { | ||||
▲ Show 20 Lines • Show All 229 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
static void | static void | ||||
args_parse(struct ifconfig_args *args, int argc, char *argv[]) | args_parse(struct ifconfig_args *args, int argc, char *argv[]) | ||||
{ | { | ||||
char options[1024]; | char options[1024]; | ||||
struct option *p; | struct option *p; | ||||
int c; | int c; | ||||
#ifdef JAIL | |||||
int jid; | |||||
#endif | |||||
melifaro: Nit: this is not needed, args is zeroed by default. | |||||
/* Parse leading line options */ | /* Parse leading line options */ | ||||
strlcpy(options, "G:adf:klmnuv", sizeof(options)); | strlcpy(options, "G:adf:j:klmnuv", sizeof(options)); | ||||
for (p = opts; p != NULL; p = p->next) | for (p = opts; p != NULL; p = p->next) | ||||
strlcat(options, p->opt, sizeof(options)); | strlcat(options, p->opt, sizeof(options)); | ||||
while ((c = getopt(argc, argv, options)) != -1) { | while ((c = getopt(argc, argv, options)) != -1) { | ||||
switch (c) { | switch (c) { | ||||
case 'a': /* scan all interfaces */ | case 'a': /* scan all interfaces */ | ||||
args->all = true; | args->all = true; | ||||
break; | break; | ||||
case 'd': /* restrict scan to "down" interfaces */ | case 'd': /* restrict scan to "down" interfaces */ | ||||
args->downonly = true; | args->downonly = true; | ||||
break; | break; | ||||
case 'f': | case 'f': | ||||
if (optarg == NULL) | if (optarg == NULL) | ||||
usage(); | usage(); | ||||
setformat(optarg); | setformat(optarg); | ||||
break; | break; | ||||
case 'G': | case 'G': | ||||
if (optarg == NULL || args->all == 0) | if (optarg == NULL || args->all == 0) | ||||
usage(); | usage(); | ||||
args->nogroup = optarg; | args->nogroup = optarg; | ||||
break; | |||||
case 'j': | |||||
#ifdef JAIL | |||||
if (optarg == NULL) | |||||
usage(); | |||||
jid = jail_getid(optarg); | |||||
Done Inline ActionsThe following sounds more idiomatic to me: jid = jail_getid(optarg); Perror("1"); if (jail_attach(jid) != 0) Perror("2"); khng: The following sounds more idiomatic to me:
jid = jail_getid(optarg);
if (jid == -1)
Perror… | |||||
Done Inline ActionsGreat! I prefer that too just worry about breaking style. nyan_myuji.xyz: Great! I prefer that too just worry about breaking style. | |||||
if (jid == -1) | |||||
Perror("jail not found"); | |||||
if (jail_attach(jid) != 0) | |||||
Perror("cannot attach to jail"); | |||||
#endif | |||||
Not Done Inline ActionsDo we want #else Perror("not built with jail support") or leave j out of options when not #ifdef JAIL? emaste: Do we want
```
#else
Perror("not built with jail support")
```
or leave `j` out of options… | |||||
Not Done Inline ActionsMaybe perror() is easier since going the other way, we also need to have usage() #ifdef'd lwhsu: Maybe perror() is easier since going the other way, we also need to have usage() `#ifdef`'d | |||||
break; | break; | ||||
case 'k': | case 'k': | ||||
args->printkeys = true; | args->printkeys = true; | ||||
break; | break; | ||||
case 'l': /* scan interface names only */ | case 'l': /* scan interface names only */ | ||||
args->namesonly++; | args->namesonly++; | ||||
break; | break; | ||||
case 'm': /* show media choices in status */ | case 'm': /* show media choices in status */ | ||||
▲ Show 20 Lines • Show All 1,494 Lines • Show Last 20 Lines |
Nit: this is not needed, args is zeroed by default.