From: Roy Marples Date: Mon, 20 Apr 2015 09:02:58 +0000 (+0000) Subject: Give up on _BSD_SOURCE and use _GNU_SOURCE for Linux. X-Git-Tag: v6.8.2~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e522a24bc6c537550aa66ec83a7629c0519ccdc;p=thirdparty%2Fdhcpcd.git Give up on _BSD_SOURCE and use _GNU_SOURCE for Linux. This is requires for newer Linux headers as there is no easy way to get at the in6_pktinfo structure, so we have to fallback to the glibc variant which requires _GNU_SOURCE being set. This does have the advantage of no longer sprinkling _GNU_SOURCE around and no longer having to cast ipi.ipi_ifindex but may break compile on older Linux. --- diff --git a/common.c b/common.c index 1b6a994e..f930ee00 100644 --- a/common.c +++ b/common.c @@ -25,11 +25,6 @@ * SUCH DAMAGE. */ -/* Needed define to get at getline for glibc and FreeBSD */ -#ifndef _GNU_SOURCE -# define _GNU_SOURCE -#endif - #ifdef __APPLE__ # include # include diff --git a/configure b/configure index 4ba9382c..b13c2326 100755 --- a/configure +++ b/configure @@ -360,23 +360,21 @@ if [ -n "$FORK" -a "$FORK" != yes -a "$FORK" != true ]; then fi case "$OS" in -kfreebsd*) +freebsd*|kfreebsd*) echo "CPPFLAGS+= -D_GNU_SOURCE" >>$CONFIG_MK echo "DHCPCD_SRCS+= if-bsd.c" >>$CONFIG_MK ;; linux*) - echo "CPPFLAGS+= -D_BSD_SOURCE -D_XOPEN_SOURCE=700" >>$CONFIG_MK + echo "CPPFLAGS+= -D_GNU_SOURCE" >>$CONFIG_MK # Large File Support, should be fine for 32-bit systems. # But if this is the case, why is it not set by default? echo "CPPFLAGS+= -D_FILE_OFFSET_BITS=64" >>$CONFIG_MK echo "CPPFLAGS+= -D_LARGEFILE_SOURCE" >>$CONFIG_MK echo "CPPFLAGS+= -D_LARGEFILE64_SOURCE" >>$CONFIG_MK - # glibc-2.20 - echo "CPPFLAGS+= -D_DEFAULT_SOURCE" >>$CONFIG_MK echo "DHCPCD_SRCS+= if-linux.c" >>$CONFIG_MK # for RTM_NEWADDR and friends - echo "#include /* fix broken headers */" >>$CONFIG_H - echo "#include " >>$CONFIG_H + echo "#include /* fix broken headers */" >>$CONFIG_H + echo "#include " >>$CONFIG_H ;; qnx*) echo "CPPFLAGS+= -D__EXT" >>$CONFIG_MK @@ -594,7 +592,6 @@ fi if [ -z "$GETLINE" ]; then printf "Testing for getline ... " cat <_getline.c -#define _GNU_SOURCE #include int main(void) { char *buf = NULL; diff --git a/dhcp6.c b/dhcp6.c index 15cdcfa4..5b98180c 100644 --- a/dhcp6.c +++ b/dhcp6.c @@ -1151,7 +1151,7 @@ logsend: cm->cmsg_type = IPV6_PKTINFO; cm->cmsg_len = CMSG_LEN(sizeof(pi)); memset(&pi, 0, sizeof(pi)); - pi.ipi6_ifindex = CAST_IPI6_IFINDEX(ifp->index); + pi.ipi6_ifindex = ifp->index; memcpy(CMSG_DATA(cm), &pi, sizeof(pi)); if (sendmsg(ctx->dhcp_fd, &ctx->sndhdr, 0) == -1) { diff --git a/eloop.c b/eloop.c index 32614879..e479ac16 100644 --- a/eloop.c +++ b/eloop.c @@ -25,9 +25,6 @@ * SUCH DAMAGE. */ -/* Needed for ppoll(2) */ -#define _GNU_SOURCE - #include #include diff --git a/ipv6.h b/ipv6.h index 5e7f2cdf..a2e3042c 100644 --- a/ipv6.h +++ b/ipv6.h @@ -29,14 +29,8 @@ #define IPV6_H #include - #include -#if defined(__linux__) && defined(__GLIBC__) -# define _LINUX_IN6_H -# include -#endif - #include "config.h" #include "dhcpcd.h" @@ -196,13 +190,6 @@ struct ipv6_state { CMSG_SPACE(sizeof(int))) -/* ipi6.ifiindex differes between OS's so have a cast function */ -#ifdef __GLIBC__ -#define CAST_IPI6_IFINDEX(idx) (int)(idx) -#else -#define CAST_IPI6_IFINDEX(idx) (idx) -#endif - #ifdef INET6 struct ipv6_ctx { struct sockaddr_in6 from; diff --git a/ipv6nd.c b/ipv6nd.c index 4df88650..4f24163a 100644 --- a/ipv6nd.c +++ b/ipv6nd.c @@ -295,7 +295,7 @@ ipv6nd_sendrsprobe(void *arg) cm->cmsg_type = IPV6_PKTINFO; cm->cmsg_len = CMSG_LEN(sizeof(pi)); memset(&pi, 0, sizeof(pi)); - pi.ipi6_ifindex = CAST_IPI6_IFINDEX(ifp->index); + pi.ipi6_ifindex = ifp->index; memcpy(CMSG_DATA(cm), &pi, sizeof(pi)); logger(ifp->ctx, LOG_DEBUG,