Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/ndp/ndp.c
Context not available. | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <libxo/xo.h> | |||||
#include "gmt2local.h" | #include "gmt2local.h" | ||||
#define NEXTADDR(w, s) \ | #define NEXTADDR(w, s) \ | ||||
Context not available. | |||||
pid = getpid(); | pid = getpid(); | ||||
thiszone = gmt2local(0); | thiszone = gmt2local(0); | ||||
argc = xo_parse_args(argc, argv); | |||||
if (argc < 0) | |||||
exit(1); | |||||
atexit(xo_finish_atexit); | |||||
while ((ch = getopt(argc, argv, "acd:f:Ii:nprstA:HPR")) != -1) | while ((ch = getopt(argc, argv, "acd:f:Ii:nprstA:HPR")) != -1) | ||||
switch (ch) { | switch (ch) { | ||||
case 'a': | case 'a': | ||||
Context not available. | |||||
if_nametoindex(*argv)) | if_nametoindex(*argv)) | ||||
setdefif(*argv); | setdefif(*argv); | ||||
else | else | ||||
errx(1, "invalid interface %s", *argv); | xo_errx(1, "invalid interface %s", *argv); | ||||
} | } | ||||
getdefif(); /* always call it to print the result */ | getdefif(); /* always call it to print the result */ | ||||
break; | break; | ||||
#else | #else | ||||
errx(1, "not supported yet"); | xo_errx(1, "not supported yet"); | ||||
/*NOTREACHED*/ | /*NOTREACHED*/ | ||||
#endif | #endif | ||||
case 'p': | case 'p': | ||||
Context not available. | |||||
char line[100], arg[5][50], *args[5], *p; | char line[100], arg[5][50], *args[5], *p; | ||||
if ((fp = fopen(name, "r")) == NULL) | if ((fp = fopen(name, "r")) == NULL) | ||||
err(1, "cannot open %s", name); | xo_err(1, "cannot open %s", name); | ||||
args[0] = &arg[0][0]; | args[0] = &arg[0][0]; | ||||
args[1] = &arg[1][0]; | args[1] = &arg[1][0]; | ||||
args[2] = &arg[2][0]; | args[2] = &arg[2][0]; | ||||
Context not available. | |||||
i = sscanf(line, "%49s %49s %49s %49s %49s", | i = sscanf(line, "%49s %49s %49s %49s %49s", | ||||
arg[0], arg[1], arg[2], arg[3], arg[4]); | arg[0], arg[1], arg[2], arg[3], arg[4]); | ||||
if (i < 2) { | if (i < 2) { | ||||
warnx("bad line: %s", line); | xo_warnx("bad line: %s", line); | ||||
retval = 1; | retval = 1; | ||||
continue; | continue; | ||||
} | } | ||||
Context not available. | |||||
if (s < 0) { | if (s < 0) { | ||||
s = socket(PF_ROUTE, SOCK_RAW, 0); | s = socket(PF_ROUTE, SOCK_RAW, 0); | ||||
if (s < 0) { | if (s < 0) { | ||||
err(1, "socket"); | xo_err(1, "socket"); | ||||
/* NOTREACHED */ | /* NOTREACHED */ | ||||
} | } | ||||
} | } | ||||
Context not available. | |||||
hints.ai_family = AF_INET6; | hints.ai_family = AF_INET6; | ||||
gai_error = getaddrinfo(host, NULL, &hints, &res); | gai_error = getaddrinfo(host, NULL, &hints, &res); | ||||
if (gai_error) { | if (gai_error) { | ||||
fprintf(stderr, "ndp: %s: %s\n", host, | xo_warnx("ndp: %s: %s", host, gai_strerror(gai_error)); | ||||
gai_strerror(gai_error)); | |||||
return 1; | return 1; | ||||
} | } | ||||
sin->sin6_addr = ((struct sockaddr_in6 *)res->ai_addr)->sin6_addr; | sin->sin6_addr = ((struct sockaddr_in6 *)res->ai_addr)->sin6_addr; | ||||
Context not available. | |||||
argv++; | argv++; | ||||
} | } | ||||
if (rtmsg(RTM_GET) < 0) { | if (rtmsg(RTM_GET) < 0) { | ||||
errx(1, "RTM_GET(%s) failed", host); | xo_errx(1, "RTM_GET(%s) failed", host); | ||||
/* NOTREACHED */ | /* NOTREACHED */ | ||||
} | } | ||||
sin = (struct sockaddr_in6 *)(rtm + 1); | sin = (struct sockaddr_in6 *)(rtm + 1); | ||||
Context not available. | |||||
goto overwrite; | goto overwrite; | ||||
} | } | ||||
} | } | ||||
fprintf(stderr, "set: cannot configure a new entry\n"); | xo_warnx("set: cannot configure a new entry"); | ||||
return 1; | return 1; | ||||
} | } | ||||
overwrite: | overwrite: | ||||
if (sdl->sdl_family != AF_LINK) { | if (sdl->sdl_family != AF_LINK) { | ||||
printf("cannot intuit interface index and type for %s\n", host); | xo_warnx("cannot intuit interface index and type for %s", | ||||
host); | |||||
return (1); | return (1); | ||||
} | } | ||||
sdl_m.sdl_type = sdl->sdl_type; | sdl_m.sdl_type = sdl->sdl_type; | ||||
Context not available. | |||||
hints.ai_family = AF_INET6; | hints.ai_family = AF_INET6; | ||||
gai_error = getaddrinfo(host, NULL, &hints, &res); | gai_error = getaddrinfo(host, NULL, &hints, &res); | ||||
if (gai_error) { | if (gai_error) { | ||||
fprintf(stderr, "ndp: %s: %s\n", host, | xo_warnx("ndp: %s: %s", host, gai_strerror(gai_error)); | ||||
gai_strerror(gai_error)); | |||||
return; | return; | ||||
} | } | ||||
sin->sin6_addr = ((struct sockaddr_in6 *)res->ai_addr)->sin6_addr; | sin->sin6_addr = ((struct sockaddr_in6 *)res->ai_addr)->sin6_addr; | ||||
Context not available. | |||||
getnameinfo((struct sockaddr *)sin, sin->sin6_len, host_buf, | getnameinfo((struct sockaddr *)sin, sin->sin6_len, host_buf, | ||||
sizeof(host_buf), NULL ,0, | sizeof(host_buf), NULL ,0, | ||||
(nflag ? NI_NUMERICHOST : 0)); | (nflag ? NI_NUMERICHOST : 0)); | ||||
printf("%s (%s) -- no entry\n", host, host_buf); | xo_errx(1, "%s (%s) -- no entry", host, host_buf); | ||||
exit(1); | |||||
} | } | ||||
} | } | ||||
Context not available. | |||||
hints.ai_family = AF_INET6; | hints.ai_family = AF_INET6; | ||||
gai_error = getaddrinfo(host, NULL, &hints, &res); | gai_error = getaddrinfo(host, NULL, &hints, &res); | ||||
if (gai_error) { | if (gai_error) { | ||||
fprintf(stderr, "ndp: %s: %s\n", host, | xo_warnx("ndp: %s: %s", host, gai_strerror(gai_error)); | ||||
gai_strerror(gai_error)); | |||||
return 1; | return 1; | ||||
} | } | ||||
sin->sin6_addr = ((struct sockaddr_in6 *)res->ai_addr)->sin6_addr; | sin->sin6_addr = ((struct sockaddr_in6 *)res->ai_addr)->sin6_addr; | ||||
Context not available. | |||||
sin->sin6_scope_id = | sin->sin6_scope_id = | ||||
((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id; | ((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id; | ||||
if (rtmsg(RTM_GET) < 0) { | if (rtmsg(RTM_GET) < 0) { | ||||
errx(1, "RTM_GET(%s) failed", host); | xo_errx(1, "RTM_GET(%s) failed", host); | ||||
/* NOTREACHED */ | /* NOTREACHED */ | ||||
} | } | ||||
sin = (struct sockaddr_in6 *)(rtm + 1); | sin = (struct sockaddr_in6 *)(rtm + 1); | ||||
Context not available. | |||||
!(rtm->rtm_flags & RTF_GATEWAY)) { | !(rtm->rtm_flags & RTF_GATEWAY)) { | ||||
goto delete; | goto delete; | ||||
} | } | ||||
fprintf(stderr, "delete: cannot delete non-NDP entry\n"); | xo_warnx("delete: cannot delete non-NDP entry"); | ||||
return 1; | return 1; | ||||
} | } | ||||
delete: | delete: | ||||
if (sdl->sdl_family != AF_LINK) { | if (sdl->sdl_family != AF_LINK) { | ||||
printf("cannot locate %s\n", host); | xo_warnx("cannot locate %s", host); | ||||
return (1); | return (1); | ||||
} | } | ||||
/* | /* | ||||
Context not available. | |||||
sin->sin6_len, host_buf, | sin->sin6_len, host_buf, | ||||
sizeof(host_buf), NULL, 0, | sizeof(host_buf), NULL, 0, | ||||
(nflag ? NI_NUMERICHOST : 0)); | (nflag ? NI_NUMERICHOST : 0)); | ||||
printf("%s (%s) deleted\n", host, host_buf); | xo_warnx("%s (%s) deleted", host, host_buf); | ||||
} | } | ||||
return 0; | return 0; | ||||
Context not available. | |||||
char flgbuf[8]; | char flgbuf[8]; | ||||
char *ifname; | char *ifname; | ||||
xo_open_container("ndp-entries"); | |||||
if (repeat) { | |||||
xo_open_list("repeat"); | |||||
xo_open_instance("repeat"); | |||||
} | |||||
xo_open_list("neighbor-entry"); | |||||
/* Print header */ | /* Print header */ | ||||
if (!tflag && !cflag) | if (!tflag && !cflag) | ||||
printf("%-*.*s %-*.*s %*.*s %-9.9s %1s %5s\n", | xo_emit("{T:/%-*.*s} {T:/%-*.*s} {T:/%*.*s} {T:/%-9.9s}" | ||||
W_ADDR, W_ADDR, "Neighbor", W_LL, W_LL, "Linklayer Address", | " {T:/%1s} {T:/%5s}\n", | ||||
W_IF, W_IF, "Netif", "Expire", "S", "Flags"); | W_ADDR, W_ADDR, "Neighbor", W_LL, W_LL, | ||||
"Linklayer Address", W_IF, W_IF, "Netif", "Expire", "S", | |||||
"Flags"); | |||||
again:; | again:; | ||||
mib[0] = CTL_NET; | mib[0] = CTL_NET; | ||||
Context not available. | |||||
mib[5] = 0; | mib[5] = 0; | ||||
#endif | #endif | ||||
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) | if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) | ||||
err(1, "sysctl(PF_ROUTE estimate)"); | xo_err(1, "sysctl(PF_ROUTE estimate)"); | ||||
if (needed > 0) { | if (needed > 0) { | ||||
if ((buf = malloc(needed)) == NULL) | if ((buf = malloc(needed)) == NULL) | ||||
err(1, "malloc"); | xo_err(1, "malloc"); | ||||
if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) | if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) | ||||
err(1, "sysctl(PF_ROUTE, NET_RT_FLAGS)"); | xo_err(1, "sysctl(PF_ROUTE, NET_RT_FLAGS)"); | ||||
lim = buf + needed; | lim = buf + needed; | ||||
} else | } else | ||||
buf = lim = NULL; | buf = lim = NULL; | ||||
Context not available. | |||||
#endif | #endif | ||||
continue; | continue; | ||||
} | } | ||||
xo_open_instance("neighbor-entry"); | |||||
gettimeofday(&now, 0); | gettimeofday(&now, 0); | ||||
if (tflag) | if (tflag) | ||||
ts_print(&now); | ts_print(&now); | ||||
Context not available. | |||||
if (W_ADDR + W_LL + W_IF - addrwidth - llwidth > ifwidth) | if (W_ADDR + W_LL + W_IF - addrwidth - llwidth > ifwidth) | ||||
ifwidth = W_ADDR + W_LL + W_IF - addrwidth - llwidth; | ifwidth = W_ADDR + W_LL + W_IF - addrwidth - llwidth; | ||||
printf("%-*.*s %-*.*s %*.*s", addrwidth, addrwidth, host_buf, | xo_emit("{d:neighbor/%-*.*s}{e:neighbor}", | ||||
llwidth, llwidth, ether_str(sdl), ifwidth, ifwidth, ifname); | addrwidth, addrwidth, host_buf, host_buf); | ||||
xo_emit(" {d:linklayer-address/%-*.*s}{e:linklayer-address}", | |||||
llwidth, llwidth, ether_str(sdl), ether_str(sdl)); | |||||
xo_emit(" {d:interface/%*.*s}{e:interface}", | |||||
ifwidth, ifwidth, ifname, ifname); | |||||
/* Print neighbor discovery specific information */ | /* Print neighbor discovery specific information */ | ||||
expire = rtm->rtm_rmx.rmx_expire; | expire = rtm->rtm_rmx.rmx_expire; | ||||
if (expire > now.tv_sec) | if (expire > now.tv_sec) { | ||||
printf(" %-9.9s", sec2str(expire - now.tv_sec)); | char *sec = sec2str(expire - now.tv_sec); | ||||
else if (expire == 0) | |||||
printf(" %-9.9s", "permanent"); | xo_emit(" {d:expire/%-9.9s}{e:expire}", sec, sec); | ||||
} else if (expire == 0) | |||||
xo_emit(" {t:expire/%-9.9s}", "permanent"); | |||||
else | else | ||||
printf(" %-9.9s", "expired"); | xo_emit(" {t:expire/%-9.9s}", "expired"); | ||||
switch (rtm->rtm_rmx.rmx_state) { | switch (rtm->rtm_rmx.rmx_state) { | ||||
case ND6_LLINFO_NOSTATE: | case ND6_LLINFO_NOSTATE: | ||||
printf(" N"); | xo_emit(" {:state}{e:state_pretty}", "N", "nostate"); | ||||
break; | break; | ||||
#ifdef ND6_LLINFO_WAITDELETE | #ifdef ND6_LLINFO_WAITDELETE | ||||
case ND6_LLINFO_WAITDELETE: | case ND6_LLINFO_WAITDELETE: | ||||
printf(" W"); | xo_emit(" {:state}{e:state_pretty}", "W", | ||||
"waitdelete"); | |||||
break; | break; | ||||
#endif | #endif | ||||
case ND6_LLINFO_INCOMPLETE: | case ND6_LLINFO_INCOMPLETE: | ||||
printf(" I"); | xo_emit(" {:state}{e:state_pretty}", "I", | ||||
"incomplete"); | |||||
break; | break; | ||||
case ND6_LLINFO_REACHABLE: | case ND6_LLINFO_REACHABLE: | ||||
printf(" R"); | xo_emit(" {:state}{e:state_pretty}", "R", "reachable"); | ||||
break; | break; | ||||
case ND6_LLINFO_STALE: | case ND6_LLINFO_STALE: | ||||
printf(" S"); | xo_emit(" {:state}{e:state_pretty}", "S", "stale"); | ||||
break; | break; | ||||
case ND6_LLINFO_DELAY: | case ND6_LLINFO_DELAY: | ||||
printf(" D"); | xo_emit(" {:state}{e:state_pretty}", "D", "delay"); | ||||
break; | break; | ||||
case ND6_LLINFO_PROBE: | case ND6_LLINFO_PROBE: | ||||
printf(" P"); | xo_emit(" {:state}{e:state_pretty}", "P", "probe"); | ||||
break; | break; | ||||
default: | default: | ||||
printf(" ?"); | xo_emit(" {:state}{e:state_pretty}", "?", "unknown"); | ||||
break; | break; | ||||
} | } | ||||
Context not available. | |||||
(rtm->rtm_flags & RTF_ANNOUNCE) ? "p" : ""); | (rtm->rtm_flags & RTF_ANNOUNCE) ? "p" : ""); | ||||
#endif | #endif | ||||
} | } | ||||
printf(" %s", flgbuf); | xo_emit(" {:flags}", flgbuf); | ||||
if (isrouter) | |||||
xo_emit("{el:flags_pretty}", "router"); | |||||
if ((rtm->rtm_flags & RTF_ANNOUNCE)) | |||||
xo_emit("{el:flags_pretty}", "proxy"); | |||||
#if 0 /* W and P are mystery even for us */ | |||||
if ((rtm->rtm_addrs & RTA_NETMASK) != 0) { | |||||
sin = (struct sockaddr_in6 *) | |||||
(sdl->sdl_len + (char *)sdl); | |||||
if (!IN6_IS_ADDR_UNSPECIFIED(&sin->sin6_addr)) | |||||
xo_emit("{el:flags_pretty", "P"); | |||||
if ((sin->sin6_len != sizeof(struct sockaddr_in6))) | |||||
xo_emit("{el:flags_pretty}", "W"); | |||||
} | |||||
#endif | |||||
if (prbs) | if (prbs) | ||||
printf(" %d", prbs); | xo_emit(" {:prbs/%d}", prbs); | ||||
printf("\n"); | xo_emit("\n"); | ||||
xo_close_instance("neighbor-entry"); | |||||
} | } | ||||
if (buf != NULL) | if (buf != NULL) | ||||
free(buf); | free(buf); | ||||
if (repeat) { | if (repeat) { | ||||
printf("\n"); | xo_emit("\n"); | ||||
fflush(stdout); | xo_close_list("neighbor-entry"); | ||||
xo_close_instance("repeat"); | |||||
xo_flush(); | |||||
sleep(repeat); | sleep(repeat); | ||||
xo_open_instance("repeat"); | |||||
xo_open_list("neighbor-entry"); | |||||
goto again; | goto again; | ||||
} | } | ||||
xo_close_list("neighbor-entry"); | |||||
if (repeat) { | |||||
xo_close_instance("repeat"); | |||||
xo_close_list("repeat"); | |||||
} | |||||
xo_close_container("ndp-entries"); | |||||
} | } | ||||
static struct in6_nbrinfo * | static struct in6_nbrinfo * | ||||
Context not available. | |||||
int s; | int s; | ||||
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) | if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) | ||||
err(1, "socket"); | xo_err(1, "socket"); | ||||
bzero(&nbi, sizeof(nbi)); | bzero(&nbi, sizeof(nbi)); | ||||
if_indextoname(ifindex, nbi.ifname); | if_indextoname(ifindex, nbi.ifname); | ||||
Context not available. | |||||
nbi.addr = *addr; | nbi.addr = *addr; | ||||
if (ioctl(s, SIOCGNBRINFO_IN6, (caddr_t)&nbi) < 0) { | if (ioctl(s, SIOCGNBRINFO_IN6, (caddr_t)&nbi) < 0) { | ||||
if (warning) | if (warning) | ||||
warn("ioctl(SIOCGNBRINFO_IN6)"); | xo_warn("ioctl(SIOCGNBRINFO_IN6)"); | ||||
close(s); | close(s); | ||||
return(NULL); | return(NULL); | ||||
} | } | ||||
Context not available. | |||||
i = sscanf(a, "%x:%x:%x:%x:%x:%x", &o[0], &o[1], &o[2], | i = sscanf(a, "%x:%x:%x:%x:%x:%x", &o[0], &o[1], &o[2], | ||||
&o[3], &o[4], &o[5]); | &o[3], &o[4], &o[5]); | ||||
if (i != 6) { | if (i != 6) { | ||||
fprintf(stderr, "ndp: invalid Ethernet address '%s'\n", a); | xo_warnx("ndp: invalid Ethernet address '%s'", a); | ||||
return (1); | return (1); | ||||
} | } | ||||
for (i = 0; i < 6; i++) | for (i = 0; i < 6; i++) | ||||
Context not available. | |||||
static void | static void | ||||
usage() | usage() | ||||
{ | { | ||||
printf("usage: ndp [-nt] hostname\n"); | xo_error("%s", | ||||
printf(" ndp [-nt] -a | -c | -p | -r | -H | -P | -R\n"); | "usage: ndp [-nt] hostname\n" | ||||
printf(" ndp [-nt] -A wait\n"); | " ndp [-nt] -a | -c | -p | -r | -H | -P | -R\n" | ||||
printf(" ndp [-nt] -d hostname\n"); | " ndp [-nt] -A wait\n" | ||||
printf(" ndp [-nt] -f filename\n"); | " ndp [-nt] -d hostname\n" | ||||
printf(" ndp [-nt] -i interface [flags...]\n"); | " ndp [-nt] -f filename\n" | ||||
" ndp [-nt] -i interface [flags...]\n" | |||||
#ifdef SIOCSDEFIFACE_IN6 | #ifdef SIOCSDEFIFACE_IN6 | ||||
printf(" ndp [-nt] -I [interface|delete]\n"); | " ndp [-nt] -I [interface|delete]\n" | ||||
#endif | #endif | ||||
printf(" ndp [-nt] -s nodename etheraddr [temp] [proxy]\n"); | " ndp [-nt] -s nodename etheraddr [temp] [proxy]\n"); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
Context not available. | |||||
switch (cmd) { | switch (cmd) { | ||||
default: | default: | ||||
fprintf(stderr, "ndp: internal wrong cmd\n"); | xo_errx(1, "ndp: internal wrong cmd"); | ||||
exit(1); | |||||
case RTM_ADD: | case RTM_ADD: | ||||
rtm->rtm_addrs |= RTA_GATEWAY; | rtm->rtm_addrs |= RTA_GATEWAY; | ||||
if (expire_time) { | if (expire_time) { | ||||
Context not available. | |||||
rtm->rtm_type = cmd; | rtm->rtm_type = cmd; | ||||
if ((rlen = write(s, (char *)&m_rtmsg, l)) < 0) { | if ((rlen = write(s, (char *)&m_rtmsg, l)) < 0) { | ||||
if (errno != ESRCH || cmd != RTM_DELETE) { | if (errno != ESRCH || cmd != RTM_DELETE) { | ||||
err(1, "writing to routing socket"); | xo_err(1, "writing to routing socket"); | ||||
/* NOTREACHED */ | /* NOTREACHED */ | ||||
} | } | ||||
} | } | ||||
Context not available. | |||||
l = read(s, (char *)&m_rtmsg, sizeof(m_rtmsg)); | l = read(s, (char *)&m_rtmsg, sizeof(m_rtmsg)); | ||||
} while (l > 0 && (rtm->rtm_seq != seq || rtm->rtm_pid != pid)); | } while (l > 0 && (rtm->rtm_seq != seq || rtm->rtm_pid != pid)); | ||||
if (l < 0) | if (l < 0) | ||||
(void) fprintf(stderr, "ndp: read from routing socket: %s\n", | xo_warnx("ndp: read from routing socket: %s", strerror(errno)); | ||||
strerror(errno)); | |||||
return (0); | return (0); | ||||
} | } | ||||
Context not available. | |||||
#endif | #endif | ||||
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { | if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { | ||||
err(1, "socket"); | xo_err(1, "socket"); | ||||
/* NOTREACHED */ | /* NOTREACHED */ | ||||
} | } | ||||
bzero(&nd, sizeof(nd)); | bzero(&nd, sizeof(nd)); | ||||
strlcpy(nd.ifname, ifname, sizeof(nd.ifname)); | strlcpy(nd.ifname, ifname, sizeof(nd.ifname)); | ||||
if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&nd) < 0) { | if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&nd) < 0) { | ||||
err(1, "ioctl(SIOCGIFINFO_IN6)"); | xo_err(1, "ioctl(SIOCGIFINFO_IN6)"); | ||||
/* NOTREACHED */ | /* NOTREACHED */ | ||||
} | } | ||||
#define ND nd.ndi | #define ND nd.ndi | ||||
Context not available. | |||||
if (strncmp(cp, f, strlen(f)) == 0) { \ | if (strncmp(cp, f, strlen(f)) == 0) { \ | ||||
valptr = strchr(cp, '='); \ | valptr = strchr(cp, '='); \ | ||||
if (valptr == NULL) \ | if (valptr == NULL) \ | ||||
err(1, "syntax error in %s field", (f)); \ | xo_err(1, "syntax error in %s field", (f)); \ | ||||
errno = 0; \ | errno = 0; \ | ||||
newval = strtoul(++valptr, NULL, 0); \ | newval = strtoul(++valptr, NULL, 0); \ | ||||
if (errno) \ | if (errno) \ | ||||
err(1, "syntax error in %s's value", (f)); \ | xo_err(1, "syntax error in %s's value", (f)); \ | ||||
v = newval; \ | v = newval; \ | ||||
} \ | } \ | ||||
} while (0) | } while (0) | ||||
Context not available. | |||||
ND.flags = newflags; | ND.flags = newflags; | ||||
if (ioctl(s, SIOCSIFINFO_IN6, (caddr_t)&nd) < 0) { | if (ioctl(s, SIOCSIFINFO_IN6, (caddr_t)&nd) < 0) { | ||||
err(1, "ioctl(SIOCSIFINFO_IN6)"); | xo_err(1, "ioctl(SIOCSIFINFO_IN6)"); | ||||
/* NOTREACHED */ | /* NOTREACHED */ | ||||
} | } | ||||
#undef SETFLAG | #undef SETFLAG | ||||
Context not available. | |||||
} | } | ||||
if (!ND.initialized) { | if (!ND.initialized) { | ||||
errx(1, "%s: not initialized yet", ifname); | xo_errx(1, "%s: not initialized yet", ifname); | ||||
/* NOTREACHED */ | /* NOTREACHED */ | ||||
} | } | ||||
if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&nd) < 0) { | if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&nd) < 0) { | ||||
err(1, "ioctl(SIOCGIFINFO_IN6)"); | xo_err(1, "ioctl(SIOCGIFINFO_IN6)"); | ||||
/* NOTREACHED */ | /* NOTREACHED */ | ||||
} | } | ||||
printf("linkmtu=%d", ND.linkmtu); | |||||
printf(", maxmtu=%d", ND.maxmtu); | xo_open_container("nd-information"); | ||||
printf(", curhlim=%d", ND.chlim); | xo_emit("{L:linkmtu}={:link-mtu/%d}", ND.linkmtu); | ||||
printf(", basereachable=%ds%dms", | xo_emit(", {L:maxmtu}={:max-link-mtu/%d}", ND.maxmtu); | ||||
xo_emit(", {L:curhlim}={:current-hop-limit/%d}", ND.chlim); | |||||
xo_emit(", {L:basereachable}={:base-reachable-time/%ds%dms}", | |||||
ND.basereachable / 1000, ND.basereachable % 1000); | ND.basereachable / 1000, ND.basereachable % 1000); | ||||
printf(", reachable=%ds", ND.reachable); | xo_emit(", {L:reachable}={:reachable-time/%ds}", ND.reachable); | ||||
printf(", retrans=%ds%dms", ND.retrans / 1000, ND.retrans % 1000); | xo_emit(", {L:retrans}={:retrans-timer/%ds%dms}", ND.retrans / 1000, | ||||
ND.retrans % 1000); | |||||
#ifdef IPV6CTL_USETEMPADDR | #ifdef IPV6CTL_USETEMPADDR | ||||
memset(nullbuf, 0, sizeof(nullbuf)); | memset(nullbuf, 0, sizeof(nullbuf)); | ||||
if (memcmp(nullbuf, ND.randomid, sizeof(nullbuf)) != 0) { | if (memcmp(nullbuf, ND.randomid, sizeof(nullbuf)) != 0) { | ||||
int j; | int j; | ||||
u_int8_t *rbuf; | char rbuf[17]; | ||||
u_int8_t *rptr[] = { | |||||
ND.randomseed0, ND.randomseed1, ND.randomid | |||||
}; | |||||
for (i = 0; i < 3; i++) { | for (i = 0; i < 3; i++) { | ||||
for (j = 0; j < 8; j++) | |||||
snprintf(rbuf + j * 2, sizeof(rbuf) - j * 2, | |||||
"%02x", rptr[i][j]); | |||||
switch (i) { | switch (i) { | ||||
case 0: | case 0: | ||||
printf("\nRandom seed(0): "); | xo_emit("\n{[:-16}{Lc:Random seed(0)}{]:}" | ||||
rbuf = ND.randomseed0; | "{:random-seed-0}", rbuf); | ||||
break; | break; | ||||
case 1: | case 1: | ||||
printf("\nRandom seed(1): "); | xo_emit("\n{[:-16}{Lc:Random seed(1)}{]:}" | ||||
rbuf = ND.randomseed1; | "{:random-seed-1}", rbuf); | ||||
break; | break; | ||||
case 2: | case 2: | ||||
printf("\nRandom ID: "); | xo_emit("\n{[:-16}{Lc:Random ID}{]:}" | ||||
rbuf = ND.randomid; | "{:random-id}", rbuf); | ||||
break; | break; | ||||
default: | default: | ||||
errx(1, "impossible case for tempaddr display"); | xo_errx(1, | ||||
"impossible case for tempaddr display"); | |||||
} | } | ||||
for (j = 0; j < 8; j++) | |||||
printf("%02x", rbuf[j]); | |||||
} | } | ||||
} | } | ||||
#endif | #endif | ||||
if (ND.flags) { | if (ND.flags) { | ||||
printf("\nFlags: "); | xo_emit("\nFlags: "); | ||||
#ifdef ND6_IFF_IFDISABLED | #ifdef ND6_IFF_IFDISABLED | ||||
if ((ND.flags & ND6_IFF_IFDISABLED)) | if ((ND.flags & ND6_IFF_IFDISABLED)) | ||||
printf("disabled "); | xo_emit("{l:flags} ", "disabled"); | ||||
#endif | #endif | ||||
if ((ND.flags & ND6_IFF_PERFORMNUD)) | if ((ND.flags & ND6_IFF_PERFORMNUD)) | ||||
printf("nud "); | xo_emit("{l:flags} ", "nud"); | ||||
#ifdef ND6_IFF_ACCEPT_RTADV | #ifdef ND6_IFF_ACCEPT_RTADV | ||||
if ((ND.flags & ND6_IFF_ACCEPT_RTADV)) | if ((ND.flags & ND6_IFF_ACCEPT_RTADV)) | ||||
printf("accept_rtadv "); | xo_emit("{l:flags} ", "accept_rtadv"); | ||||
#endif | #endif | ||||
#ifdef ND6_IFF_AUTO_LINKLOCAL | #ifdef ND6_IFF_AUTO_LINKLOCAL | ||||
if ((ND.flags & ND6_IFF_AUTO_LINKLOCAL)) | if ((ND.flags & ND6_IFF_AUTO_LINKLOCAL)) | ||||
printf("auto_linklocal "); | xo_emit("{l:flags} ", "auto_linklocal"); | ||||
#endif | #endif | ||||
#ifdef ND6_IFF_NO_PREFER_IFACE | #ifdef ND6_IFF_NO_PREFER_IFACE | ||||
if ((ND.flags & ND6_IFF_NO_PREFER_IFACE)) | if ((ND.flags & ND6_IFF_NO_PREFER_IFACE)) | ||||
printf("no_prefer_iface "); | xo_emit("{l:flags} ", "no_prefer_iface"); | ||||
#endif | #endif | ||||
} | } | ||||
putc('\n', stdout); | xo_emit("\n"); | ||||
xo_close_container("nd-information"); | |||||
#undef ND | #undef ND | ||||
close(s); | close(s); | ||||
Context not available. | |||||
struct timeval now; | struct timeval now; | ||||
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) { | if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) { | ||||
err(1, "sysctl(ICMPV6CTL_ND6_DRLIST)"); | xo_err(1, "sysctl(ICMPV6CTL_ND6_DRLIST)"); | ||||
/*NOTREACHED*/ | /*NOTREACHED*/ | ||||
} | } | ||||
if (l == 0) | if (l == 0) | ||||
Context not available. | |||||
return; | return; | ||||
buf = malloc(l); | buf = malloc(l); | ||||
if (!buf) { | if (!buf) { | ||||
err(1, "malloc"); | xo_err(1, "malloc"); | ||||
/*NOTREACHED*/ | /*NOTREACHED*/ | ||||
} | } | ||||
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) { | if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) { | ||||
err(1, "sysctl(ICMPV6CTL_ND6_DRLIST)"); | xo_err(1, "sysctl(ICMPV6CTL_ND6_DRLIST)"); | ||||
/*NOTREACHED*/ | /*NOTREACHED*/ | ||||
} | } | ||||
xo_open_container("default-router-list"); | |||||
xo_open_list("default-router-entry"); | |||||
ep = (struct in6_defrouter *)(buf + l); | ep = (struct in6_defrouter *)(buf + l); | ||||
for (p = (struct in6_defrouter *)buf; p < ep; p++) { | for (p = (struct in6_defrouter *)buf; p < ep; p++) { | ||||
int rtpref; | int rtpref; | ||||
xo_open_instance("default-router-entry"); | |||||
if (getnameinfo((struct sockaddr *)&p->rtaddr, | if (getnameinfo((struct sockaddr *)&p->rtaddr, | ||||
p->rtaddr.sin6_len, host_buf, sizeof(host_buf), NULL, 0, | p->rtaddr.sin6_len, host_buf, sizeof(host_buf), NULL, 0, | ||||
(nflag ? NI_NUMERICHOST : 0)) != 0) | (nflag ? NI_NUMERICHOST : 0)) != 0) | ||||
strlcpy(host_buf, "?", sizeof(host_buf)); | strlcpy(host_buf, "?", sizeof(host_buf)); | ||||
printf("%s if=%s", host_buf, | xo_emit("{:address} {L:if}={:interface}", host_buf, | ||||
if_indextoname(p->if_index, ifix_buf)); | if_indextoname(p->if_index, ifix_buf)); | ||||
printf(", flags=%s%s", | xo_emit(", {L:flags}={:flags/%s%s}", | ||||
p->flags & ND_RA_FLAG_MANAGED ? "M" : "", | p->flags & ND_RA_FLAG_MANAGED ? "M" : "", | ||||
p->flags & ND_RA_FLAG_OTHER ? "O" : ""); | p->flags & ND_RA_FLAG_OTHER ? "O" : ""); | ||||
if (p->flags & ND_RA_FLAG_MANAGED) | |||||
xo_emit("{el:flags_pretty}", "managed"); | |||||
if (p->flags & ND_RA_FLAG_OTHER) | |||||
xo_emit("{el:flags_pretty}", "other"); | |||||
rtpref = ((p->flags & ND_RA_FLAG_RTPREF_MASK) >> 3) & 0xff; | rtpref = ((p->flags & ND_RA_FLAG_RTPREF_MASK) >> 3) & 0xff; | ||||
printf(", pref=%s", rtpref_str[rtpref]); | xo_emit(", {L:pref}={:preference}", rtpref_str[rtpref]); | ||||
gettimeofday(&now, 0); | gettimeofday(&now, 0); | ||||
if (p->expire == 0) | if (p->expire == 0) | ||||
printf(", expire=Never\n"); | xo_emit(", {L:expire}={:expire}\n", "Never"); | ||||
else | else | ||||
printf(", expire=%s\n", | xo_emit(", {L:expire}={:expire}\n", | ||||
sec2str(p->expire - now.tv_sec)); | sec2str(p->expire - now.tv_sec)); | ||||
xo_close_instance("default-router-entry"); | |||||
} | } | ||||
free(buf); | free(buf); | ||||
xo_close_list("default-router-entry"); | |||||
xo_close_container("default-router-list"); | |||||
} | } | ||||
static void | static void | ||||
Context not available. | |||||
char namebuf[NI_MAXHOST]; | char namebuf[NI_MAXHOST]; | ||||
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) { | if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) { | ||||
err(1, "sysctl(ICMPV6CTL_ND6_PRLIST)"); | xo_err(1, "sysctl(ICMPV6CTL_ND6_PRLIST)"); | ||||
/*NOTREACHED*/ | /*NOTREACHED*/ | ||||
} | } | ||||
buf = malloc(l); | buf = malloc(l); | ||||
if (!buf) { | if (!buf) { | ||||
err(1, "malloc"); | xo_err(1, "malloc"); | ||||
/*NOTREACHED*/ | /*NOTREACHED*/ | ||||
} | } | ||||
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) { | if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) { | ||||
err(1, "sysctl(ICMPV6CTL_ND6_PRLIST)"); | xo_err(1, "sysctl(ICMPV6CTL_ND6_PRLIST)"); | ||||
/*NOTREACHED*/ | /*NOTREACHED*/ | ||||
} | } | ||||
xo_open_container("prefix-list"); | |||||
xo_open_list("prefix-entry"); | |||||
ep = (struct in6_prefix *)(buf + l); | ep = (struct in6_prefix *)(buf + l); | ||||
for (p = (struct in6_prefix *)buf; p < ep; p = n) { | for (p = (struct in6_prefix *)buf; p < ep; p = n) { | ||||
advrtr = (struct sockaddr_in6 *)(p + 1); | advrtr = (struct sockaddr_in6 *)(p + 1); | ||||
n = (struct in6_prefix *)&advrtr[p->advrtrs]; | n = (struct in6_prefix *)&advrtr[p->advrtrs]; | ||||
xo_open_instance("prefix-entry"); | |||||
if (getnameinfo((struct sockaddr *)&p->prefix, | if (getnameinfo((struct sockaddr *)&p->prefix, | ||||
p->prefix.sin6_len, namebuf, sizeof(namebuf), | p->prefix.sin6_len, namebuf, sizeof(namebuf), | ||||
NULL, 0, niflags) != 0) | NULL, 0, niflags) != 0) | ||||
strlcpy(namebuf, "?", sizeof(namebuf)); | strlcpy(namebuf, "?", sizeof(namebuf)); | ||||
printf("%s/%d if=%s\n", namebuf, p->prefixlen, | xo_emit("{q:prefix/%s%c%d} {L:if}={:interface}\n", namebuf, | ||||
if_indextoname(p->if_index, ifix_buf)); | '/', p->prefixlen, if_indextoname(p->if_index, ifix_buf)); | ||||
gettimeofday(&now, 0); | gettimeofday(&now, 0); | ||||
/* | /* | ||||
Context not available. | |||||
* meaning of fields, especially flags, is very different | * meaning of fields, especially flags, is very different | ||||
* by origin. notify the difference to the users. | * by origin. notify the difference to the users. | ||||
*/ | */ | ||||
printf("flags=%s%s%s%s%s", | xo_emit("{L:flags}={:flags/%s%s%s%s%s}", | ||||
p->raflags.onlink ? "L" : "", | p->raflags.onlink ? "L" : "", | ||||
p->raflags.autonomous ? "A" : "", | p->raflags.autonomous ? "A" : "", | ||||
(p->flags & NDPRF_ONLINK) != 0 ? "O" : "", | (p->flags & NDPRF_ONLINK) != 0 ? "O" : "", | ||||
Context not available. | |||||
"" | "" | ||||
#endif | #endif | ||||
); | ); | ||||
if (p->raflags.onlink) | |||||
xo_emit("{el:flags_pretty}", "onlink"); | |||||
if (p->raflags.autonomous) | |||||
xo_emit("{el:flags_pretty}", "autonomous"); | |||||
if ((p->flags & NDPRF_ONLINK) != 0) | |||||
xo_emit("{el:flags_pretty}", "ndprf_onlink"); | |||||
if ((p->flags & NDPRF_DETACHED) != 0) | |||||
xo_emit("{el:flags_pretty}", "ndprf_detached"); | |||||
#ifdef NDPRF_HOME | |||||
if ((p->flags & NDPRF_HOME) != 0) | |||||
xo_emit("{el:flags_pretty}", "ndprf_home"); | |||||
#endif | |||||
if (p->vltime == ND6_INFINITE_LIFETIME) | if (p->vltime == ND6_INFINITE_LIFETIME) | ||||
printf(" vltime=infinity"); | xo_emit(" {L:vltime}={:valid-lifetime}", "infinity"); | ||||
else | else | ||||
printf(" vltime=%lu", (unsigned long)p->vltime); | xo_emit(" {L:vltime}={:valid-lifetime/%lu}", | ||||
(unsigned long)p->vltime); | |||||
if (p->pltime == ND6_INFINITE_LIFETIME) | if (p->pltime == ND6_INFINITE_LIFETIME) | ||||
printf(", pltime=infinity"); | xo_emit(", {L:pltime}={:preferred-lifetime}", | ||||
"infinity"); | |||||
else | else | ||||
printf(", pltime=%lu", (unsigned long)p->pltime); | xo_emit(", {L:pltime}={:preferred-lifetime/%lu}", | ||||
(unsigned long)p->pltime); | |||||
if (p->expire == 0) | if (p->expire == 0) | ||||
printf(", expire=Never"); | xo_emit(", {L:expire}={:expire}", "Never"); | ||||
else if (p->expire >= now.tv_sec) | else if (p->expire >= now.tv_sec) | ||||
printf(", expire=%s", | xo_emit(", {L:expire}={:expire}", | ||||
sec2str(p->expire - now.tv_sec)); | sec2str(p->expire - now.tv_sec)); | ||||
else | else | ||||
printf(", expired"); | xo_emit(", {:expire}", "expired"); | ||||
printf(", ref=%d", p->refcnt); | xo_emit(", {L:ref}={:reference-count/%d}", p->refcnt); | ||||
printf("\n"); | xo_emit("\n"); | ||||
/* | /* | ||||
* "advertising router" list is meaningful only if the prefix | * "advertising router" list is meaningful only if the prefix | ||||
* information is from RA. | * information is from RA. | ||||
Context not available. | |||||
struct sockaddr_in6 *sin6; | struct sockaddr_in6 *sin6; | ||||
sin6 = advrtr; | sin6 = advrtr; | ||||
printf(" advertised by\n"); | xo_emit("{P: }advertised by\n"); | ||||
xo_open_list("advertised-by"); | |||||
for (j = 0; j < p->advrtrs; j++) { | for (j = 0; j < p->advrtrs; j++) { | ||||
struct in6_nbrinfo *nbi; | struct in6_nbrinfo *nbi; | ||||
xo_open_instance("advertised-by"); | |||||
if (getnameinfo((struct sockaddr *)sin6, | if (getnameinfo((struct sockaddr *)sin6, | ||||
sin6->sin6_len, namebuf, sizeof(namebuf), | sin6->sin6_len, namebuf, sizeof(namebuf), | ||||
NULL, 0, ninflags) != 0) | NULL, 0, ninflags) != 0) | ||||
strlcpy(namebuf, "?", sizeof(namebuf)); | strlcpy(namebuf, "?", sizeof(namebuf)); | ||||
printf(" %s", namebuf); | xo_emit("{P: }{:address}", namebuf); | ||||
nbi = getnbrinfo(&sin6->sin6_addr, | nbi = getnbrinfo(&sin6->sin6_addr, | ||||
p->if_index, 0); | p->if_index, 0); | ||||
Context not available. | |||||
case ND6_LLINFO_STALE: | case ND6_LLINFO_STALE: | ||||
case ND6_LLINFO_DELAY: | case ND6_LLINFO_DELAY: | ||||
case ND6_LLINFO_PROBE: | case ND6_LLINFO_PROBE: | ||||
printf(" (reachable)\n"); | xo_emit(" {d:/(reachable)}" | ||||
"{eq:reachable/yes}\n"); | |||||
break; | break; | ||||
default: | default: | ||||
printf(" (unreachable)\n"); | xo_emit(" {d:/(unreachable)}" | ||||
"{eq:reachable/no}\n"); | |||||
} | } | ||||
} else | } else | ||||
printf(" (no neighbor state)\n"); | xo_emit(" (no neighbor state)\n"); | ||||
xo_close_instance("advertised-by"); | |||||
sin6++; | sin6++; | ||||
} | } | ||||
xo_close_list("advertised-by"); | |||||
} else | } else | ||||
printf(" No advertising router\n"); | xo_emit(" No advertising router\n"); | ||||
} | } | ||||
free(buf); | free(buf); | ||||
xo_close_list("prefix-entry"); | |||||
xo_close_container("prefix-list"); | |||||
} | } | ||||
static void | static void | ||||
Context not available. | |||||
int s; | int s; | ||||
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) | if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) | ||||
err(1, "socket"); | xo_err(1, "socket"); | ||||
strlcpy(dummyif, "lo0", sizeof(dummyif)); /* dummy */ | strlcpy(dummyif, "lo0", sizeof(dummyif)); /* dummy */ | ||||
if (ioctl(s, SIOCSPFXFLUSH_IN6, (caddr_t)&dummyif) < 0) | if (ioctl(s, SIOCSPFXFLUSH_IN6, (caddr_t)&dummyif) < 0) | ||||
err(1, "ioctl(SIOCSPFXFLUSH_IN6)"); | xo_err(1, "ioctl(SIOCSPFXFLUSH_IN6)"); | ||||
} | } | ||||
static void | static void | ||||
Context not available. | |||||
int s; | int s; | ||||
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) | if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) | ||||
err(1, "socket"); | xo_err(1, "socket"); | ||||
strlcpy(dummyif, "lo0", sizeof(dummyif)); /* dummy */ | strlcpy(dummyif, "lo0", sizeof(dummyif)); /* dummy */ | ||||
if (ioctl(s, SIOCSRTRFLUSH_IN6, (caddr_t)&dummyif) < 0) | if (ioctl(s, SIOCSRTRFLUSH_IN6, (caddr_t)&dummyif) < 0) | ||||
err(1, "ioctl(SIOCSRTRFLUSH_IN6)"); | xo_err(1, "ioctl(SIOCSRTRFLUSH_IN6)"); | ||||
close(s); | close(s); | ||||
} | } | ||||
Context not available. | |||||
int s; | int s; | ||||
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) | if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) | ||||
err(1, "socket"); | xo_err(1, "socket"); | ||||
strlcpy(dummyif, "lo0", sizeof(dummyif)); /* dummy */ | strlcpy(dummyif, "lo0", sizeof(dummyif)); /* dummy */ | ||||
if (ioctl(s, SIOCSNDFLUSH_IN6, (caddr_t)&dummyif) < 0) | if (ioctl(s, SIOCSNDFLUSH_IN6, (caddr_t)&dummyif) < 0) | ||||
err(1, "ioctl(SIOCSNDFLUSH_IN6)"); | xo_err(1, "ioctl(SIOCSNDFLUSH_IN6)"); | ||||
close(s); | close(s); | ||||
} | } | ||||
Context not available. | |||||
ifindex = 0; | ifindex = 0; | ||||
else { | else { | ||||
if ((ifindex = if_nametoindex(ifname)) == 0) | if ((ifindex = if_nametoindex(ifname)) == 0) | ||||
err(1, "failed to resolve i/f index for %s", ifname); | xo_err(1, "failed to resolve i/f index for %s", | ||||
ifname); | |||||
} | } | ||||
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) | if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) | ||||
err(1, "socket"); | xo_err(1, "socket"); | ||||
strlcpy(ndifreq.ifname, "lo0", sizeof(ndifreq.ifname)); /* dummy */ | strlcpy(ndifreq.ifname, "lo0", sizeof(ndifreq.ifname)); /* dummy */ | ||||
ndifreq.ifindex = ifindex; | ndifreq.ifindex = ifindex; | ||||
if (ioctl(s, SIOCSDEFIFACE_IN6, (caddr_t)&ndifreq) < 0) | if (ioctl(s, SIOCSDEFIFACE_IN6, (caddr_t)&ndifreq) < 0) | ||||
err(1, "ioctl(SIOCSDEFIFACE_IN6)"); | xo_err(1, "ioctl(SIOCSDEFIFACE_IN6)"); | ||||
close(s); | close(s); | ||||
} | } | ||||
Context not available. | |||||
char ifname[IFNAMSIZ+8]; | char ifname[IFNAMSIZ+8]; | ||||
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) | if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) | ||||
err(1, "socket"); | xo_err(1, "socket"); | ||||
memset(&ndifreq, 0, sizeof(ndifreq)); | memset(&ndifreq, 0, sizeof(ndifreq)); | ||||
strlcpy(ndifreq.ifname, "lo0", sizeof(ndifreq.ifname)); /* dummy */ | strlcpy(ndifreq.ifname, "lo0", sizeof(ndifreq.ifname)); /* dummy */ | ||||
if (ioctl(s, SIOCGDEFIFACE_IN6, (caddr_t)&ndifreq) < 0) | if (ioctl(s, SIOCGDEFIFACE_IN6, (caddr_t)&ndifreq) < 0) | ||||
err(1, "ioctl(SIOCGDEFIFACE_IN6)"); | xo_err(1, "ioctl(SIOCGDEFIFACE_IN6)"); | ||||
xo_open_container("nd-default-interface"); | |||||
if (ndifreq.ifindex == 0) | if (ndifreq.ifindex == 0) | ||||
printf("No default interface.\n"); | xo_warnx("No default interface."); | ||||
else { | else { | ||||
if ((if_indextoname(ndifreq.ifindex, ifname)) == NULL) | if ((if_indextoname(ndifreq.ifindex, ifname)) == NULL) | ||||
err(1, "failed to resolve ifname for index %lu", | xo_err(1, "failed to resolve ifname for index %lu", | ||||
ndifreq.ifindex); | ndifreq.ifindex); | ||||
printf("ND default interface = %s\n", ifname); | xo_emit("{L:ND default interface} = {:interface}\n", ifname); | ||||
} | } | ||||
xo_close_container("nd-default-interface"); | |||||
close(s); | close(s); | ||||
} | } | ||||
Context not available. | |||||
/* Default */ | /* Default */ | ||||
s = (tvp->tv_sec + thiszone) % 86400; | s = (tvp->tv_sec + thiszone) % 86400; | ||||
(void)printf("%02d:%02d:%02d.%06u ", | xo_emit("{q:timestamp/%02d:%02d:%02d.%06u} ", | ||||
s / 3600, (s % 3600) / 60, s % 60, (u_int32_t)tvp->tv_usec); | s / 3600, (s % 3600) / 60, s % 60, (u_int32_t)tvp->tv_usec); | ||||
} | } | ||||
Context not available. |