From ef00ac75b53e178bd7632b6b6373d9f8d3fc53d2 Mon Sep 17 00:00:00 2001 From: Mats Erik Andersson Date: Wed, 29 Sep 2010 16:36:54 +0200 Subject: [PATCH] Fine tuning for OpenBSD and GNU/kfreebsd. GNU/Linux and FreeBSD are also fine with these. --- darkstat.c | 5 ++++- decode.c | 5 +++++ decode.h | 1 + http.c | 10 ++++++---- localip.c | 11 +++-------- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/darkstat.c b/darkstat.c index 308cba5..da3b92d 100644 --- a/darkstat.c +++ b/darkstat.c @@ -106,7 +106,10 @@ static void cb_bindaddr(const char *arg) struct addrinfo hints, *ai; memset(&hints, '\0', sizeof(hints)); - hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; + hints.ai_flags = AI_PASSIVE; +#ifdef AI_ADDRCONFIG + hints.ai_flags |= AI_ADDRCONFIG; +#endif hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; diff --git a/decode.c b/decode.c index e20b0b3..c3bb176 100644 --- a/decode.c +++ b/decode.c @@ -46,6 +46,11 @@ #define ETHERTYPE_PPPOE 0x8864 #endif +#ifndef ETHERTYPE_IPV6 +# include /* ETH_P_IPV6 for GNU/kfreebsd */ +# define ETHERTYPE_IPV6 ETH_P_IPV6 +#endif + #include /* struct ifreq */ #include /* n_long */ #include /* struct ip */ diff --git a/decode.h b/decode.h index 73c20e7..5e70dad 100644 --- a/decode.h +++ b/decode.h @@ -8,6 +8,7 @@ */ #include +#include /* n_time */ #include /* in_addr_t */ #include /* struct ip */ diff --git a/http.c b/http.c index b232705..a79f567 100644 --- a/http.c +++ b/http.c @@ -873,10 +873,13 @@ void http_init(const char *bindaddr, const unsigned short bindport, memset(&hints, '\0', sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; + hints.ai_flags = AI_PASSIVE; +#ifdef AI_ADDRCONFIG + hints.ai_flags |= AI_ADDRCONFIG; +#endif snprintf(portstr, sizeof(portstr), "%u", bindport); - if (ret = getaddrinfo(bindaddr, portstr, &hints, &aiptr)) + if ((ret = getaddrinfo(bindaddr, portstr, &hints, &aiptr))) err(1, "getaddrinfo(): %s", gai_strerror(ret)); for (ai = aiptr; ai; ai = ai->ai_next) { @@ -899,8 +902,7 @@ void http_init(const char *bindaddr, const unsigned short bindport, /* bind socket */ memcpy(&addrin, ai->ai_addr, ai->ai_addrlen); - if (bind(sockin, (struct sockaddr *)&addrin, - sizeof(addrin)) == -1) { + if (bind(sockin, (struct sockaddr *)&addrin, ai->ai_addrlen) == -1) { close(sockin); continue; } diff --git a/localip.c b/localip.c index 622decf..11330cd 100644 --- a/localip.c +++ b/localip.c @@ -71,16 +71,11 @@ localip_update(void) } /* IPv6 needs some obvious exceptions. */ - if( ifa->ifa_addr->sa_family == AF_INET6 ) { + if ( ifa->ifa_addr->sa_family == AF_INET6 ) { struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) ifa->ifa_addr; -#ifdef __FreeBSD__ - if( IN6_IS_ADDR_LINKLOCAL(&(sa6->sin6_addr)) - || IN6_IS_ADDR_SITELOCAL(&(sa6->sin6_addr)) ) -#else - if( IN6_IS_ADDR_LINKLOCAL(&(sa6->sin6_addr.s6_addr)) - || IN6_IS_ADDR_SITELOCAL(&(sa6->sin6_addr.s6_addr)) ) -#endif + if ( IN6_IS_ADDR_LINKLOCAL(&(sa6->sin6_addr)) + || IN6_IS_ADDR_SITELOCAL(&(sa6->sin6_addr)) ) continue; else /* Only standard IPv6 can reach this point. */ -- 2.17.1