Changeset View
Changeset View
Standalone View
Standalone View
sbin/ifconfig/ifconfig.c
Show First 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | |||||
static char *descr = NULL; | static char *descr = NULL; | ||||
static size_t descrlen = 64; | static size_t descrlen = 64; | ||||
#endif | #endif | ||||
static int setaddr; | static int setaddr; | ||||
static int setmask; | static int setmask; | ||||
static int doalias; | static int doalias; | ||||
static int clearaddr; | static int clearaddr; | ||||
int newaddr = 1; | int newaddr = 1; | ||||
int printifname = 0; | |||||
struct ifconfig_args global_args; | struct ifconfig_args global_args; | ||||
int exit_code = 0; | int exit_code = 0; | ||||
static char ifname_to_print[IFNAMSIZ]; /* Helper for printifnamemaybe() */ | |||||
/* Formatter Strings */ | /* Formatter Strings */ | ||||
char *f_inet, *f_inet6, *f_ether, *f_addr; | char *f_inet, *f_inet6, *f_ether, *f_addr; | ||||
#ifdef WITHOUT_NETLINK | #ifdef WITHOUT_NETLINK | ||||
static void list_interfaces_ioctl(struct ifconfig_args *args); | static void list_interfaces_ioctl(struct ifconfig_args *args); | ||||
static void status(struct ifconfig_args *args, const struct sockaddr_dl *sdl, | static void status(struct ifconfig_args *args, const struct sockaddr_dl *sdl, | ||||
struct ifaddrs *ifa); | struct ifaddrs *ifa); | ||||
#endif | #endif | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | usage(void) | ||||
" ifconfig [-j jail] interface create\n" | " ifconfig [-j jail] interface create\n" | ||||
" ifconfig [-j jail] -a %s[-d] [-m] [-u] [-v] [address_family]\n" | " ifconfig [-j jail] -a %s[-d] [-m] [-u] [-v] [address_family]\n" | ||||
" ifconfig [-j jail] -l [-d] [-u] [address_family]\n" | " ifconfig [-j jail] -l [-d] [-u] [address_family]\n" | ||||
" ifconfig [-j jail] %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); | ||||
} | } | ||||
static void | |||||
ifname_update(if_ctx *ctx, const char *name) | |||||
{ | |||||
strlcpy(ctx->_ifname_storage_ioctl, name, sizeof(ctx->_ifname_storage_ioctl)); | |||||
ctx->ifname = ctx->_ifname_storage_ioctl; | |||||
strlcpy(ifname_to_print, name, sizeof(ifname_to_print)); | |||||
} | |||||
void | void | ||||
ifcreate_ioctl(if_ctx *ctx, struct ifreq *ifr) | ifcreate_ioctl(if_ctx *ctx, struct ifreq *ifr) | ||||
{ | { | ||||
char ifname_orig[IFNAMSIZ]; | |||||
strlcpy(ifname_orig, ifr->ifr_name, sizeof(ifname_orig)); | |||||
if (ioctl(ctx->io_s, SIOCIFCREATE2, ifr) < 0) { | if (ioctl(ctx->io_s, SIOCIFCREATE2, ifr) < 0) { | ||||
switch (errno) { | switch (errno) { | ||||
case EEXIST: | case EEXIST: | ||||
errx(1, "interface %s already exists", ifr->ifr_name); | errx(1, "interface %s already exists", ifr->ifr_name); | ||||
default: | default: | ||||
err(1, "SIOCIFCREATE2 (%s)", ifr->ifr_name); | err(1, "SIOCIFCREATE2 (%s)", ifr->ifr_name); | ||||
} | } | ||||
} | } | ||||
if (strncmp(ifname_orig, ifr->ifr_name, sizeof(ifname_orig)) != 0) | |||||
ifname_update(ctx, ifr->ifr_name); | |||||
} | } | ||||
#ifdef WITHOUT_NETLINK | #ifdef WITHOUT_NETLINK | ||||
static int | static int | ||||
calcorders(struct ifaddrs *ifa, struct ifa_queue *q) | calcorders(struct ifaddrs *ifa, struct ifa_queue *q) | ||||
{ | { | ||||
struct ifaddrs *prev; | struct ifaddrs *prev; | ||||
struct ifa_order_elt *cur; | struct ifa_order_elt *cur; | ||||
▲ Show 20 Lines • Show All 177 Lines • ▼ Show 20 Lines | sortifaddrs(struct ifaddrs *list, | ||||
return (result); | return (result); | ||||
} | } | ||||
#endif | #endif | ||||
static void | static void | ||||
printifnamemaybe(void) | printifnamemaybe(void) | ||||
{ | { | ||||
if (printifname) | if (ifname_to_print[0] != '\0') | ||||
printf("%s\n", name); | printf("%s\n", ifname_to_print); | ||||
} | } | ||||
static void | static void | ||||
list_interfaces(struct ifconfig_args *args) | list_interfaces(struct ifconfig_args *args) | ||||
{ | { | ||||
#ifdef WITHOUT_NETLINK | #ifdef WITHOUT_NETLINK | ||||
list_interfaces_ioctl(args); | list_interfaces_ioctl(args); | ||||
#else | #else | ||||
▲ Show 20 Lines • Show All 1,100 Lines • ▼ Show 20 Lines | setifname(if_ctx *ctx, const char *val, int dummy __unused) | ||||
newname = strdup(val); | newname = strdup(val); | ||||
if (newname == NULL) | if (newname == NULL) | ||||
err(1, "no memory to set ifname"); | err(1, "no memory to set ifname"); | ||||
ifr.ifr_data = newname; | ifr.ifr_data = newname; | ||||
if (ioctl(ctx->io_s, SIOCSIFNAME, (caddr_t)&ifr) < 0) { | if (ioctl(ctx->io_s, SIOCSIFNAME, (caddr_t)&ifr) < 0) { | ||||
free(newname); | free(newname); | ||||
err(1, "ioctl SIOCSIFNAME (set name)"); | err(1, "ioctl SIOCSIFNAME (set name)"); | ||||
} | } | ||||
printifname = 1; | ifname_update(ctx, newname); | ||||
strlcpy(name, newname, sizeof(name)); | |||||
free(newname); | free(newname); | ||||
} | } | ||||
static void | static void | ||||
setifdescr(if_ctx *ctx, const char *val, int dummy __unused) | setifdescr(if_ctx *ctx, const char *val, int dummy __unused) | ||||
{ | { | ||||
char *newdescr; | char *newdescr; | ||||
▲ Show 20 Lines • Show All 505 Lines • Show Last 20 Lines |