Blob Blame History Raw
From: Roger Shimizu <rogershimizu@gmail.com>
Date: Thu, 24 Dec 2015 01:16:58 +0900
Subject: Support to build on kFreeBSD & GNU/Hurd platform

Signed-off-by: Roger Shimizu <rogershimizu@gmail.com>
---
 cftoken.c            |  4 ++--
 cftoken.l            |  4 ++--
 common.c             | 38 +++++++++++++++++++-------------------
 config.c             |  8 ++++----
 configure            |  2 +-
 configure.in         |  2 +-
 dhcp6_ctl.c          |  2 +-
 dhcp6_ctlclient.c    |  2 +-
 dhcp6c.c             |  6 +++---
 dhcp6relay.c         |  6 +++---
 dhcp6s.c             |  4 ++--
 if.c                 |  2 +-
 missing/getifaddrs.c |  2 +-
 13 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/cftoken.c b/cftoken.c
index 079f274..6d43200 100644
--- a/cftoken.c
+++ b/cftoken.c
@@ -2539,7 +2539,7 @@ cfswitch_buffer(incl)
 	incstack[incstackp].state = YY_CURRENT_BUFFER;
 	incstack[incstackp].lineno = lineno;
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__GNU__)
 	fp = fopen(path, "re");
 #else
 	fp = fopen(path, "r");
