summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2001-08-13 14:33:36 +0000
committerJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2001-08-13 14:33:36 +0000
commit23bfc638e92a88043673b111d2863490162c2e47 (patch)
tree1f41573c20d3e9ca39b47cc5d17ead023b93212f /sbin
parent7558101cf54e3ecde54fbd01f31fa636c4fbf2ab (diff)
use getifaddrs(3) rather than SIOCGIFCONF. in fact, if_map() does not do
the right thing on certain set of interface addresses. SIOCGIFCONF is the worst possible ioctl API...
Diffstat (limited to 'sbin')
-rw-r--r--sbin/isakmpd/if.c25
-rw-r--r--sbin/isakmpd/if.h4
-rw-r--r--sbin/isakmpd/sysdep/bsdi/Makefile.sysdep4
-rw-r--r--sbin/isakmpd/sysdep/freebsd/Makefile.sysdep4
-rw-r--r--sbin/isakmpd/sysdep/netbsd/Makefile.sysdep3
-rw-r--r--sbin/isakmpd/sysdep/openbsd/Makefile.sysdep4
-rw-r--r--sbin/isakmpd/udp.c10
7 files changed, 37 insertions, 17 deletions
diff --git a/sbin/isakmpd/if.c b/sbin/isakmpd/if.c
index 6d4569210ee..ca1e6a8ac05 100644
--- a/sbin/isakmpd/if.c
+++ b/sbin/isakmpd/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.8 2001/07/18 20:56:35 markus Exp $ */
+/* $OpenBSD: if.c,v 1.9 2001/08/13 14:33:35 itojun Exp $ */
/* $EOM: if.c,v 1.12 1999/10/01 13:45:20 niklas Exp $ */
/*
@@ -40,12 +40,16 @@
#include <net/if.h>
#include <stdlib.h>
#include <unistd.h>
+#ifdef HAVE_GETIFADDRS
+#include <ifaddrs.h>
+#endif
#include "sysdep.h"
#include "log.h"
#include "if.h"
+#ifndef HAVE_GETIFADDRS
/* XXX Unsafe if either x or y has side-effects. */
#ifndef MAX
#define MAX(x, y) ((x) > (y) ? (x) : (y))
@@ -112,10 +116,24 @@ err:
close (s);
return -1;
}
+#endif
int
-if_map (void (*func) (struct ifreq *, void *), void *arg)
+if_map (void (*func) (char *, struct sockaddr *, void *), void *arg)
{
+#ifdef HAVE_GETIFADDRS
+ struct ifaddrs *ifap, *ifa;
+
+ if (getifaddrs(&ifap) < 0)
+ return -1;
+
+ for (ifa = ifap; ifa; ifa = ifa->ifa_next)
+ {
+ (*func) (ifa->ifa_name, ifa->ifa_addr, arg);
+ }
+ freeifaddrs(ifap);
+ return 0;
+#else
struct ifconf ifc;
struct ifreq *ifrp;
caddr_t limit, p;
@@ -128,7 +146,7 @@ if_map (void (*func) (struct ifreq *, void *), void *arg)
for (p = ifc.ifc_buf; p < limit; p += len)
{
ifrp = (struct ifreq *)p;
- (*func) (ifrp, arg);
+ (*func) (ifrp->ifr_name, &ifrp->ifr_addr, arg);
#ifdef USE_OLD_SOCKADDR
len = sizeof ifrp->ifr_name + sizeof ifrp->ifr_addr;
#else
@@ -138,4 +156,5 @@ if_map (void (*func) (struct ifreq *, void *), void *arg)
}
free (ifc.ifc_buf);
return 0;
+#endif
}
diff --git a/sbin/isakmpd/if.h b/sbin/isakmpd/if.h
index e249229b588..0cffcaba508 100644
--- a/sbin/isakmpd/if.h
+++ b/sbin/isakmpd/if.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.h,v 1.3 1998/11/17 11:10:12 niklas Exp $ */
+/* $OpenBSD: if.h,v 1.4 2001/08/13 14:33:35 itojun Exp $ */
/* $EOM: if.h,v 1.2 1998/07/07 23:35:58 niklas Exp $ */
/*
@@ -42,7 +42,7 @@
struct ifreq;
struct ifconf;
-extern int if_map (void (*) (struct ifreq *, void *), void *);
+extern int if_map (void (*) (char *, struct sockaddr *, void *), void *);
extern int siocgifconf (struct ifconf *);
#endif /* _IF_H_ */
diff --git a/sbin/isakmpd/sysdep/bsdi/Makefile.sysdep b/sbin/isakmpd/sysdep/bsdi/Makefile.sysdep
index 8814b0323fb..968fbb581be 100644
--- a/sbin/isakmpd/sysdep/bsdi/Makefile.sysdep
+++ b/sbin/isakmpd/sysdep/bsdi/Makefile.sysdep
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.sysdep,v 1.2 2001/07/18 20:52:39 markus Exp $
+# $OpenBSD: Makefile.sysdep,v 1.3 2001/08/13 14:33:35 itojun Exp $
#
# Copyright (c) 1999 Niklas Hallqvist. All rights reserved.
@@ -52,7 +52,7 @@ CFLAGS+= -I/usr/build/keynote
LDFLAGS+= -L/usr/build/keynote
.endif
-CFLAGS+= -DNO_IDEA -DNO_RC5 -DHAVE_GETNAMEINFO \
+CFLAGS+= -DNO_IDEA -DNO_RC5 -DHAVE_GETNAMEINFO -DHAVE_GETIFADDRS \
-I${.CURDIR}/sysdep/common
CFLAGS+= -I/usr/include -I/usr/contrib/include
diff --git a/sbin/isakmpd/sysdep/freebsd/Makefile.sysdep b/sbin/isakmpd/sysdep/freebsd/Makefile.sysdep
index c65a6d3c4a1..cedb1adb30a 100644
--- a/sbin/isakmpd/sysdep/freebsd/Makefile.sysdep
+++ b/sbin/isakmpd/sysdep/freebsd/Makefile.sysdep
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.sysdep,v 1.4 2001/06/29 22:18:58 itojun Exp $
+# $OpenBSD: Makefile.sysdep,v 1.5 2001/08/13 14:33:35 itojun Exp $
#
# Copyright (c) 1999 Niklas Hallqvist. All rights reserved.
@@ -45,7 +45,7 @@ LIBSYSDEPDIR= ${.CURDIR}/sysdep/common/libsysdep
LDADD+= -lgmp ${LIBSYSDEPDIR}/libsysdep.a -L/usr/local/lib
DPADD+= ${LIBGMP} ${LIBSYSDEPDIR}/libsysdep.a
-CFLAGS+= -DHAVE_GETNAMEINFO \
+CFLAGS+= -DHAVE_GETNAMEINFO -DHAVE_GETIFADDRS \
-I${.CURDIR}/sysdep/common -I/usr/include \
-I/usr/local/include -I/usr/local/include/openssl
diff --git a/sbin/isakmpd/sysdep/netbsd/Makefile.sysdep b/sbin/isakmpd/sysdep/netbsd/Makefile.sysdep
index 8813a9227d8..635aad52e8d 100644
--- a/sbin/isakmpd/sysdep/netbsd/Makefile.sysdep
+++ b/sbin/isakmpd/sysdep/netbsd/Makefile.sysdep
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.sysdep,v 1.6 2001/06/29 22:18:59 itojun Exp $
+# $OpenBSD: Makefile.sysdep,v 1.7 2001/08/13 14:33:35 itojun Exp $
#
# Copyright (c) 1999 Niklas Hallqvist. All rights reserved.
@@ -40,6 +40,7 @@ LDADD+= ${LIBGMP} ${LIBSYSDEPDIR}/libsysdep.a -lipsec
DPADD+= ${LIBGMP} ${LIBSYSDEPDIR}/libsysdep.a ${LIBIPSEC}
CFLAGS+= -DNO_RSA -DNO_IDEA -DNO_RC5 -DHAVE_GETNAMEINFO \
+ -DHAVE_GETIFADDRS \
-I${.CURDIR}/sysdep/common
.if exists(/usr/pkg/include/openssl/rsa.h)
CFLAGS+= -I/usr/pkg/include/openssl
diff --git a/sbin/isakmpd/sysdep/openbsd/Makefile.sysdep b/sbin/isakmpd/sysdep/openbsd/Makefile.sysdep
index 9eae1cd0586..3e2fbcfd722 100644
--- a/sbin/isakmpd/sysdep/openbsd/Makefile.sysdep
+++ b/sbin/isakmpd/sysdep/openbsd/Makefile.sysdep
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.sysdep,v 1.18 2001/06/29 19:40:36 ho Exp $
+# $OpenBSD: Makefile.sysdep,v 1.19 2001/08/13 14:33:35 itojun Exp $
# $EOM: Makefile.sysdep,v 1.18 2001/01/26 10:55:22 niklas Exp $
#
@@ -37,7 +37,7 @@
IPSEC_SRCS= pf_key_v2.c
IPSEC_CFLAGS= -DUSE_PF_KEY_V2
-CFLAGS+= -Werror -DHAVE_GETNAMEINFO -DHAVE_PCAP
+CFLAGS+= -Werror -DHAVE_GETNAMEINFO -DHAVE_GETIFADDRS -DHAVE_PCAP
# Some OpenBSD systems do not provide dlopen(3).
#.if ${MACHINE_ARCH} != "alpha" && ${MACHINE_ARCH} != "mips" && ${MACHINE_ARCH} != "powerpc" && ${MACHINE_ARCH} != "vax" && ${MACHINE_ARCH} != "m88k"
diff --git a/sbin/isakmpd/udp.c b/sbin/isakmpd/udp.c
index d88083bcb64..960e9254692 100644
--- a/sbin/isakmpd/udp.c
+++ b/sbin/isakmpd/udp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: udp.c,v 1.47 2001/08/12 15:48:44 angelos Exp $ */
+/* $OpenBSD: udp.c,v 1.48 2001/08/13 14:33:35 itojun Exp $ */
/* $EOM: udp.c,v 1.57 2001/01/26 10:09:57 niklas Exp $ */
/*
@@ -266,7 +266,7 @@ udp_clone (struct udp_transport *u, struct sockaddr *raddr)
* system-wide pools of known ISAKMP transports.
*/
static struct transport *
-udp_bind (struct sockaddr *addr)
+udp_bind (const struct sockaddr *addr)
{
struct sockaddr *src = malloc (addr->sa_len);
@@ -282,10 +282,10 @@ udp_bind (struct sockaddr *addr)
* create an UDP server socket bound to it.
*/
static void
-udp_bind_if (struct ifreq *ifrp, void *arg)
+udp_bind_if (char *ifname, struct sockaddr *if_addr, void *arg)
{
char *port = (char *)arg;
- struct sockaddr *if_addr = &ifrp->ifr_addr, saddr;
+ struct sockaddr saddr;
struct conf_list *listen_on;
struct udp_transport *u;
struct conf_list_node *address;
@@ -352,7 +352,7 @@ udp_bind_if (struct ifreq *ifrp, void *arg)
if_addr->sa_family);
return;
}
- strncpy (flags_ifr.ifr_name, ifrp->ifr_name, sizeof flags_ifr.ifr_name - 1);
+ strncpy (flags_ifr.ifr_name, ifname, sizeof flags_ifr.ifr_name - 1);
if (ioctl (s, SIOCGIFFLAGS, (caddr_t)&flags_ifr) == -1)
{
log_error ("udp_bind_if: ioctl (%d, SIOCGIFFLAGS, ...) failed", s);