Changeset View
Changeset View
Standalone View
Standalone View
sbin/ifconfig/ifconfig.c
Show All 37 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/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> | ||||
#include <net/if.h> | #include <net/if.h> | ||||
Show All 9 Lines | |||||
#include <ifaddrs.h> | #include <ifaddrs.h> | ||||
#include <ctype.h> | #include <ctype.h> | ||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#ifdef JAIL | #ifdef JAIL | ||||
#include <jail.h> | #include <jail.h> | ||||
#include <nl_types.h> | |||||
#endif | #endif | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include "ifconfig.h" | #include "ifconfig.h" | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | opt_register(struct option *p) | ||||
opts = p; | opts = p; | ||||
} | } | ||||
static void | static void | ||||
usage(void) | usage(void) | ||||
{ | { | ||||
char options[1024]; | char options[1024]; | ||||
struct option *p; | struct option *p; | ||||
#ifdef JAIL | |||||
const char *jail = "[-j jail] "; | |||||
#else | |||||
const char *jail = ""; | |||||
#endif | |||||
/* 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 [-f type:format] %s%sinterface address_family\n" | ||||
" [address [dest_address]] [parameters]\n" | " [address [dest_address]] [parameters]\n" | ||||
" ifconfig interface create\n" | " ifconfig %sinterface create\n" | ||||
" ifconfig -a %s[-d] [-m] [-u] [-v] [address_family]\n" | " ifconfig -a %s[-d] %s[-m] [-u] [-v] [address_family]\n" | ||||
" ifconfig -l [-d] [-u] [address_family]\n" | " ifconfig -l [-d] %s[-u] [address_family]\n" | ||||
" ifconfig %s[-d] [-m] [-u] [-v]\n", | " ifconfig %s[-d] %s[-m] [-u] [-v]\n", | ||||
options, options, options); | jail, options, jail, options, jail, jail, options, jail); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
#define ORDERS_SIZE(x) sizeof(x) / sizeof(x[0]) | #define ORDERS_SIZE(x) sizeof(x) / sizeof(x[0]) | ||||
static int | static int | ||||
calcorders(struct ifaddrs *ifa, struct ifa_queue *q) | calcorders(struct ifaddrs *ifa, struct ifa_queue *q) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 197 Lines • ▼ Show 20 Lines | main(int argc, char *argv[]) | ||||
struct ifreq paifr; | struct ifreq paifr; | ||||
const struct sockaddr_dl *sdl; | const struct sockaddr_dl *sdl; | ||||
char options[1024], *cp, *envformat, *namecp = NULL; | char options[1024], *cp, *envformat, *namecp = NULL; | ||||
struct ifa_queue q = TAILQ_HEAD_INITIALIZER(q); | struct ifa_queue q = TAILQ_HEAD_INITIALIZER(q); | ||||
struct ifa_order_elt *cur, *tmp; | struct ifa_order_elt *cur, *tmp; | ||||
const char *ifname; | const char *ifname; | ||||
struct option *p; | struct option *p; | ||||
size_t iflen; | size_t iflen; | ||||
#ifdef JAIL | |||||
int jid; | |||||
jid = 0; | |||||
#endif | |||||
all = downonly = uponly = namesonly = noload = verbose = 0; | all = downonly = uponly = namesonly = noload = verbose = 0; | ||||
f_inet = f_inet6 = f_ether = f_addr = NULL; | f_inet = f_inet6 = f_ether = f_addr = NULL; | ||||
envformat = getenv("IFCONFIG_FORMAT"); | envformat = getenv("IFCONFIG_FORMAT"); | ||||
if (envformat != NULL) | if (envformat != NULL) | ||||
setformat(envformat); | setformat(envformat); | ||||
/* | /* | ||||
* Ensure we print interface name when expected to, | * Ensure we print interface name when expected to, | ||||
* even if we terminate early due to error. | * even if we terminate early due to error. | ||||
*/ | */ | ||||
atexit(printifnamemaybe); | atexit(printifnamemaybe); | ||||
/* Parse leading line options */ | /* Parse leading line options */ | ||||
#ifdef JAIL | |||||
strlcpy(options, "f:adj:klmnuv", sizeof(options)); | |||||
#else | |||||
strlcpy(options, "f:adklmnuv", sizeof(options)); | strlcpy(options, "f:adklmnuv", sizeof(options)); | ||||
#endif | |||||
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 */ | ||||
all++; | all++; | ||||
break; | break; | ||||
case 'd': /* restrict scan to "down" interfaces */ | case 'd': /* restrict scan to "down" interfaces */ | ||||
downonly++; | downonly++; | ||||
break; | break; | ||||
case 'f': | case 'f': | ||||
if (optarg == NULL) | if (optarg == NULL) | ||||
usage(); | usage(); | ||||
setformat(optarg); | setformat(optarg); | ||||
break; | break; | ||||
#ifdef JAIL | |||||
case 'j': | |||||
jid = jail_getid(optarg); | |||||
noload++; | |||||
break; | |||||
#endif | |||||
case 'k': | case 'k': | ||||
printkeys++; | printkeys++; | ||||
break; | break; | ||||
case 'l': /* scan interface names only */ | case 'l': /* scan interface names only */ | ||||
namesonly++; | namesonly++; | ||||
break; | break; | ||||
case 'm': /* show media choices in status */ | case 'm': /* show media choices in status */ | ||||
supmedia = 1; | supmedia = 1; | ||||
Show All 23 Lines | #endif | ||||
/* -l cannot be used with -a or -m */ | /* -l cannot be used with -a or -m */ | ||||
if (namesonly && (all || supmedia)) | if (namesonly && (all || supmedia)) | ||||
usage(); | usage(); | ||||
/* nonsense.. */ | /* nonsense.. */ | ||||
if (uponly && downonly) | if (uponly && downonly) | ||||
usage(); | usage(); | ||||
#ifdef JAIL | |||||
if (jid > 0) { | |||||
(void)catopen("libc", NL_CAT_LOCALE); | |||||
if (jail_attach(jid) == -1) { | |||||
if (errno == EINVAL) | |||||
errx(1, "jail does not exist"); | |||||
err(1, "jail_attach()"); | |||||
} | |||||
} else if (jid == -1) { | |||||
errx(1, "jail does not exist"); | |||||
} | |||||
#endif | |||||
/* no arguments is equivalent to '-a' */ | /* no arguments is equivalent to '-a' */ | ||||
if (!namesonly && argc < 1) | if (!namesonly && argc < 1) | ||||
all = 1; | all = 1; | ||||
/* -a and -l allow an address family arg to limit the output */ | /* -a and -l allow an address family arg to limit the output */ | ||||
if (all || namesonly) { | if (all || namesonly) { | ||||
if (argc > 1) | if (argc > 1) | ||||
▲ Show 20 Lines • Show All 1,026 Lines • Show Last 20 Lines |