diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2000-02-25 10:25:47 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2000-02-25 10:25:47 +0000 |
commit | 8c03970d0118fefd90f53cc0d3a1bc6f4bd532cc (patch) | |
tree | 6b6d586da262ba4a64cc6c278c4f30258835ccde /usr.sbin/faithd | |
parent | 67f3ea9113f38477250cf7f262db9102804cd289 (diff) |
use getifaddrs, not SIOCGIFCONF, to avoid LP64 alignment issues.
Diffstat (limited to 'usr.sbin/faithd')
-rw-r--r-- | usr.sbin/faithd/faithd.8 | 12 | ||||
-rw-r--r-- | usr.sbin/faithd/faithd.c | 87 |
2 files changed, 91 insertions, 8 deletions
diff --git a/usr.sbin/faithd/faithd.8 b/usr.sbin/faithd/faithd.8 index a1131346b0a..d1795f36614 100644 --- a/usr.sbin/faithd/faithd.8 +++ b/usr.sbin/faithd/faithd.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: faithd.8,v 1.2 1999/12/20 16:32:53 itojun Exp $ +.\" $OpenBSD: faithd.8,v 1.3 2000/02/25 10:25:46 itojun Exp $ .\" .\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" KAME Id: faithd.8,v 1.1.1.1 1999/12/20 16:07:42 itojun Exp +.\" KAME Id: faithd.8,v 1.4 2000/01/22 07:56:48 itojun Exp .\" .Dd May 17, 1998 .Dt FAITHD 8 @@ -233,6 +233,14 @@ on error. .Xr faith 4 , .Xr route 8 , .Xr sysctl 8 +.Rs +.%A Jun-ichiro itojun Hagino +.%A Kazu Yamamoto +.%T "An IPv6-to-IPv4 transport relay translator" +.%R internet draft +.%N draft-ietf-ngtrans-tcpudp-relay-00.txt +.%O work in progress material +.Re .\" .Sh SECURITY NOTICE It is very insecure to use diff --git a/usr.sbin/faithd/faithd.c b/usr.sbin/faithd/faithd.c index 3dc0e0c547f..7b5bbbd626c 100644 --- a/usr.sbin/faithd/faithd.c +++ b/usr.sbin/faithd/faithd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: faithd.c,v 1.3 1999/12/30 16:31:01 deraadt Exp $ */ +/* $OpenBSD: faithd.c,v 1.4 2000/02/25 10:25:46 itojun Exp $ */ /* * Copyright (C) 1997 and 1998 WIDE Project. @@ -35,6 +35,7 @@ * Usage: faithd [<port> <progpath> <arg1(progname)> <arg2> ...] * e.g. faithd telnet /usr/local/v6/sbin/telnetd telnetd */ +#define HAVE_GETIFADDRS #include <sys/param.h> #include <sys/types.h> @@ -70,6 +71,9 @@ #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> +#ifdef HAVE_GETIFADDRS +#include <ifaddrs.h> +#endif #ifdef FAITH4 #include <resolv.h> @@ -109,7 +113,9 @@ static int map4to6 __P((struct sockaddr_in *, struct sockaddr_in6 *)); static void sig_child __P((int)); static void sig_terminate __P((int)); static void start_daemon __P((void)); +#ifndef HAVE_GETIFADDRS static unsigned int if_maxindex __P((void)); +#endif static void grab_myaddrs __P((void)); static void free_myaddrs __P((void)); static void update_myaddrs __P((void)); @@ -677,6 +683,7 @@ exit_success(const char *fmt, ...) } #ifdef USE_ROUTE +#ifndef HAVE_GETIFADDRS static unsigned int if_maxindex() { @@ -691,17 +698,73 @@ if_maxindex() if_freenameindex(p0); return max; } +#endif static void grab_myaddrs() { +#ifdef HAVE_GETIFADDRS + struct ifaddrs *ifap, *ifa; + struct myaddrs *p; + struct sockaddr_in6 *sin6; + + if (getifaddrs(&ifap) != 0) { + exit_failure("getifaddrs"); + /*NOTREACHED*/ + } + + for (ifa = ifap; ifa; ifa = ifa->ifa_next) { + switch (ifa->ifa_addr->sa_family) { + case AF_INET: + case AF_INET6: + break; + default: + continue; + } + + p = (struct myaddrs *)malloc(sizeof(struct myaddrs) + + ifa->ifa_addr->sa_len); + if (!p) { + exit_failure("not enough core"); + /*NOTREACHED*/ + } + memcpy(p + 1, ifa->ifa_addr, ifa->ifa_addr->sa_len); + p->next = myaddrs; + p->addr = (struct sockaddr *)(p + 1); +#ifdef __KAME__ + if (ifa->ifa_addr->sa_family == AF_INET6) { + sin6 = (struct sockaddr_in6 *)p->addr; + if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) + || IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) { + sin6->sin6_scope_id = + ntohs(*(u_int16_t *)&sin6->sin6_addr.s6_addr[2]); + sin6->sin6_addr.s6_addr[2] = 0; + sin6->sin6_addr.s6_addr[3] = 0; + } + } +#endif + myaddrs = p; + if (dflag) { + char hbuf[NI_MAXHOST]; + getnameinfo(p->addr, p->addr->sa_len, + hbuf, sizeof(hbuf), NULL, 0, + NI_NUMERICHOST); + syslog(LOG_INFO, "my interface: %s %s", hbuf, + ifa->ifa_name); + } + } + + freeifaddrs(ifap); +#else int s; unsigned int maxif; struct ifreq *iflist; struct ifconf ifconf; - struct ifreq *ifr, *ifr_end; + struct ifreq *ifr, *ifrp, *ifr_end; struct myaddrs *p; struct sockaddr_in6 *sin6; + size_t siz; + char ifrbuf[sizeof(struct ifreq) + 1024]; maxif = if_maxindex() + 1; iflist = (struct ifreq *)malloc(maxif * BUFSIZ); /* XXX */ @@ -725,10 +788,21 @@ grab_myaddrs() /* Look for this interface in the list */ ifr_end = (struct ifreq *) (ifconf.ifc_buf + ifconf.ifc_len); - for (ifr = ifconf.ifc_req; - ifr < ifr_end; - ifr = (struct ifreq *) ((char *) &ifr->ifr_addr - + ifr->ifr_addr.sa_len)) { + for (ifrp = ifconf.ifc_req; + ifrp < ifr_end; + ifrp = (struct ifreq *)((char *)ifrp + siz)) { + memcpy(ifrbuf, ifrp, sizeof(*ifrp)); + ifr = (struct ifreq *)ifrbuf; + siz = ifr->ifr_addr.sa_len; + if (siz < sizeof(ifr->ifr_addr)) + siz = sizeof(ifr->ifr_addr); + siz += (sizeof(*ifrp) - sizeof(ifr->ifr_addr)); + if (siz > sizeof(ifrbuf)) { + /* ifr too big */ + break; + } + memcpy(ifrbuf, ifrp, siz); + switch (ifr->ifr_addr.sa_family) { case AF_INET: case AF_INET6: @@ -768,6 +842,7 @@ grab_myaddrs() } free(iflist); +#endif } static void |