summaryrefslogtreecommitdiff
path: root/usr.sbin/ndp
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2002-06-02 01:31:15 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2002-06-02 01:31:15 +0000
commit03ec6dd58e3cc326c65d7ecc753b1c3b919238e9 (patch)
tree81071efba0605d27f25eb682c8ea527e5f177bbc /usr.sbin/ndp
parentc8c9ff7d3c71fcdb0d3861d60f2604aed6ec742c (diff)
KNF
Diffstat (limited to 'usr.sbin/ndp')
-rw-r--r--usr.sbin/ndp/ndp.c187
1 files changed, 93 insertions, 94 deletions
diff --git a/usr.sbin/ndp/ndp.c b/usr.sbin/ndp/ndp.c
index 620fb435743..9c651469569 100644
--- a/usr.sbin/ndp/ndp.c
+++ b/usr.sbin/ndp/ndp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ndp.c,v 1.18 2002/05/29 22:22:20 itojun Exp $ */
+/* $OpenBSD: ndp.c,v 1.19 2002/06/02 01:31:14 deraadt Exp $ */
/* $KAME: ndp.c,v 1.86 2002/05/26 01:16:10 itojun Exp $ */
/*
@@ -171,8 +171,8 @@ main(argc, argv)
char **argv;
{
int ch;
- int aflag = 0, dflag = 0, sflag = 0, Hflag = 0,
- pflag = 0, rflag = 0, Pflag = 0, Rflag = 0;
+ int aflag = 0, dflag = 0, sflag = 0, Hflag = 0;
+ int pflag = 0, rflag = 0, Pflag = 0, Rflag = 0;
pid = getpid();
thiszone = gmt2local(0);
@@ -382,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);
@@ -392,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)
@@ -446,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,
- (nflag ? NI_NUMERICHOST : 0));
+ sizeof(host_buf), NULL ,0,
+ (nflag ? NI_NUMERICHOST : 0));
printf("%s (%s) -- no entry\n", host, host_buf);
exit(1);
}
@@ -487,14 +488,14 @@ 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) {
@@ -531,9 +532,9 @@ delete:
}
#endif
getnameinfo((struct sockaddr *)&s6,
- s6.sin6_len, host_buf,
- sizeof(host_buf), NULL, 0,
- (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);
}
@@ -672,13 +673,13 @@ 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) {
+ switch (nbi->state) {
case ND6_LLINFO_NOSTATE:
printf(" N");
break;
@@ -719,23 +720,21 @@ 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);
#if 0 /* W and P are mystery even for us */
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" : "");
#else
snprintf(flgbuf, sizeof(flgbuf), "%s%s",
- isrouter ? "R" : "",
- (rtm->rtm_flags & RTF_ANNOUNCE) ? "p" : "");
+ isrouter ? "R" : "",
+ (rtm->rtm_flags & RTF_ANNOUNCE) ? "p" : "");
#endif
}
printf(" %s", flgbuf);
@@ -791,7 +790,7 @@ ether_str(sdl)
if (sdl->sdl_alen) {
cp = (u_char *)LLADDR(sdl);
snprintf(hbuf, sizeof(hbuf), "%x:%x:%x:%x:%x:%x",
- cp[0], cp[1], cp[2], cp[3], cp[4], cp[5]);
+ cp[0], cp[1], cp[2], cp[3], cp[4], cp[5]);
} else
snprintf(hbuf, sizeof(hbuf), "(incomplete)");
@@ -806,7 +805,7 @@ 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);
@@ -923,9 +922,9 @@ ifinfo(argc, argv)
bzero(&nd, sizeof(nd));
strlcpy(nd.ifname, ifname, sizeof(nd.ifname));
if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&nd) < 0) {
- err(1, "ioctl(SIOCGIFINFO_IN6)");
+ err(1, "ioctl(SIOCGIFINFO_IN6)");
/* NOTREACHED */
- }
+ }
#define ND nd.ndi
newflags = ND.flags;
for (i = 1; i < argc; i++) {
@@ -970,7 +969,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
@@ -980,7 +979,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;
@@ -1014,7 +1013,7 @@ ifinfo(argc, argv)
}
putc('\n', stdout);
#undef ND
-
+
close(s);
}
@@ -1054,21 +1053,21 @@ rtrlist()
p->rtaddr.sin6_len, host_buf, sizeof(host_buf), NULL, 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
@@ -1083,9 +1082,9 @@ rtrlist()
bzero(&dr, sizeof(dr));
strlcpy(dr.ifname, "lo0", sizeof(dr.ifname)); /* dummy */
if (ioctl(s, SIOCGDRLST_IN6, (caddr_t)&dr) < 0) {
- err(1, "ioctl(SIOCGDRLST_IN6)");
+ err(1, "ioctl(SIOCGDRLST_IN6)");
/* NOTREACHED */
- }
+ }
#define DR dr.defrouter[i]
for (i = 0 ; DR.if_index && i < DRLSTSIZ ; i++) {
struct sockaddr_in6 sin6;
@@ -1095,20 +1094,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,
- (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);
@@ -1153,7 +1152,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);
/*
@@ -1161,16 +1160,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
@@ -1183,7 +1182,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);
@@ -1207,10 +1206,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:
@@ -1242,9 +1241,9 @@ plist()
bzero(&pr, sizeof(pr));
strlcpy(pr.ifname, "lo0", sizeof(pr.ifname)); /* dummy */
if (ioctl(s, SIOCGPRLST_IN6, (caddr_t)&pr) < 0) {
- err(1, "ioctl(SIOCGPRLST_IN6)");
+ err(1, "ioctl(SIOCGPRLST_IN6)");
/* NOTREACHED */
- }
+ }
#define PR pr.prefix[i]
for (i = 0; PR.if_index && i < PRLSTSIZ ; i++) {
struct sockaddr_in6 p6;
@@ -1268,7 +1267,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;
@@ -1277,13 +1276,13 @@ plist()
niflags = NI_NUMERICHOST;
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);
/*
@@ -1292,24 +1291,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");
@@ -1323,7 +1322,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
@@ -1369,22 +1368,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,
- (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
@@ -1392,7 +1391,7 @@ plist()
}
if (PR.advrtrs > DRLSTSIZ)
printf(" and %d routers\n",
- PR.advrtrs - DRLSTSIZ);
+ PR.advrtrs - DRLSTSIZ);
} else
printf(" No advertising router\n");
}
@@ -1411,7 +1410,7 @@ pfx_flush()
err(1, "socket");
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
@@ -1424,7 +1423,7 @@ rtr_flush()
err(1, "socket");
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);
}
@@ -1439,7 +1438,7 @@ harmonize_rtr()
err(1, "socket");
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);
}
@@ -1466,7 +1465,7 @@ setdefif(ifname)
ndifreq.ifindex = ifindex;
if (ioctl(s, SIOCSDEFIFACE_IN6, (caddr_t)&ndifreq) < 0)
- err(1, "ioctl(SIOCSDEFIFACE_IN6)");
+ err(1, "ioctl(SIOCSDEFIFACE_IN6)");
close(s);
}
@@ -1484,7 +1483,7 @@ getdefif()
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");