Skip to contentSkip to conversation

src: fix build with musl libc

PATCH In review Rodrigo Rebello 2 participants 4 messages Nov 23, 2015 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 src: fix build with musl libc

The GNU version of 'struct tcphdr' is not exposed by musl libc headers unless _GNU_SOURCE is defined. Without this definition, the build fails with:

rpc.c: In function 'rpc_helper_cb':
rpc.c:351:15: error: 'struct tcphdr' has no member named 'doff'

     offset += th->doff * 4;
                 ^
---
 src/helpers/rpc.c | 1 +
 1 file changed, 1 insertion(+)
src/helpers/rpc.c +1 -0
index 82493c2..3a7b337 100644
@@ -28,6 +28,7 @@
 
 #include <rpc/rpc_msg.h>
 #include <rpc/pmap_prot.h>
+#define _GNU_SOURCE
 #include <netinet/tcp.h>
 #include <netinet/udp.h>
 
Signature · 1 line
2.1.4
#1 lore raw
Quoted 8 lines · Rodrigo Rebello

The GNU version of 'struct tcphdr' is not exposed by musl libc headers unless _GNU_SOURCE is defined. Without this definition, the build fails with:

rpc.c: In function 'rpc_helper_cb':
rpc.c:351:15: error: 'struct tcphdr' has no member named 'doff'

     offset += th->doff * 4;
                 ^

You can probably update the code to use the non-GNU version, that should work both with musl, libc and any other new version that sticks to the standard.

Thanks.

#2 lore raw

Pablo,

2015-11-23 9:07 GMT-02:00 Pablo Neira Ayuso <[email protected]>:

Quoted 10 lines · Rodrigo Rebello
Quoted 8 lines

The GNU version of 'struct tcphdr' is not exposed by musl libc headers unless _GNU_SOURCE is defined. Without this definition, the build fails with:

rpc.c: In function 'rpc_helper_cb':
rpc.c:351:15: error: 'struct tcphdr' has no member named 'doff'

     offset += th->doff * 4;
                 ^
Quoted 5 lines

You can probably update the code to use the non-GNU version, that should work both with musl, libc and any other new version that sticks to the standard.

Thanks.

I could change 'doff' to 'th_off' in rpc.c:351, which is the name used in the BSD version of 'struct tcphdr', but then I'd have to define the macro __FAVOR_BSD in order to get the code to compile with uClibc (in contrast to musl, uClibc only exposes the GNU version by default).

So, I don't see any advantages in doing that (changing the member name
+ defining __FAVOR_BSD) instead of simply defining _GNU_SOURCE. Besides, I've noticed that a similar issue has been solved before by using the same approach (commit fe1f2d58add1e56e651c43de8cd60db8123d49bb).

Regards,
Rodrigo

#3 lore raw
Quoted 24 lines · Rodrigo Rebello

Pablo,

2015-11-23 9:07 GMT-02:00 Pablo Neira Ayuso <[email protected]>:

Quoted 10 lines · Rodrigo Rebello
Quoted 8 lines

The GNU version of 'struct tcphdr' is not exposed by musl libc headers unless _GNU_SOURCE is defined. Without this definition, the build fails with:

rpc.c: In function 'rpc_helper_cb':
rpc.c:351:15: error: 'struct tcphdr' has no member named 'doff'

     offset += th->doff * 4;
                 ^
Quoted 5 lines

You can probably update the code to use the non-GNU version, that should work both with musl, libc and any other new version that sticks to the standard.

Thanks.

I could change 'doff' to 'th_off' in rpc.c:351, which is the name used in the BSD version of 'struct tcphdr', but then I'd have to define the macro __FAVOR_BSD in order to get the code to compile with uClibc (in contrast to musl, uClibc only exposes the GNU version by default).

Quoted 5 lines

So, I don't see any advantages in doing that (changing the member name
+ defining __FAVOR_BSD) instead of simply defining _GNU_SOURCE. Besides, I've noticed that a similar issue has been solved before by using the same approach (commit fe1f2d58add1e56e651c43de8cd60db8123d49bb).

OK, I have pushed out your patch. Thanks.