diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2002-10-26 20:14:28 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2002-10-26 20:14:28 +0000 |
commit | 2a750eaaafebdb7ba595d3d0aba4f09ab116338b (patch) | |
tree | 84b20cd22a410a6a02db891153bce200e3fa82da | |
parent | c0b35e587d56aa7a6d530cba439af0f5fbd796ed (diff) |
use strtoul, not atoi. some error handling sync w/kame.
-rw-r--r-- | usr.sbin/route6d/route6d.c | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/usr.sbin/route6d/route6d.c b/usr.sbin/route6d/route6d.c index b478c827eda..5187cc1768d 100644 --- a/usr.sbin/route6d/route6d.c +++ b/usr.sbin/route6d/route6d.c @@ -1,5 +1,5 @@ -/* $OpenBSD: route6d.c,v 1.31 2002/08/21 16:30:29 itojun Exp $ */ -/* $KAME: route6d.c,v 1.88 2002/08/21 16:24:25 itojun Exp $ */ +/* $OpenBSD: route6d.c,v 1.32 2002/10/26 20:14:27 itojun Exp $ */ +/* $KAME: route6d.c,v 1.94 2002/10/26 20:08:55 itojun Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -31,7 +31,7 @@ */ #if 0 -static char _rcsid[] = "$OpenBSD: route6d.c,v 1.31 2002/08/21 16:30:29 itojun Exp $"; +static char _rcsid[] = "$OpenBSD: route6d.c,v 1.32 2002/10/26 20:14:27 itojun Exp $"; #endif #include <stdio.h> @@ -562,7 +562,8 @@ ripalarm() void init() { - int i, int0, int255, error; + int i, error; + const int int0 = 0, int1 = 1, int255 = 255; struct addrinfo hints, *res; char port[10]; @@ -586,12 +587,16 @@ init() /*NOTREACHED*/ } - int0 = 0; int255 = 255; ripsock = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (ripsock < 0) { fatal("rip socket"); /*NOTREACHED*/ } + if (setsockopt(ripsock, IPPROTO_IPV6, IPV6_V6ONLY, + &int1, sizeof(int1)) < 0) { + fatal("rip IPV6_V6ONLY"); + /*NOTREACHED*/ + } if (bind(ripsock, res->ai_addr, res->ai_addrlen) < 0) { fatal("rip bind"); /*NOTREACHED*/ @@ -2706,16 +2711,16 @@ addroute(rrt, gw, ifcp) if (errno == EEXIST) { trace(0, "ADD: Route already exists %s/%d gw %s\n", - inet6_n2p(&np->rip6_dest), np->rip6_plen, buf1); + inet6_n2p(&np->rip6_dest), np->rip6_plen, buf1); if (rtlog) fprintf(rtlog, "ADD: Route already exists %s/%d gw %s\n", - inet6_n2p(&np->rip6_dest), np->rip6_plen, buf1); + inet6_n2p(&np->rip6_dest), np->rip6_plen, buf1); } else { trace(0, "Can not write to rtsock (addroute): %s\n", - strerror(errno)); + strerror(errno)); if (rtlog) fprintf(rtlog, "\tCan not write to rtsock: %s\n", - strerror(errno)); + strerror(errno)); } return -1; } @@ -2773,16 +2778,16 @@ delroute(np, gw) if (errno == ESRCH) { trace(0, "RTDEL: Route does not exist: %s/%d gw %s\n", - inet6_n2p(&np->rip6_dest), np->rip6_plen, buf2); + inet6_n2p(&np->rip6_dest), np->rip6_plen, buf2); if (rtlog) fprintf(rtlog, "RTDEL: Route does not exist: %s/%d gw %s\n", - inet6_n2p(&np->rip6_dest), np->rip6_plen, buf2); + inet6_n2p(&np->rip6_dest), np->rip6_plen, buf2); } else { trace(0, "Can not write to rtsock (delroute): %s\n", - strerror(errno)); + strerror(errno)); if (rtlog) fprintf(rtlog, "\tCan not write to rtsock: %s\n", - strerror(errno)); + strerror(errno)); } return -1; } @@ -3003,13 +3008,14 @@ void filterconfig() { int i; - char *p, *ap, *iflp, *ifname; + char *p, *ap, *iflp, *ifname, *ep; struct iff ftmp, *iff_obj; struct ifc *ifcp; struct riprt *rrt; #if 0 struct in6_addr gw; #endif + u_long plen; for (i = 0; i < nfilter; i++) { ap = filter[i]; @@ -3032,7 +3038,14 @@ filterconfig() fatal("invalid prefix specified for '%s'", ap); /*NOTREACHED*/ } - ftmp.iff_plen = atoi(p); + errno = 0; + ep = NULL; + plen = strtoul(p, &ep, 10); + if (errno || !*p || *ep || plen > sizeof(ftmp.iff_addr) * 8) { + fatal("invalid prefix length specified for '%s'", ap); + /*NOTREACHED*/ + } + ftmp.iff_plen = plen; ftmp.iff_next = NULL; applyplen(&ftmp.iff_addr, ftmp.iff_plen); ifonly: @@ -3330,7 +3343,10 @@ fatal(const char *fmt, ...) vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); perror(buf); - syslog(LOG_ERR, "%s: %s", buf, strerror(errno)); + if (errno) + syslog(LOG_ERR, "%s: %s", buf, strerror(errno)); + else + syslog(LOG_ERR, "%s", buf); rtdexit(); } |