Changeset View
Changeset View
Standalone View
Standalone View
head/sbin/ifconfig/ifconfig.c
Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | |||||
size_t descrlen = 64; | size_t descrlen = 64; | ||||
int setaddr; | int setaddr; | ||||
int setmask; | int setmask; | ||||
int doalias; | int doalias; | ||||
int clearaddr; | int clearaddr; | ||||
int newaddr = 1; | int newaddr = 1; | ||||
int verbose; | int verbose; | ||||
int noload; | int noload; | ||||
int printifname = 0; | |||||
int supmedia = 0; | int supmedia = 0; | ||||
int printkeys = 0; /* Print keying material for interfaces. */ | int printkeys = 0; /* Print keying material for interfaces. */ | ||||
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); | ||||
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); | |||||
static struct option *opts = NULL; | static struct option *opts = NULL; | ||||
struct ifa_order_elt { | struct ifa_order_elt { | ||||
int if_order; | int if_order; | ||||
int af_orders[255]; | int af_orders[255]; | ||||
struct ifaddrs *ifa; | struct ifaddrs *ifa; | ||||
TAILQ_ENTRY(ifa_order_elt) link; | TAILQ_ENTRY(ifa_order_elt) link; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 173 Lines • ▼ Show 20 Lines | else | ||||
tail->ifa_next = next; | tail->ifa_next = next; | ||||
tail = next; | tail = next; | ||||
} | } | ||||
return (result); | return (result); | ||||
} | } | ||||
void printifnamemaybe() | |||||
{ | |||||
if (printifname) | |||||
printf("%s\n", name); | |||||
} | |||||
int | int | ||||
main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||
{ | { | ||||
int c, all, namesonly, downonly, uponly; | int c, all, namesonly, downonly, uponly; | ||||
const struct afswtch *afp = NULL; | const struct afswtch *afp = NULL; | ||||
int ifindex; | int ifindex; | ||||
struct ifaddrs *ifap, *sifap, *ifa; | struct ifaddrs *ifap, *sifap, *ifa; | ||||
struct ifreq paifr; | struct ifreq paifr; | ||||
const struct sockaddr_dl *sdl; | const struct sockaddr_dl *sdl; | ||||
char options[1024], *cp, *namecp = NULL; | char options[1024], *cp, *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; | ||||
all = downonly = uponly = namesonly = noload = verbose = 0; | all = downonly = uponly = namesonly = noload = verbose = 0; | ||||
/* | |||||
* Ensure we print interface name when expected to, | |||||
* even if we terminate early due to error. | |||||
*/ | |||||
atexit(printifnamemaybe); | |||||
/* Parse leading line options */ | /* Parse leading line options */ | ||||
strlcpy(options, "adklmnuv", sizeof(options)); | strlcpy(options, "adklmnuv", 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 */ | ||||
all++; | all++; | ||||
▲ Show 20 Lines • Show All 680 Lines • ▼ Show 20 Lines | if (ioctl(s, SIOCSIFMTU, (caddr_t)&ifr) < 0) | ||||
err(1, "ioctl SIOCSIFMTU (set mtu)"); | err(1, "ioctl SIOCSIFMTU (set mtu)"); | ||||
} | } | ||||
static void | static void | ||||
setifname(const char *val, int dummy __unused, int s, | setifname(const char *val, int dummy __unused, int s, | ||||
const struct afswtch *afp) | const struct afswtch *afp) | ||||
{ | { | ||||
char *newname; | char *newname; | ||||
strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); | |||||
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(s, SIOCSIFNAME, (caddr_t)&ifr) < 0) { | if (ioctl(s, SIOCSIFNAME, (caddr_t)&ifr) < 0) { | ||||
free(newname); | free(newname); | ||||
err(1, "ioctl SIOCSIFNAME (set name)"); | err(1, "ioctl SIOCSIFNAME (set name)"); | ||||
} | } | ||||
printifname = 1; | |||||
strlcpy(name, newname, sizeof(name)); | strlcpy(name, newname, sizeof(name)); | ||||
free(newname); | free(newname); | ||||
} | } | ||||
/* ARGSUSED */ | /* ARGSUSED */ | ||||
static void | static void | ||||
setifdescr(const char *val, int dummy __unused, int s, | setifdescr(const char *val, int dummy __unused, int s, | ||||
const struct afswtch *afp) | const struct afswtch *afp) | ||||
{ | { | ||||
char *newdescr; | char *newdescr; | ||||
strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); | |||||
ifr.ifr_buffer.length = strlen(val) + 1; | ifr.ifr_buffer.length = strlen(val) + 1; | ||||
if (ifr.ifr_buffer.length == 1) { | if (ifr.ifr_buffer.length == 1) { | ||||
ifr.ifr_buffer.buffer = newdescr = NULL; | ifr.ifr_buffer.buffer = newdescr = NULL; | ||||
ifr.ifr_buffer.length = 0; | ifr.ifr_buffer.length = 0; | ||||
} else { | } else { | ||||
newdescr = strdup(val); | newdescr = strdup(val); | ||||
ifr.ifr_buffer.buffer = newdescr; | ifr.ifr_buffer.buffer = newdescr; | ||||
if (newdescr == NULL) { | if (newdescr == NULL) { | ||||
▲ Show 20 Lines • Show All 351 Lines • Show Last 20 Lines |