summaryrefslogtreecommitdiff
path: root/usr.sbin/rtsold/if.c
diff options
context:
space:
mode:
authorJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2000-02-25 10:32:22 +0000
committerJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2000-02-25 10:32:22 +0000
commitba7767ec9c45d31f14b0ecaf5c21fd86c7046f24 (patch)
tree947bb03960ab35025b62bad150bb13a6f19930f4 /usr.sbin/rtsold/if.c
parent18cf87ed57039c403152d9fb3395ddd293b52ecb (diff)
use getifaddrs, not SIOCGIFCONF for LP64 align issue. (sync with kame).
Diffstat (limited to 'usr.sbin/rtsold/if.c')
-rw-r--r--usr.sbin/rtsold/if.c55
1 files changed, 54 insertions, 1 deletions
diff --git a/usr.sbin/rtsold/if.c b/usr.sbin/rtsold/if.c
index 65872bd84f3..4fef07fd307 100644
--- a/usr.sbin/rtsold/if.c
+++ b/usr.sbin/rtsold/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.4 2000/01/17 16:33:49 itojun Exp $ */
+/* $OpenBSD: if.c,v 1.5 2000/02/25 10:32:21 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -65,6 +65,9 @@
#include <fcntl.h>
#include <errno.h>
#include <limits.h>
+#ifdef HAVE_GETIFADDRS
+#include <ifaddrs.h>
+#endif
#include "rtsold.h"
@@ -72,7 +75,9 @@ extern int rssock;
static int ifsock;
static int get_llflag __P((const char *name));
+#ifndef HAVE_GETIFADDRS
static unsigned int if_maxindex __P((void));
+#endif
static void get_rtaddrs __P((int addrs, struct sockaddr *sa,
struct sockaddr **rti_info));
@@ -311,6 +316,51 @@ getinet6sysctl(int code)
static int
get_llflag(const char *name)
{
+#ifdef HAVE_GETIFADDRS
+ struct ifaddrs *ifap, *ifa;
+ struct in6_ifreq ifr6;
+ struct sockaddr_in6 *sin6;
+ int s;
+
+ if ((s = socket(PF_INET6, SOCK_DGRAM, 0)) < 0) {
+ warnmsg(LOG_ERR, __FUNCTION__, "socket(SOCK_DGRAM): %s",
+ strerror(errno));
+ exit(1);
+ }
+ if (getifaddrs(&ifap) != 0) {
+ warnmsg(LOG_ERR, __FUNCTION__, "etifaddrs: %s",
+ strerror(errno));
+ exit(1);
+ }
+
+ for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+ if (strlen(ifa->ifa_name) != strlen(name)
+ || strncmp(ifa->ifa_name, name, strlen(name)) != 0)
+ continue;
+ if (ifa->ifa_addr->sa_family != AF_INET6)
+ continue;
+ sin6 = (struct sockaddr_in6 *)ifa->ifa_addr;
+ if (!IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))
+ continue;
+
+ memset(&ifr6, 0, sizeof(ifr6));
+ strcpy(ifr6.ifr_name, name);
+ memcpy(&ifr6.ifr_ifru.ifru_addr, sin6, sin6->sin6_len);
+ if (ioctl(s, SIOCGIFAFLAG_IN6, &ifr6) < 0) {
+ warnmsg(LOG_ERR, __FUNCTION__,
+ "ioctl(SIOCGIFAFLAG_IN6): %s", strerror(errno));
+ exit(1);
+ }
+
+ freeifaddrs(ifap);
+ close(s);
+ return ifr6.ifr_ifru.ifru_flags6;
+ }
+
+ freeifaddrs(ifap);
+ close(s);
+ return -1;
+#else
int s;
unsigned int maxif;
struct ifreq *iflist;
@@ -372,8 +422,10 @@ get_llflag(const char *name)
free(iflist);
close(s);
return -1;
+#endif
}
+#ifndef HAVE_GETIFADDRS
static unsigned int
if_maxindex()
{
@@ -388,6 +440,7 @@ if_maxindex()
if_freenameindex(p0);
return max;
}
+#endif
static void
get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)