diff options
author | maxim <maxim@FreeBSD.org> | 2006-05-17 18:41:05 +0000 |
---|---|---|
committer | maxim <maxim@FreeBSD.org> | 2006-05-17 18:41:05 +0000 |
commit | c919e859027f0b200f81ba863d34ce0b82e2cc7b (patch) | |
tree | 9533d6fdcad9d611a61c193b070b693c8bd4bb3b /usr.sbin/mrouted/cfparse.y | |
parent | 13602a353ca35e6594bdd7201c284768ed3317fe (diff) | |
download | FreeBSD-src-c919e859027f0b200f81ba863d34ce0b82e2cc7b.zip FreeBSD-src-c919e859027f0b200f81ba863d34ce0b82e2cc7b.tar.gz |
o SIOCGIFCONF -> getifaddrs(3) conversion. As a side effect fix
bin/95041: subnet mask mismatch.
PR: bin/95041
Obtained from: NetBSD
Tested by: Hans Lambermont
MFC after: 2 months
Diffstat (limited to 'usr.sbin/mrouted/cfparse.y')
-rw-r--r-- | usr.sbin/mrouted/cfparse.y | 57 |
1 files changed, 26 insertions, 31 deletions
diff --git a/usr.sbin/mrouted/cfparse.y b/usr.sbin/mrouted/cfparse.y index 1827f6a..9ab1f62 100644 --- a/usr.sbin/mrouted/cfparse.y +++ b/usr.sbin/mrouted/cfparse.y @@ -15,6 +15,7 @@ #endif #include "defs.h" #include <netdb.h> +#include <ifaddrs.h> /* * Local function declarations @@ -25,7 +26,7 @@ static void yyerror __P((char *s)); static char * next_word __P((void)); static int yylex __P((void)); static u_int32 valid_if __P((char *s)); -static struct ifreq * ifconfaddr __P((struct ifconf *ifcp, u_int32 a)); +static const char * ifconfaddr(u_int32_t a); int yyparse __P((void)); static FILE *f; @@ -128,15 +129,14 @@ stmt : error } ifmods | TUNNEL interface addrname { - - struct ifreq *ifr; + const char *ifname; struct ifreq ffr; vifi_t vifi; order++; - ifr = ifconfaddr(&ifc, $2); - if (ifr == 0) + ifname = ifconfaddr($2); + if (ifname == 0) fatal("Tunnel local address %s is not mine", inet_fmt($2, s1)); @@ -145,7 +145,7 @@ stmt : error fatal("Tunnel local address %s is a loopback address", inet_fmt($2, s1)); - if (ifconfaddr(&ifc, $3) != 0) + if (ifconfaddr($3) != 0) fatal("Tunnel remote address %s is one of mine", inet_fmt($3, s1)); @@ -165,7 +165,7 @@ stmt : error if (numvifs == MAXVIFS) fatal("too many vifs"); - strncpy(ffr.ifr_name, ifr->ifr_name, IFNAMSIZ); + strlcpy(ffr.ifr_name, ifname, sizeof(ffr.ifr_name)); if (ioctl(udp_socket, SIOCGIFFLAGS, (char *)&ffr)<0) fatal("ioctl SIOCGIFFLAGS on %s", ffr.ifr_name); @@ -176,8 +176,7 @@ stmt : error v->uv_lcl_addr = $2; v->uv_rmt_addr = $3; v->uv_dst_addr = $3; - strncpy(v->uv_name, ffr.ifr_name, IFNAMSIZ); - v->uv_name[IFNAMSIZ-1]='\0'; + strlcpy(v->uv_name, ffr.ifr_name, sizeof(v->uv_name)); if (!(ffr.ifr_flags & IFF_UP)) { v->uv_flags |= VIFF_DOWN; @@ -905,28 +904,24 @@ char *s; return 0; } -static struct ifreq * -ifconfaddr(ifcp, a) - struct ifconf *ifcp; - u_int32 a; +static const char * +ifconfaddr(u_int32_t a) { - int n; - struct ifreq *ifrp = (struct ifreq *)ifcp->ifc_buf; - struct ifreq *ifend = (struct ifreq *)((char *)ifrp + ifcp->ifc_len); - - while (ifrp < ifend) { - if (ifrp->ifr_addr.sa_family == AF_INET && - ((struct sockaddr_in *)&ifrp->ifr_addr)->sin_addr.s_addr == a) - return (ifrp); -#ifdef HAVE_SA_LEN - n = ifrp->ifr_addr.sa_len + sizeof(ifrp->ifr_name); - if (n < sizeof(*ifrp)) - ++ifrp; - else - ifrp = (struct ifreq *)((char *)ifrp + n); -#else - ++ifrp; -#endif + static char ifname[IFNAMSIZ]; + struct ifaddrs *ifap, *ifa; + + if (getifaddrs(&ifap) != 0) + return (NULL); + + for (ifa = ifap; ifa; ifa = ifa->ifa_next) { + if (ifa->ifa_addr->sa_family == AF_INET && + ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr == a) { + strlcpy(ifname, ifa->ifa_name, sizeof(ifname)); + freeifaddrs(ifap); + return (ifname); + } } - return (0); + + freeifaddrs(ifap); + return (NULL); } |