@@ -2566,7 +2566,7 @@ cfparse(conf)
 	char *conf;
 {
 	configfilename = conf;
-#ifdef __linux__
+#if defined(__linux__) || defined(__GNU__)
 	if ((yyin = fopen(configfilename, "re")) == NULL) {
 #else
 	if ((yyin = fopen(configfilename, "r")) == NULL) {
diff --git a/cftoken.l b/cftoken.l
index e307357..f35b59f 100644
--- a/cftoken.l
+++ b/cftoken.l
@@ -418,7 +418,7 @@ cfswitch_buffer(incl)
 	incstack[incstackp].state = YY_CURRENT_BUFFER;
 	incstack[incstackp].lineno = lineno;
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__GNU__)
 	fp = fopen(path, "re");
 #else
 	fp = fopen(path, "r");
@@ -445,7 +445,7 @@ cfparse(conf)
 	char *conf;
 {
 	configfilename = conf;
-#ifdef __linux__
+#if defined(__linux__) || defined(__GNU__)
 	if ((yyin = fopen(configfilename, "re")) == NULL) {
 #else
 	if ((yyin = fopen(configfilename, "r")) == NULL) {
diff --git a/common.c b/common.c
index b5c09c3..10d905f 100644
--- a/common.c
+++ b/common.c
@@ -45,9 +45,9 @@
 #endif
 #include <net/if.h>
 #include <netinet/in.h>
-#ifdef __KAME__
+#if defined (__KAME__) || defined (__FreeBSD_kernel__)
 #include <net/if_types.h>
-#ifdef __FreeBSD__
+#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
 #include <net/if_var.h>
 #endif
 #include <net/if_dl.h>
@@ -64,7 +64,7 @@
 #include <libdevinfo.h>
 #endif
 
-#ifdef __KAME__
+#if defined (__KAME__) || defined (__FreeBSD_kernel__)
 #include <netinet6/in6_var.h>
 #endif
 
@@ -86,7 +86,7 @@
 #include <common.h>
 #include <timer.h>
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__GNU__)
 /* from /usr/include/linux/ipv6.h */
 
 struct in6_ifreq {
@@ -716,7 +716,7 @@ getifaddr(addr, ifnam, prefix, plen, strong, ignoreflags)
 			continue;
 
 		memcpy(&sin6, ifa->ifa_addr, sysdep_sa_len(ifa->ifa_addr));
-#ifdef __KAME__
+#if defined (__KAME__) || defined (__FreeBSD_kernel__)
 		if (IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr)) {
 			sin6.sin6_addr.s6_addr[2] = 0;
 			sin6.sin6_addr.s6_addr[3] = 0;
@@ -742,7 +742,7 @@ getifaddr(addr, ifnam, prefix, plen, strong, ignoreflags)
 				continue;
 		}
 		memcpy(addr, &sin6.sin6_addr, sizeof(sin6.sin6_addr));
-#ifdef __KAME__
+#if defined (__KAME__) || defined (__FreeBSD_kernel__)
 		if (IN6_IS_ADDR_LINKLOCAL(addr))
 			addr->s6_addr[2] = addr->s6_addr[3] = 0; 
 #endif
@@ -961,7 +961,7 @@ in6_matchflags(addr, ifnam, flags)
 	char *ifnam;
 	int flags;
 {
-#ifdef __KAME__
+#if defined (__KAME__) || defined (__FreeBSD_kernel__)
 	int s;
 	struct in6_ifreq ifr6;
 
@@ -1115,7 +1115,7 @@ getifhwaddr(const char *ifname, char *buf, u_int16_t *hwtypep, int ppa)
 		(void) snprintf(fname, sizeof (fname), "/dev/%s", ifname);
 	getctl.maxlen = sizeof (getbuf);
 	getctl.buf = (char *)getbuf;
-#ifdef __linux__
+#if defined(__linux__) || defined(__GNU__)
 	if ((fd = open(fname, O_RDWR | O_CLOEXEC)) == -1) {
 #else
 	if ((fd = open(fname, O_RDWR)) == -1) {
@@ -1135,7 +1135,7 @@ getifhwaddr(const char *ifname, char *buf, u_int16_t *hwtypep, int ppa)
 		cp++;
 		dlar.dl_ppa = atoi(cp);
 		*cp = '\0';
-#ifdef __linux__
+#if defined(__linux__) || defined(__GNU__)
 		if ((fd = open(fname, O_RDWR | O_CLOEXEC)) == -1)
 #else
 		if ((fd = open(fname, O_RDWR)) == -1)
@@ -1232,7 +1232,7 @@ gethwid(buf, len, ifname, hwtypep)
 	u_int16_t *hwtypep;
 {
 	struct ifaddrs *ifa, *ifap;
-#ifdef __KAME__
+#if defined (__KAME__) || defined (__FreeBSD_kernel__)
 	struct sockaddr_dl *sdl;
 #endif
 #ifdef __linux__
@@ -1270,7 +1270,7 @@ gethwid(buf, len, ifname, hwtypep)
 			continue;
 		if (ifa->ifa_addr == NULL)
 			continue;
-#ifdef __KAME__
+#if defined (__KAME__) || defined (__FreeBSD_kernel__)
 		if (ifa->ifa_addr->sa_family != AF_LINK)
 			continue;
 
@@ -3257,10 +3257,10 @@ ifaddrconf(cmd, ifname, addr, plen, pltime, vltime)
 	int pltime;
 	int vltime;
 {
-#ifdef __KAME__
+#if defined (__KAME__) || defined (__FreeBSD_kernel__)
 	struct in6_aliasreq req;
 #endif
-#ifdef __linux__
+#if defined(__linux__) || defined(__GNU__)
 	struct in6_ifreq req;
 	struct ifreq ifr;
 #endif
@@ -3274,10 +3274,10 @@ ifaddrconf(cmd, ifname, addr, plen, pltime, vltime)
 	switch(cmd) {
 	case IFADDRCONF_ADD:
 		cmdstr = "add";
-#ifdef __KAME__
+#if defined (__KAME__) || defined (__FreeBSD_kernel__)
 		ioctl_cmd = SIOCAIFADDR_IN6;
 #endif
-#ifdef __linux__
+#if defined(__linux__) || defined(__GNU__)
 		ioctl_cmd = SIOCSIFADDR;
 #endif
 #ifdef __sun__
@@ -3286,10 +3286,10 @@ ifaddrconf(cmd, ifname, addr, plen, pltime, vltime)
 		break;
 	case IFADDRCONF_REMOVE:
 		cmdstr = "remove";
-#ifdef __KAME__
+#if defined (__KAME__) || defined (__FreeBSD_kernel__)
 		ioctl_cmd = SIOCDIFADDR_IN6;
 #endif
-#ifdef __linux__
+#if defined(__linux__) || defined(__GNU__)
 		ioctl_cmd = SIOCDIFADDR;
 #endif
 #ifdef __sun__
@@ -3300,7 +3300,7 @@ ifaddrconf(cmd, ifname, addr, plen, pltime, vltime)
 		return (-1);
 	}
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__GNU__)
 #define SOCKTYPE (SOCK_DGRAM | SOCK_CLOEXEC)
 #else
 #define SOCKTYPE SOCK_DGRAM
@@ -3312,7 +3312,7 @@ ifaddrconf(cmd, ifname, addr, plen, pltime, vltime)
 	}
 
 	memset(&req, 0, sizeof(req));
-#ifdef __KAME__
+#if defined (__KAME__) || defined (__FreeBSD_kernel__)
 	req.ifra_addr = *addr;
 	memcpy(req.ifra_name, ifname, sizeof(req.ifra_name));
 	(void)sa6_plen2mask(&req.ifra_prefixmask, plen);
diff --git a/config.c b/config.c
index e04d6a5..2c5ad5d 100644
--- a/config.c
+++ b/config.c
@@ -35,7 +35,7 @@
 
 #include <net/if.h>
 #include <netinet/in.h>
-#ifdef __KAME__
+#if defined (__KAME__) || defined (__FreeBSD_kernel__)
 #include <net/if_dl.h>
 #endif
 #ifdef __linux__
@@ -48,7 +48,7 @@
 #include <string.h>
 #include <ifaddrs.h>
 #include <errno.h>
-#ifdef __linux__
+#ifdef __GLIBC__
 #define __USE_XOPEN
 #include <time.h>
 #endif
@@ -1227,7 +1227,7 @@ get_default_ifid(pif)
 	struct prefix_ifconf *pif;
 {
 	struct ifaddrs *ifa, *ifap;
-#ifdef __KAME__
+#if defined (__KAME__) || defined (__FreeBSD_kernel__)
 	struct sockaddr_dl *sdl;
 #endif
 #ifdef __linux__
@@ -1254,7 +1254,7 @@ get_default_ifid(pif)
 		if (ifa->ifa_addr == NULL)
 			continue;
 
-#ifdef __KAME__
+#if defined (__KAME__) || defined (__FreeBSD_kernel__)
 		if (ifa->ifa_addr->sa_family != AF_LINK)
 			continue;
 
diff --git a/configure b/configure
index 4722b7b..8b67abe 100755
--- a/configure
+++ b/configure
@@ -2994,7 +2994,7 @@ cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 #include <netinet/in.h>
-#ifdef __KAME__
+#if defined (__KAME__) || defined (__FreeBSD_kernel__)
  yes
 #endif
 _ACEOF
diff --git a/configure.in b/configure.in
index 6da9af5..e320956 100644
--- a/configure.in
+++ b/configure.in
@@ -65,7 +65,7 @@ AC_TRY_COMPILE([#include <sys/queue.h>],
 
 AC_EGREP_CPP(yes,
 [#include <netinet/in.h>
-#ifdef __KAME__
+#if defined (__KAME__) || defined (__FreeBSD_kernel__)
  yes
 #endif], [result=kame], [result=regular])
 AC_MSG_CHECKING(for getaddrinfo/getnameinfo library)
diff --git a/dhcp6_ctl.c b/dhcp6_ctl.c
index f1bae0b..dc6c323 100644
--- a/dhcp6_ctl.c
+++ b/dhcp6_ctl.c
@@ -97,7 +97,7 @@ dhcp6_ctl_init(addr, port, max, sockp)
 		    gai_strerror(error));
 		return (-1);
 	}
-#ifdef __linux__
+#if defined(__linux__) || defined(__GNU__)
 	res->ai_socktype |= SOCK_CLOEXEC;
 #endif
 	ctlsock = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
diff --git a/dhcp6_ctlclient.c b/dhcp6_ctlclient.c
index 2bec3e7..84ede58 100644
--- a/dhcp6_ctlclient.c
+++ b/dhcp6_ctlclient.c
@@ -169,7 +169,7 @@ main(argc, argv)
 
 	s = -1;
 	for (res = res0; res != NULL; res = res->ai_next) {
-#ifdef __linux__
+#if defined(__linux__) || defined(__GNU__)
 		res->ai_socktype |= SOCK_CLOEXEC;
 #endif
 		s = socket(res->ai_family, res->ai_socktype,
diff --git a/dhcp6c.c b/dhcp6c.c
index 1d10a78..4e1356b 100644
--- a/dhcp6c.c
+++ b/dhcp6c.c
@@ -50,7 +50,7 @@
 #endif
 
 #include <netinet/in.h>
-#ifdef __KAME__
+#if defined (__KAME__) || defined (__FreeBSD_kernel__)
 #include <net/if_dl.h>
 #include <netinet6/in6_var.h>
 #endif
@@ -290,7 +290,7 @@ client6_init()
 		    gai_strerror(error));
 		exit(1);
 	}
-#ifdef __linux__
+#if defined(__linux__) || defined(__GNU__)
 	/* Force socket to be closed on execve */
 	res->ai_socktype |= SOCK_CLOEXEC;
 #endif
@@ -350,7 +350,7 @@ client6_init()
 	freeaddrinfo(res);
 
 	/* open a routing socket to watch the routing table */
-#ifdef __linux__
+#if defined(__linux__) || defined(__GNU__)
 #define SOCKTYPE (SOCK_RAW | SOCK_CLOEXEC)
 #else
 #define SOCKTYPE SOCK_RAW
diff --git a/dhcp6relay.c b/dhcp6relay.c
index 200d3cb..ed4aee7 100644
--- a/dhcp6relay.c
+++ b/dhcp6relay.c
@@ -41,7 +41,7 @@
 
 #include <netinet/in.h>
 
-#ifdef __KAME__
+#if defined (__KAME__) || defined (__FreeBSD_kernel__)
 #include <netinet6/in6_var.h>
 #endif
 
@@ -359,7 +359,7 @@ relay6_init(int ifnum, char *iflist[])
 		    gai_strerror(error));
 		goto failexit;
 	}
-#ifdef __linux__
+#if defined(__linux__) || defined(__GNU__)
 	res->ai_socktype |= SOCK_CLOEXEC;
 #endif
 	csock = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
@@ -468,7 +468,7 @@ relay6_init(int ifnum, char *iflist[])
 		goto failexit;
 	}
 	memcpy(&sa6_client, res->ai_addr, sizeof (sa6_client));
-#ifdef __linux__
+#if defined(__linux__) || defined(__GNU__)
 	res->ai_socktype |= SOCK_CLOEXEC;
 #endif
 	ssock = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
diff --git a/dhcp6s.c b/dhcp6s.c
index ff8b17d..a230d75 100644
--- a/dhcp6s.c
+++ b/dhcp6s.c
@@ -51,7 +51,7 @@
 #endif
 
 #include <netinet/in.h>
-#ifdef __KAME__
+#if defined (__KAME__) || defined (__FreeBSD_kernel__)
 #include <netinet6/in6_var.h>
 #endif
 
@@ -532,7 +532,7 @@ server6_init()
 		    strerror(errno));
 		exit(1);
 	}
-#if !defined(__linux__) && !defined(__sun__)
+#if !defined(__linux__) && !defined(__sun__) && !defined(__GNU__)
 	/* make the socket write-only */
 	if (shutdown(outsock, 0)) {
 		debug_printf(LOG_ERR, FNAME, "shutdown(outbound, 0): %s",
diff --git a/if.c b/if.c
index c690671..d69e79a 100644
--- a/if.c
+++ b/if.c
@@ -34,7 +34,7 @@
 
 #include <net/if.h>
 #include <netinet/in.h>
-#ifdef __KAME__
+#if defined (__KAME__) || defined (__FreeBSD_kernel__)
 #include <net/if_dl.h>
 #endif
 
diff --git a/missing/getifaddrs.c b/missing/getifaddrs.c
index 23b3e43..42dba27 100644
--- a/missing/getifaddrs.c
+++ b/missing/getifaddrs.c
@@ -167,7 +167,7 @@ getifaddrs(struct ifaddrs **ifap)
 	struct ifaddrs *ifa = NULL;
 	char *buf;
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__GNU__)
 #define SOCKTYPE (SOCK_DGRAM | SOCK_CLOEXEC)
 #else
 #define SOCKTYPE SOCK_DGRAM