- NI_WITHSCOPEID was deprecated
- use strlcpy() and snprintf() - use err() - style Obtained from: KAME
This commit is contained in:
parent
2f4c5de968
commit
a96bd7843f
@ -113,10 +113,6 @@
|
||||
#include <unistd.h>
|
||||
#include "gmt2local.h"
|
||||
|
||||
#ifndef NI_WITHSCOPEID
|
||||
#define NI_WITHSCOPEID 0
|
||||
#endif
|
||||
|
||||
/* packing rule for routing socket */
|
||||
#define ROUNDUP(a) \
|
||||
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
|
||||
@ -181,7 +177,7 @@ main(argc, argv)
|
||||
pid = getpid();
|
||||
thiszone = gmt2local(0);
|
||||
while ((ch = getopt(argc, argv, "acndfIilprstA:HPR")) != -1)
|
||||
switch ((char)ch) {
|
||||
switch (ch) {
|
||||
case 'a':
|
||||
aflag = 1;
|
||||
break;
|
||||
@ -316,7 +312,7 @@ file(name)
|
||||
args[3] = &arg[3][0];
|
||||
args[4] = &arg[4][0];
|
||||
retval = 0;
|
||||
while(fgets(line, 100, fp) != NULL) {
|
||||
while (fgets(line, 100, fp) != NULL) {
|
||||
i = sscanf(line, "%s %s %s %s %s", arg[0], arg[1], arg[2],
|
||||
arg[3], arg[4]);
|
||||
if (i < 2) {
|
||||
@ -337,8 +333,8 @@ getsocket()
|
||||
if (s < 0) {
|
||||
s = socket(PF_ROUTE, SOCK_RAW, 0);
|
||||
if (s < 0) {
|
||||
perror("ndp: socket");
|
||||
exit(1);
|
||||
err(1, "socket");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -386,7 +382,7 @@ set(argc, argv)
|
||||
#ifdef __KAME__
|
||||
if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr)) {
|
||||
*(u_int16_t *)&sin->sin6_addr.s6_addr[2] =
|
||||
htons(((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id);
|
||||
htons(((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id);
|
||||
}
|
||||
#endif
|
||||
ea = (u_char *)LLADDR(&sdl_m);
|
||||
@ -396,6 +392,7 @@ set(argc, argv)
|
||||
while (argc-- > 0) {
|
||||
if (strncmp(argv[0], "temp", 4) == 0) {
|
||||
struct timeval time;
|
||||
|
||||
gettimeofday(&time, 0);
|
||||
expire_time = time.tv_sec + 20 * 60;
|
||||
} else if (strncmp(argv[0], "proxy", 5) == 0)
|
||||
@ -403,8 +400,8 @@ set(argc, argv)
|
||||
argv++;
|
||||
}
|
||||
if (rtmsg(RTM_GET) < 0) {
|
||||
perror(host);
|
||||
return (1);
|
||||
errx(1, "RTM_GET(%s) failed", host);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
sin = (struct sockaddr_in6 *)(rtm + 1);
|
||||
sdl = (struct sockaddr_dl *)(ROUNDUP(sin->sin6_len) + (char *)sin);
|
||||
@ -450,21 +447,21 @@ get(host)
|
||||
gai_error = getaddrinfo(host, NULL, &hints, &res);
|
||||
if (gai_error) {
|
||||
fprintf(stderr, "ndp: %s: %s\n", host,
|
||||
gai_strerror(gai_error));
|
||||
gai_strerror(gai_error));
|
||||
return;
|
||||
}
|
||||
sin->sin6_addr = ((struct sockaddr_in6 *)res->ai_addr)->sin6_addr;
|
||||
#ifdef __KAME__
|
||||
if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr)) {
|
||||
*(u_int16_t *)&sin->sin6_addr.s6_addr[2] =
|
||||
htons(((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id);
|
||||
htons(((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id);
|
||||
}
|
||||
#endif
|
||||
dump(&sin->sin6_addr);
|
||||
if (found_entry == 0) {
|
||||
getnameinfo((struct sockaddr *)sin, sin->sin6_len, host_buf,
|
||||
sizeof(host_buf), NULL ,0,
|
||||
NI_WITHSCOPEID | (nflag ? NI_NUMERICHOST : 0));
|
||||
sizeof(host_buf), NULL ,0,
|
||||
(nflag ? NI_NUMERICHOST : 0));
|
||||
printf("%s (%s) -- no entry\n", host, host_buf);
|
||||
exit(1);
|
||||
}
|
||||
@ -491,19 +488,19 @@ delete(host)
|
||||
gai_error = getaddrinfo(host, NULL, &hints, &res);
|
||||
if (gai_error) {
|
||||
fprintf(stderr, "ndp: %s: %s\n", host,
|
||||
gai_strerror(gai_error));
|
||||
gai_strerror(gai_error));
|
||||
return 1;
|
||||
}
|
||||
sin->sin6_addr = ((struct sockaddr_in6 *)res->ai_addr)->sin6_addr;
|
||||
#ifdef __KAME__
|
||||
if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr)) {
|
||||
*(u_int16_t *)&sin->sin6_addr.s6_addr[2] =
|
||||
htons(((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id);
|
||||
htons(((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id);
|
||||
}
|
||||
#endif
|
||||
if (rtmsg(RTM_GET) < 0) {
|
||||
perror(host);
|
||||
return (1);
|
||||
errx(1, "RTM_GET(%s) failed", host);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
sin = (struct sockaddr_in6 *)(rtm + 1);
|
||||
sdl = (struct sockaddr_dl *)(ROUNDUP(sin->sin6_len) + (char *)sin);
|
||||
@ -535,9 +532,9 @@ delete(host)
|
||||
}
|
||||
#endif
|
||||
getnameinfo((struct sockaddr *)&s6,
|
||||
s6.sin6_len, host_buf,
|
||||
sizeof(host_buf), NULL, 0,
|
||||
NI_WITHSCOPEID | (nflag ? NI_NUMERICHOST : 0));
|
||||
s6.sin6_len, host_buf,
|
||||
sizeof(host_buf), NULL, 0,
|
||||
(nflag ? NI_NUMERICHOST : 0));
|
||||
printf("%s (%s) deleted\n", host, host_buf);
|
||||
}
|
||||
|
||||
@ -587,7 +584,7 @@ again:;
|
||||
err(1, "sysctl(PF_ROUTE estimate)");
|
||||
if (needed > 0) {
|
||||
if ((buf = malloc(needed)) == NULL)
|
||||
errx(1, "malloc");
|
||||
err(1, "malloc");
|
||||
if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
|
||||
err(1, "sysctl(PF_ROUTE, NET_RT_FLAGS)");
|
||||
lim = buf + needed;
|
||||
@ -608,7 +605,7 @@ again:;
|
||||
* lo0). Such routes entry would annoy getnbrinfo() below,
|
||||
* so we skip them.
|
||||
* XXX: such routes should have the GATEWAY flag, not the
|
||||
* LINK flag. However, there are rotten routing software
|
||||
* LINK flag. However, there is rotten routing software
|
||||
* that advertises all routes that have the GATEWAY flag.
|
||||
* Thus, KAME kernel intentionally does not set the LINK flag.
|
||||
* What is to be fixed is not ndp, but such routing software
|
||||
@ -634,8 +631,7 @@ again:;
|
||||
#endif
|
||||
}
|
||||
getnameinfo((struct sockaddr *)sin, sin->sin6_len, host_buf,
|
||||
sizeof(host_buf), NULL, 0,
|
||||
NI_WITHSCOPEID | (nflag ? NI_NUMERICHOST : 0));
|
||||
sizeof(host_buf), NULL, 0, (nflag ? NI_NUMERICHOST : 0));
|
||||
if (cflag == 1) {
|
||||
#ifdef RTF_WASCLONED
|
||||
if (rtm->rtm_flags & RTF_WASCLONED)
|
||||
@ -670,37 +666,37 @@ again:;
|
||||
if (nbi) {
|
||||
if (nbi->expire > time.tv_sec) {
|
||||
printf(" %-9.9s",
|
||||
sec2str(nbi->expire - time.tv_sec));
|
||||
sec2str(nbi->expire - time.tv_sec));
|
||||
} else if (nbi->expire == 0)
|
||||
printf(" %-9.9s", "permanent");
|
||||
else
|
||||
printf(" %-9.9s", "expired");
|
||||
|
||||
switch(nbi->state) {
|
||||
case ND6_LLINFO_NOSTATE:
|
||||
switch (nbi->state) {
|
||||
case ND6_LLINFO_NOSTATE:
|
||||
printf(" N");
|
||||
break;
|
||||
#ifdef ND6_LLINFO_WAITDELETE
|
||||
case ND6_LLINFO_WAITDELETE:
|
||||
case ND6_LLINFO_WAITDELETE:
|
||||
printf(" W");
|
||||
break;
|
||||
#endif
|
||||
case ND6_LLINFO_INCOMPLETE:
|
||||
case ND6_LLINFO_INCOMPLETE:
|
||||
printf(" I");
|
||||
break;
|
||||
case ND6_LLINFO_REACHABLE:
|
||||
case ND6_LLINFO_REACHABLE:
|
||||
printf(" R");
|
||||
break;
|
||||
case ND6_LLINFO_STALE:
|
||||
case ND6_LLINFO_STALE:
|
||||
printf(" S");
|
||||
break;
|
||||
case ND6_LLINFO_DELAY:
|
||||
case ND6_LLINFO_DELAY:
|
||||
printf(" D");
|
||||
break;
|
||||
case ND6_LLINFO_PROBE:
|
||||
case ND6_LLINFO_PROBE:
|
||||
printf(" P");
|
||||
break;
|
||||
default:
|
||||
default:
|
||||
printf(" ?");
|
||||
break;
|
||||
}
|
||||
@ -718,18 +714,16 @@ again:;
|
||||
*/
|
||||
if ((rtm->rtm_addrs & RTA_NETMASK) == 0) {
|
||||
snprintf(flgbuf, sizeof(flgbuf), "%s%s",
|
||||
isrouter ? "R" : "",
|
||||
(rtm->rtm_flags & RTF_ANNOUNCE) ? "p" : "");
|
||||
isrouter ? "R" : "",
|
||||
(rtm->rtm_flags & RTF_ANNOUNCE) ? "p" : "");
|
||||
} else {
|
||||
sin = (struct sockaddr_in6 *)
|
||||
(sdl->sdl_len + (char *)sdl);
|
||||
(sdl->sdl_len + (char *)sdl);
|
||||
snprintf(flgbuf, sizeof(flgbuf), "%s%s%s%s",
|
||||
isrouter ? "R" : "",
|
||||
!IN6_IS_ADDR_UNSPECIFIED(&sin->sin6_addr)
|
||||
? "P" : "",
|
||||
(sin->sin6_len != sizeof(struct sockaddr_in6))
|
||||
? "W" : "",
|
||||
(rtm->rtm_flags & RTF_ANNOUNCE) ? "p" : "");
|
||||
isrouter ? "R" : "",
|
||||
!IN6_IS_ADDR_UNSPECIFIED(&sin->sin6_addr) ? "P" : "",
|
||||
(sin->sin6_len != sizeof(struct sockaddr_in6)) ? "W" : "",
|
||||
(rtm->rtm_flags & RTF_ANNOUNCE) ? "p" : "");
|
||||
}
|
||||
printf(" %-4.4s", flgbuf);
|
||||
|
||||
@ -778,18 +772,17 @@ static char *
|
||||
ether_str(sdl)
|
||||
struct sockaddr_dl *sdl;
|
||||
{
|
||||
static char ebuf[32];
|
||||
static char hbuf[NI_MAXHOST];
|
||||
u_char *cp;
|
||||
|
||||
if (sdl->sdl_alen) {
|
||||
cp = (u_char *)LLADDR(sdl);
|
||||
sprintf(ebuf, "%x:%x:%x:%x:%x:%x",
|
||||
cp[0], cp[1], cp[2], cp[3], cp[4], cp[5]);
|
||||
} else {
|
||||
sprintf(ebuf, "(incomplete)");
|
||||
}
|
||||
snprintf(hbuf, sizeof(hbuf), "%x:%x:%x:%x:%x:%x",
|
||||
cp[0], cp[1], cp[2], cp[3], cp[4], cp[5]);
|
||||
} else
|
||||
snprintf(hbuf, sizeof(hbuf), "(incomplete)");
|
||||
|
||||
return(ebuf);
|
||||
return(hbuf);
|
||||
}
|
||||
|
||||
int
|
||||
@ -800,12 +793,12 @@ ndp_ether_aton(a, n)
|
||||
int i, o[6];
|
||||
|
||||
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) {
|
||||
fprintf(stderr, "ndp: invalid Ethernet address '%s'\n", a);
|
||||
return (1);
|
||||
}
|
||||
for (i=0; i<6; i++)
|
||||
for (i = 0; i < 6; i++)
|
||||
n[i] = o[i];
|
||||
return (0);
|
||||
}
|
||||
@ -882,8 +875,8 @@ rtmsg(cmd)
|
||||
rtm->rtm_type = cmd;
|
||||
if ((rlen = write(s, (char *)&m_rtmsg, l)) < 0) {
|
||||
if (errno != ESRCH || cmd != RTM_DELETE) {
|
||||
perror("writing to routing socket");
|
||||
return (-1);
|
||||
err(1, "writing to routing socket");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
do {
|
||||
@ -909,14 +902,14 @@ ifinfo(argc, argv)
|
||||
#endif
|
||||
|
||||
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
|
||||
perror("ndp: socket");
|
||||
exit(1);
|
||||
err(1, "socket");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
bzero(&nd, sizeof(nd));
|
||||
strcpy(nd.ifname, ifname);
|
||||
strlcpy(nd.ifname, ifname, sizeof(nd.ifname));
|
||||
if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&nd) < 0) {
|
||||
perror("ioctl (SIOCGIFINFO_IN6)");
|
||||
exit(1);
|
||||
err(1, "ioctl(SIOCGIFINFO_IN6)");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
#define ND nd.ndi
|
||||
newflags = ND.flags;
|
||||
@ -945,8 +938,8 @@ ifinfo(argc, argv)
|
||||
|
||||
ND.flags = newflags;
|
||||
if (ioctl(s, SIOCSIFINFO_FLAGS, (caddr_t)&nd) < 0) {
|
||||
perror("ioctl(SIOCSIFINFO_FLAGS)");
|
||||
exit(1);
|
||||
err(1, "ioctl(SIOCSIFINFO_FLAGS)");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
#undef SETFLAG
|
||||
}
|
||||
@ -954,7 +947,7 @@ ifinfo(argc, argv)
|
||||
printf("linkmtu=%d", ND.linkmtu);
|
||||
printf(", curhlim=%d", ND.chlim);
|
||||
printf(", basereachable=%ds%dms",
|
||||
ND.basereachable / 1000, ND.basereachable % 1000);
|
||||
ND.basereachable / 1000, ND.basereachable % 1000);
|
||||
printf(", reachable=%ds", ND.reachable);
|
||||
printf(", retrans=%ds%dms", ND.retrans / 1000, ND.retrans % 1000);
|
||||
#ifdef IPV6CTL_USETEMPADDR
|
||||
@ -964,7 +957,7 @@ ifinfo(argc, argv)
|
||||
u_int8_t *rbuf;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
switch(i) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
printf("\nRandom seed(0): ");
|
||||
rbuf = ND.randomseed0;
|
||||
@ -994,7 +987,7 @@ ifinfo(argc, argv)
|
||||
}
|
||||
putc('\n', stdout);
|
||||
#undef ND
|
||||
|
||||
|
||||
close(s);
|
||||
}
|
||||
|
||||
@ -1018,7 +1011,7 @@ rtrlist()
|
||||
}
|
||||
buf = malloc(l);
|
||||
if (!buf) {
|
||||
errx(1, "not enough core");
|
||||
err(1, "malloc");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) {
|
||||
@ -1032,23 +1025,23 @@ rtrlist()
|
||||
|
||||
if (getnameinfo((struct sockaddr *)&p->rtaddr,
|
||||
p->rtaddr.sin6_len, host_buf, sizeof(host_buf), NULL, 0,
|
||||
NI_WITHSCOPEID | (nflag ? NI_NUMERICHOST : 0)) != 0)
|
||||
(nflag ? NI_NUMERICHOST : 0)) != 0)
|
||||
strlcpy(host_buf, "?", sizeof(host_buf));
|
||||
|
||||
|
||||
printf("%s if=%s", host_buf,
|
||||
if_indextoname(p->if_index, ifix_buf));
|
||||
if_indextoname(p->if_index, ifix_buf));
|
||||
printf(", flags=%s%s",
|
||||
p->flags & ND_RA_FLAG_MANAGED ? "M" : "",
|
||||
p->flags & ND_RA_FLAG_OTHER ? "O" : "");
|
||||
p->flags & ND_RA_FLAG_MANAGED ? "M" : "",
|
||||
p->flags & ND_RA_FLAG_OTHER ? "O" : "");
|
||||
rtpref = ((p->flags & ND_RA_FLAG_RTPREF_MASK) >> 3) & 0xff;
|
||||
printf(", pref=%s", rtpref_str[rtpref]);
|
||||
|
||||
|
||||
gettimeofday(&time, 0);
|
||||
if (p->expire == 0)
|
||||
printf(", expire=Never\n");
|
||||
else
|
||||
printf(", expire=%s\n",
|
||||
sec2str(p->expire - time.tv_sec));
|
||||
sec2str(p->expire - time.tv_sec));
|
||||
}
|
||||
free(buf);
|
||||
#else
|
||||
@ -1057,15 +1050,15 @@ rtrlist()
|
||||
struct timeval time;
|
||||
|
||||
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
|
||||
perror("ndp: socket");
|
||||
exit(1);
|
||||
err(1, "socket");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
bzero(&dr, sizeof(dr));
|
||||
strcpy(dr.ifname, "lo0"); /* dummy */
|
||||
strlcpy(dr.ifname, "lo0", sizeof(dr.ifname)); /* dummy */
|
||||
if (ioctl(s, SIOCGDRLST_IN6, (caddr_t)&dr) < 0) {
|
||||
perror("ioctl (SIOCGDRLST_IN6)");
|
||||
exit(1);
|
||||
}
|
||||
err(1, "ioctl(SIOCGDRLST_IN6)");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
#define DR dr.defrouter[i]
|
||||
for (i = 0 ; DR.if_index && i < DRLSTSIZ ; i++) {
|
||||
struct sockaddr_in6 sin6;
|
||||
@ -1075,20 +1068,20 @@ rtrlist()
|
||||
sin6.sin6_len = sizeof(sin6);
|
||||
sin6.sin6_addr = DR.rtaddr;
|
||||
getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, host_buf,
|
||||
sizeof(host_buf), NULL, 0,
|
||||
NI_WITHSCOPEID | (nflag ? NI_NUMERICHOST : 0));
|
||||
|
||||
sizeof(host_buf), NULL, 0,
|
||||
(nflag ? NI_NUMERICHOST : 0));
|
||||
|
||||
printf("%s if=%s", host_buf,
|
||||
if_indextoname(DR.if_index, ifix_buf));
|
||||
if_indextoname(DR.if_index, ifix_buf));
|
||||
printf(", flags=%s%s",
|
||||
DR.flags & ND_RA_FLAG_MANAGED ? "M" : "",
|
||||
DR.flags & ND_RA_FLAG_OTHER ? "O" : "");
|
||||
DR.flags & ND_RA_FLAG_MANAGED ? "M" : "",
|
||||
DR.flags & ND_RA_FLAG_OTHER ? "O" : "");
|
||||
gettimeofday(&time, 0);
|
||||
if (DR.expire == 0)
|
||||
printf(", expire=Never\n");
|
||||
else
|
||||
printf(", expire=%s\n",
|
||||
sec2str(DR.expire - time.tv_sec));
|
||||
sec2str(DR.expire - time.tv_sec));
|
||||
}
|
||||
#undef DR
|
||||
close(s);
|
||||
@ -1105,13 +1098,8 @@ plist()
|
||||
struct sockaddr_in6 *advrtr;
|
||||
size_t l;
|
||||
struct timeval time;
|
||||
#ifdef NI_WITHSCOPEID
|
||||
const int niflags = NI_NUMERICHOST | NI_WITHSCOPEID;
|
||||
int ninflags = (nflag ? NI_NUMERICHOST : 0) | NI_WITHSCOPEID;
|
||||
#else
|
||||
const int niflags = NI_NUMERICHOST;
|
||||
int ninflags = nflag ? NI_NUMERICHOST : 0;
|
||||
#endif
|
||||
char namebuf[NI_MAXHOST];
|
||||
|
||||
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) {
|
||||
@ -1120,7 +1108,7 @@ plist()
|
||||
}
|
||||
buf = malloc(l);
|
||||
if (!buf) {
|
||||
errx(1, "not enough core");
|
||||
err(1, "malloc");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) {
|
||||
@ -1138,7 +1126,7 @@ plist()
|
||||
NULL, 0, niflags) != 0)
|
||||
strlcpy(namebuf, "?", sizeof(namebuf));
|
||||
printf("%s/%d if=%s\n", namebuf, p->prefixlen,
|
||||
if_indextoname(p->if_index, ifix_buf));
|
||||
if_indextoname(p->if_index, ifix_buf));
|
||||
|
||||
gettimeofday(&time, 0);
|
||||
/*
|
||||
@ -1146,16 +1134,16 @@ plist()
|
||||
* by origin. notify the difference to the users.
|
||||
*/
|
||||
printf("flags=%s%s%s%s%s",
|
||||
p->raflags.onlink ? "L" : "",
|
||||
p->raflags.autonomous ? "A" : "",
|
||||
(p->flags & NDPRF_ONLINK) != 0 ? "O" : "",
|
||||
(p->flags & NDPRF_DETACHED) != 0 ? "D" : "",
|
||||
p->raflags.onlink ? "L" : "",
|
||||
p->raflags.autonomous ? "A" : "",
|
||||
(p->flags & NDPRF_ONLINK) != 0 ? "O" : "",
|
||||
(p->flags & NDPRF_DETACHED) != 0 ? "D" : "",
|
||||
#ifdef NDPRF_HOME
|
||||
(p->flags & NDPRF_HOME) != 0 ? "H" : ""
|
||||
(p->flags & NDPRF_HOME) != 0 ? "H" : ""
|
||||
#else
|
||||
""
|
||||
""
|
||||
#endif
|
||||
);
|
||||
);
|
||||
if (p->vltime == ND6_INFINITE_LIFETIME)
|
||||
printf(" vltime=infinity");
|
||||
else
|
||||
@ -1168,7 +1156,7 @@ plist()
|
||||
printf(", expire=Never");
|
||||
else if (p->expire >= time.tv_sec)
|
||||
printf(", expire=%s",
|
||||
sec2str(p->expire - time.tv_sec));
|
||||
sec2str(p->expire - time.tv_sec));
|
||||
else
|
||||
printf(", expired");
|
||||
printf(", ref=%d", p->refcnt);
|
||||
@ -1192,10 +1180,10 @@ plist()
|
||||
strlcpy(namebuf, "?", sizeof(namebuf));
|
||||
printf(" %s", namebuf);
|
||||
|
||||
nbi = getnbrinfo(&sin6->sin6_addr, p->if_index,
|
||||
0);
|
||||
nbi = getnbrinfo(&sin6->sin6_addr,
|
||||
p->if_index, 0);
|
||||
if (nbi) {
|
||||
switch(nbi->state) {
|
||||
switch (nbi->state) {
|
||||
case ND6_LLINFO_REACHABLE:
|
||||
case ND6_LLINFO_STALE:
|
||||
case ND6_LLINFO_DELAY:
|
||||
@ -1221,15 +1209,15 @@ plist()
|
||||
gettimeofday(&time, 0);
|
||||
|
||||
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
|
||||
perror("ndp: socket");
|
||||
exit(1);
|
||||
err(1, "socket");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
bzero(&pr, sizeof(pr));
|
||||
strcpy(pr.ifname, "lo0"); /* dummy */
|
||||
strlcpy(pr.ifname, "lo0", sizeof(pr.ifname)); /* dummy */
|
||||
if (ioctl(s, SIOCGPRLST_IN6, (caddr_t)&pr) < 0) {
|
||||
perror("ioctl (SIOCGPRLST_IN6)");
|
||||
exit(1);
|
||||
}
|
||||
err(1, "ioctl(SIOCGPRLST_IN6)");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
#define PR pr.prefix[i]
|
||||
for (i = 0; PR.if_index && i < PRLSTSIZ ; i++) {
|
||||
struct sockaddr_in6 p6;
|
||||
@ -1253,7 +1241,7 @@ plist()
|
||||
u_int16_t linkid;
|
||||
|
||||
memcpy(&linkid, &p6.sin6_addr.s6_addr[2],
|
||||
sizeof(linkid));
|
||||
sizeof(linkid));
|
||||
linkid = ntohs(linkid);
|
||||
p6.sin6_scope_id = linkid;
|
||||
p6.sin6_addr.s6_addr[2] = 0;
|
||||
@ -1261,17 +1249,14 @@ plist()
|
||||
}
|
||||
|
||||
niflags = NI_NUMERICHOST;
|
||||
#ifdef __KAME__
|
||||
niflags |= NI_WITHSCOPEID;
|
||||
#endif
|
||||
if (getnameinfo((struct sockaddr *)&p6,
|
||||
sizeof(p6), namebuf, sizeof(namebuf),
|
||||
NULL, 0, niflags)) {
|
||||
sizeof(p6), namebuf, sizeof(namebuf),
|
||||
NULL, 0, niflags)) {
|
||||
warnx("getnameinfo failed");
|
||||
continue;
|
||||
}
|
||||
printf("%s/%d if=%s\n", namebuf, PR.prefixlen,
|
||||
if_indextoname(PR.if_index, ifix_buf));
|
||||
if_indextoname(PR.if_index, ifix_buf));
|
||||
|
||||
gettimeofday(&time, 0);
|
||||
/*
|
||||
@ -1280,24 +1265,24 @@ plist()
|
||||
*/
|
||||
#if 0
|
||||
printf(" %s",
|
||||
PR.origin == PR_ORIG_RA ? "" : "advertise: ");
|
||||
PR.origin == PR_ORIG_RA ? "" : "advertise: ");
|
||||
#endif
|
||||
#ifdef NDPRF_ONLINK
|
||||
printf("flags=%s%s%s%s%s",
|
||||
PR.raflags.onlink ? "L" : "",
|
||||
PR.raflags.autonomous ? "A" : "",
|
||||
(PR.flags & NDPRF_ONLINK) != 0 ? "O" : "",
|
||||
(PR.flags & NDPRF_DETACHED) != 0 ? "D" : "",
|
||||
PR.raflags.onlink ? "L" : "",
|
||||
PR.raflags.autonomous ? "A" : "",
|
||||
(PR.flags & NDPRF_ONLINK) != 0 ? "O" : "",
|
||||
(PR.flags & NDPRF_DETACHED) != 0 ? "D" : "",
|
||||
#ifdef NDPRF_HOME
|
||||
(PR.flags & NDPRF_HOME) != 0 ? "H" : ""
|
||||
(PR.flags & NDPRF_HOME) != 0 ? "H" : ""
|
||||
#else
|
||||
""
|
||||
""
|
||||
#endif
|
||||
);
|
||||
);
|
||||
#else
|
||||
printf("flags=%s%s",
|
||||
PR.raflags.onlink ? "L" : "",
|
||||
PR.raflags.autonomous ? "A" : "");
|
||||
PR.raflags.onlink ? "L" : "",
|
||||
PR.raflags.autonomous ? "A" : "");
|
||||
#endif
|
||||
if (PR.vltime == ND6_INFINITE_LIFETIME)
|
||||
printf(" vltime=infinity");
|
||||
@ -1311,7 +1296,7 @@ plist()
|
||||
printf(", expire=Never");
|
||||
else if (PR.expire >= time.tv_sec)
|
||||
printf(", expire=%s",
|
||||
sec2str(PR.expire - time.tv_sec));
|
||||
sec2str(PR.expire - time.tv_sec));
|
||||
else
|
||||
printf(", expired");
|
||||
#ifdef NDPRF_ONLINK
|
||||
@ -1357,22 +1342,22 @@ plist()
|
||||
sin6.sin6_addr = PR.advrtr[j];
|
||||
sin6.sin6_scope_id = PR.if_index; /* XXX */
|
||||
getnameinfo((struct sockaddr *)&sin6,
|
||||
sin6.sin6_len, host_buf,
|
||||
sizeof(host_buf), NULL, 0,
|
||||
NI_WITHSCOPEID | (nflag ? NI_NUMERICHOST : 0));
|
||||
sin6.sin6_len, host_buf,
|
||||
sizeof(host_buf), NULL, 0,
|
||||
(nflag ? NI_NUMERICHOST : 0));
|
||||
printf(" %s", host_buf);
|
||||
|
||||
nbi = getnbrinfo(&sin6.sin6_addr, PR.if_index,
|
||||
0);
|
||||
nbi = getnbrinfo(&sin6.sin6_addr,
|
||||
PR.if_index, 0);
|
||||
if (nbi) {
|
||||
switch(nbi->state) {
|
||||
case ND6_LLINFO_REACHABLE:
|
||||
case ND6_LLINFO_STALE:
|
||||
case ND6_LLINFO_DELAY:
|
||||
case ND6_LLINFO_PROBE:
|
||||
switch (nbi->state) {
|
||||
case ND6_LLINFO_REACHABLE:
|
||||
case ND6_LLINFO_STALE:
|
||||
case ND6_LLINFO_DELAY:
|
||||
case ND6_LLINFO_PROBE:
|
||||
printf(" (reachable)\n");
|
||||
break;
|
||||
default:
|
||||
default:
|
||||
printf(" (unreachable)\n");
|
||||
}
|
||||
} else
|
||||
@ -1380,7 +1365,7 @@ plist()
|
||||
}
|
||||
if (PR.advrtrs > DRLSTSIZ)
|
||||
printf(" and %d routers\n",
|
||||
PR.advrtrs - DRLSTSIZ);
|
||||
PR.advrtrs - DRLSTSIZ);
|
||||
} else
|
||||
printf(" No advertising router\n");
|
||||
}
|
||||
@ -1397,9 +1382,9 @@ pfx_flush()
|
||||
|
||||
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
|
||||
err(1, "socket");
|
||||
strcpy(dummyif, "lo0"); /* dummy */
|
||||
strlcpy(dummyif, "lo0", sizeof(dummyif)); /* dummy */
|
||||
if (ioctl(s, SIOCSPFXFLUSH_IN6, (caddr_t)&dummyif) < 0)
|
||||
err(1, "ioctl(SIOCSPFXFLUSH_IN6)");
|
||||
err(1, "ioctl(SIOCSPFXFLUSH_IN6)");
|
||||
}
|
||||
|
||||
void
|
||||
@ -1410,9 +1395,9 @@ rtr_flush()
|
||||
|
||||
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
|
||||
err(1, "socket");
|
||||
strcpy(dummyif, "lo0"); /* dummy */
|
||||
strlcpy(dummyif, "lo0", sizeof(dummyif)); /* dummy */
|
||||
if (ioctl(s, SIOCSRTRFLUSH_IN6, (caddr_t)&dummyif) < 0)
|
||||
err(1, "ioctl(SIOCSRTRFLUSH_IN6)");
|
||||
err(1, "ioctl(SIOCSRTRFLUSH_IN6)");
|
||||
|
||||
close(s);
|
||||
}
|
||||
@ -1425,9 +1410,9 @@ harmonize_rtr()
|
||||
|
||||
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
|
||||
err(1, "socket");
|
||||
strcpy(dummyif, "lo0"); /* dummy */
|
||||
strlcpy(dummyif, "lo0", sizeof(dummyif)); /* dummy */
|
||||
if (ioctl(s, SIOCSNDFLUSH_IN6, (caddr_t)&dummyif) < 0)
|
||||
err(1, "ioctl (SIOCSNDFLUSH_IN6)");
|
||||
err(1, "ioctl(SIOCSNDFLUSH_IN6)");
|
||||
|
||||
close(s);
|
||||
}
|
||||
@ -1450,11 +1435,11 @@ setdefif(ifname)
|
||||
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
|
||||
err(1, "socket");
|
||||
|
||||
strcpy(ndifreq.ifname, "lo0"); /* dummy */
|
||||
strlcpy(ndifreq.ifname, "lo0", sizeof(ndifreq.ifname)); /* dummy */
|
||||
ndifreq.ifindex = ifindex;
|
||||
|
||||
if (ioctl(s, SIOCSDEFIFACE_IN6, (caddr_t)&ndifreq) < 0)
|
||||
err(1, "ioctl (SIOCSDEFIFACE_IN6)");
|
||||
err(1, "ioctl(SIOCSDEFIFACE_IN6)");
|
||||
|
||||
close(s);
|
||||
}
|
||||
@ -1469,10 +1454,10 @@ getdefif()
|
||||
err(1, "socket");
|
||||
|
||||
memset(&ndifreq, 0, sizeof(ndifreq));
|
||||
strcpy(ndifreq.ifname, "lo0"); /* dummy */
|
||||
strlcpy(ndifreq.ifname, "lo0", sizeof(ndifreq.ifname)); /* dummy */
|
||||
|
||||
if (ioctl(s, SIOCGDEFIFACE_IN6, (caddr_t)&ndifreq) < 0)
|
||||
err(1, "ioctl (SIOCGDEFIFACE_IN6)");
|
||||
err(1, "ioctl(SIOCGDEFIFACE_IN6)");
|
||||
|
||||
if (ndifreq.ifindex == 0)
|
||||
printf("No default interface.\n");
|
||||
@ -1495,6 +1480,8 @@ sec2str(total)
|
||||
int days, hours, mins, secs;
|
||||
int first = 1;
|
||||
char *p = result;
|
||||
char *ep = &result[sizeof(result)];
|
||||
int n;
|
||||
|
||||
days = total / 3600 / 24;
|
||||
hours = (total / 3600) % 24;
|
||||
@ -1503,17 +1490,26 @@ sec2str(total)
|
||||
|
||||
if (days) {
|
||||
first = 0;
|
||||
p += sprintf(p, "%dd", days);
|
||||
n = snprintf(p, ep - p, "%dd", days);
|
||||
if (n < 0 || n >= ep - p)
|
||||
return "?";
|
||||
p += n;
|
||||
}
|
||||
if (!first || hours) {
|
||||
first = 0;
|
||||
p += sprintf(p, "%dh", hours);
|
||||
n = snprintf(p, ep - p, "%dh", hours);
|
||||
if (n < 0 || n >= ep - p)
|
||||
return "?";
|
||||
p += n;
|
||||
}
|
||||
if (!first || mins) {
|
||||
first = 0;
|
||||
p += sprintf(p, "%dm", mins);
|
||||
n = snprintf(p, ep - p, "%dm", mins);
|
||||
if (n < 0 || n >= ep - p)
|
||||
return "?";
|
||||
p += n;
|
||||
}
|
||||
sprintf(p, "%ds", secs);
|
||||
snprintf(p, ep - p, "%ds", secs);
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user