diff mbox series

[xtables] xtables-monitor: fix build with older glibc

Message ID 3a3a9bd4da64a6ea681bb3c06637f0bbb89d3808.1542257809.git.baruch@tkos.co.il
State Superseded
Delegated to: Pablo Neira
Headers show
Series [xtables] xtables-monitor: fix build with older glibc | expand

Commit Message

Baruch Siach Nov. 15, 2018, 4:56 a.m. UTC
glibc older than 2.19 require _BSD_SOURCE to expose BSD style fields of
struct tcphdr. Fix the following build failure:

xtables-monitor.c: In function 'trace_print_packet':
xtables-monitor.c:406:43: error: 'const struct tcphdr' has no member named 'th_sport'
    printf("SPORT=%d DPORT=%d ", ntohs(tcph->th_sport), ntohs(tcph->th_dport));
                                           ^
xtables-monitor.c:406:66: error: 'const struct tcphdr' has no member named 'th_dport'
    printf("SPORT=%d DPORT=%d ", ntohs(tcph->th_sport), ntohs(tcph->th_dport));
                                                                  ^
...

Cc: Florian Westphal <fw@strlen.de>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
 iptables/xtables-monitor.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Florian Westphal Nov. 15, 2018, 8:12 a.m. UTC | #1
Baruch Siach <baruch@tkos.co.il> wrote:
> glibc older than 2.19 require _BSD_SOURCE to expose BSD style fields of
> struct tcphdr. Fix the following build failure:
> 
> xtables-monitor.c: In function 'trace_print_packet':
> xtables-monitor.c:406:43: error: 'const struct tcphdr' has no member named 'th_sport'
>     printf("SPORT=%d DPORT=%d ", ntohs(tcph->th_sport), ntohs(tcph->th_dport));
>                                            ^
> xtables-monitor.c:406:66: error: 'const struct tcphdr' has no member named 'th_dport'
>     printf("SPORT=%d DPORT=%d ", ntohs(tcph->th_sport), ntohs(tcph->th_dport));

Thanks for the patch, but this gives me:

> +#define _BSD_SOURCE

In file included from /usr/include/bits/libc-header-start.h:33:0, from /usr/include/stdlib.h:25,
from xtables-monitor.c:13: /usr/include/features.h:184:3:
# warning "_BSD_SOURCE and # _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"

build does complete though.
Does _DEFAULT_SOURCE work for older glibc as well?
Baruch Siach Nov. 15, 2018, 8:26 a.m. UTC | #2
Hi Florian,

Florian Westphal writes:
> Baruch Siach <baruch@tkos.co.il> wrote:
>> glibc older than 2.19 require _BSD_SOURCE to expose BSD style fields of
>> struct tcphdr. Fix the following build failure:
>>
>> xtables-monitor.c: In function 'trace_print_packet':
>> xtables-monitor.c:406:43: error: 'const struct tcphdr' has no member named 'th_sport'
>>     printf("SPORT=%d DPORT=%d ", ntohs(tcph->th_sport), ntohs(tcph->th_dport));
>>                                            ^
>> xtables-monitor.c:406:66: error: 'const struct tcphdr' has no member named 'th_dport'
>>     printf("SPORT=%d DPORT=%d ", ntohs(tcph->th_sport), ntohs(tcph->th_dport));
>
> Thanks for the patch, but this gives me:
>
>> +#define _BSD_SOURCE
>
> In file included from /usr/include/bits/libc-header-start.h:33:0, from /usr/include/stdlib.h:25,
> from xtables-monitor.c:13: /usr/include/features.h:184:3:
> # warning "_BSD_SOURCE and # _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"
>
> build does complete though.
> Does _DEFAULT_SOURCE work for older glibc as well?

It doesn't. I guess that the alternative is to use the GNU names for
tcphdr fields. That should work with any glibc version. Would you
approve a patch doing that?

Thanks,
baruch

--
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch@tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -
Florian Westphal Nov. 15, 2018, 8:32 a.m. UTC | #3
Baruch Siach <baruch@tkos.co.il> wrote:
> Hi Florian,
> 
> Florian Westphal writes:
> > Baruch Siach <baruch@tkos.co.il> wrote:
> >> glibc older than 2.19 require _BSD_SOURCE to expose BSD style fields of
> >> struct tcphdr. Fix the following build failure:
> >>
> >> xtables-monitor.c: In function 'trace_print_packet':
> >> xtables-monitor.c:406:43: error: 'const struct tcphdr' has no member named 'th_sport'
> >>     printf("SPORT=%d DPORT=%d ", ntohs(tcph->th_sport), ntohs(tcph->th_dport));
> >>                                            ^
> >> xtables-monitor.c:406:66: error: 'const struct tcphdr' has no member named 'th_dport'
> >>     printf("SPORT=%d DPORT=%d ", ntohs(tcph->th_sport), ntohs(tcph->th_dport));
> >
> > Thanks for the patch, but this gives me:
> >
> >> +#define _BSD_SOURCE
> >
> > In file included from /usr/include/bits/libc-header-start.h:33:0, from /usr/include/stdlib.h:25,
> > from xtables-monitor.c:13: /usr/include/features.h:184:3:
> > # warning "_BSD_SOURCE and # _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"
> >
> > build does complete though.
> > Does _DEFAULT_SOURCE work for older glibc as well?
> 
> It doesn't.

Figures...

> I guess that the alternative is to use the GNU names for
> tcphdr fields. That should work with any glibc version. Would you
> approve a patch doing that?

Sure, thanks a lot!
diff mbox series

Patch

diff --git a/iptables/xtables-monitor.c b/iptables/xtables-monitor.c
index 3b1ca777a28a..f664dc541ab3 100644
--- a/iptables/xtables-monitor.c
+++ b/iptables/xtables-monitor.c
@@ -9,6 +9,7 @@ 
  * This software has been sponsored by Sophos Astaro <http://www.sophos.com>
  */
 
+#define _BSD_SOURCE
 #include <stdlib.h>
 #include <time.h>
 #include <string.h>