summaryrefslogtreecommitdiff
path: root/usr.sbin/mrouted
diff options
context:
space:
mode:
authoritojun <itojun@NetBSD.org>2003-08-18 05:39:52 +0000
committeritojun <itojun@NetBSD.org>2003-08-18 05:39:52 +0000
commit757e4585598c300e1fa666b5ac8595efc705d43e (patch)
tree387e7bfc7da22cfd53a252c0555eab4e3c730851 /usr.sbin/mrouted
parentdc4bf37abfea2d129cbcc62b42e0046c8ea4e1b8 (diff)
SIOCGIFCONF -> getifaddrs conversion
Diffstat (limited to 'usr.sbin/mrouted')
-rw-r--r--usr.sbin/mrouted/cfparse.y62
1 files changed, 26 insertions, 36 deletions
diff --git a/usr.sbin/mrouted/cfparse.y b/usr.sbin/mrouted/cfparse.y
index 664a00bb18b..f2a4b9ed7ca 100644
--- a/usr.sbin/mrouted/cfparse.y
+++ b/usr.sbin/mrouted/cfparse.y
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cfparse.y,v 1.14 2003/07/13 12:40:17 itojun Exp $ */
+/* $NetBSD: cfparse.y,v 1.15 2003/08/18 05:39:53 itojun Exp $ */
/*
* Configuration file parser for mrouted.
@@ -26,6 +26,7 @@
#include <stdarg.h>
#include "defs.h"
#include <netdb.h>
+#include <ifaddrs.h>
/*
* Local function declarations
@@ -38,7 +39,7 @@ static void yyerror(char *s);
static char * next_word(void);
static int yylex(void);
static u_int32_t valid_if(char *s);
-static struct ifreq * ifconfaddr(struct ifconf *ifcp, u_int32_t a);
+static const char * ifconfaddr(u_int32_t a);
int yyparse(void);
static FILE *f __attribute__((__unused__)); /* XXX egcs */
@@ -49,8 +50,6 @@ extern int cache_lifetime;
extern int max_prune_lifetime;
static int lineno;
-static struct ifreq ifbuf[32];
-static struct ifconf ifc;
static struct uvif *v;
@@ -128,26 +127,25 @@ 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));
- strncpy(ffr.ifr_name, ifr->ifr_name, IFNAMSIZ);
+ strncpy(ffr.ifr_name, ifname, sizeof(ffr.ifr_name));
if (ioctl(udp_socket, SIOCGIFFLAGS, (char *)&ffr)<0)
fatal("ioctl SIOCGIFFLAGS on %s",ffr.ifr_name);
if (ffr.ifr_flags & IFF_LOOPBACK)
fatal("Tunnel local address %s is a loopback interface",
inet_fmt($2));
- if (ifconfaddr(&ifc, $3) != 0)
+ if (ifconfaddr($3) != 0)
fatal("Tunnel remote address %s is one of mine",
inet_fmt($3));
@@ -569,11 +567,6 @@ config_vifs_from_file()
return;
}
- ifc.ifc_buf = (char *)ifbuf;
- ifc.ifc_len = sizeof(ifbuf);
- if (ioctl(udp_socket, SIOCGIFCONF, (char *)&ifc) < 0)
- logit(LOG_ERR, errno, "ioctl SIOCGIFCONF");
-
yyparse();
fclose(f);
@@ -593,28 +586,25 @@ char *s;
return 0;
}
-static struct ifreq *
-ifconfaddr(ifcp, a)
- struct ifconf *ifcp;
+static const char *
+ifconfaddr(a)
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);
-#if (defined(BSD) && (BSD >= 199006))
- 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);
}