From b21c598a396678831dc34baad800a940f883b3cd Mon Sep 17 00:00:00 2001 From: Kylie McClain Date: Tue, 9 Feb 2016 18:58:55 -0500 Subject: [PATCH] Fix struct redefinition errors when using netinet/tcp.h When using non-glibc libraries, they may define their own structs in netinet/tcp.h, which we also attempt to define. If not glibc, we will define __UAPI_DEF_TCPHDR=0 so that tcp.h's inclusion does not attempt to redefine the tcphdr struct, which on non-glibc libraries such as musl libc, are defined by the libc's netinet/tcp.h. --- include/uapi/linux/libc-compat.h | 6 ++++++ include/uapi/linux/tcp.h | 3 +++ 2 files changed, 9 insertions(+) diff --git a/include/uapi/linux/libc-compat.h b/include/uapi/linux/libc-compat.h index 8ca6895..f508429 100644 --- a/include/uapi/linux/libc-compat.h +++ b/include/uapi/linux/libc-compat.h @@ -57,6 +57,12 @@ #define __UAPI_DEF_ETHHDR 1 #endif +#ifdef _NETINET_TCP_H /* musl */ +#define __UAPI_DEF_TCPHDR 0 +#else /* glibc uses _NETINET_TCP_H, but does not include the kernel header. */ +#define __UAPI_DEF_TCPHDR 1 +#endif + /* Coordinate with libc netinet/in.h header. */ #if defined(_NETINET_IN_H) diff --git a/include/uapi/linux/tcp.h b/include/uapi/linux/tcp.h index 65a77b0..2cbd606 100644 --- a/include/uapi/linux/tcp.h +++ b/include/uapi/linux/tcp.h @@ -20,7 +20,9 @@ #include #include #include +#include +#if __UAPI_DEF_TCPHDR struct tcphdr { __be16 source; __be16 dest; @@ -55,6 +57,7 @@ struct tcphdr { __sum16 check; __be16 urg_ptr; }; +#endif /* * The union cast uses a gcc extension to avoid aliasing problems