From patchwork Fri Nov 16 05:23:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baruch Siach X-Patchwork-Id: 998768 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netfilter-devel-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=tkos.co.il Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42x68r3855z9sBN for ; Fri, 16 Nov 2018 16:23:56 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727273AbeKPPes (ORCPT ); Fri, 16 Nov 2018 10:34:48 -0500 Received: from guitar.tcltek.co.il ([192.115.133.116]:48167 "EHLO mx.tkos.co.il" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727124AbeKPPes (ORCPT ); Fri, 16 Nov 2018 10:34:48 -0500 Received: from tarshish.tkos.co.il (unknown [10.0.8.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx.tkos.co.il (Postfix) with ESMTPS id E3E4844004B; Fri, 16 Nov 2018 07:23:51 +0200 (IST) From: Baruch Siach To: Pablo Neira Ayuso Cc: netfilter-devel@vger.kernel.org, Baruch Siach , Florian Westphal Subject: [PATCH xtables v2] xtables-monitor: fix build with older glibc Date: Fri, 16 Nov 2018 07:23:32 +0200 Message-Id: <5516362e95ce7352e8b99906846fb69ea0730d38.1542345812.git.baruch@tkos.co.il> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org glibc older than 2.19 only expose BSD style fields of struct tcphdr when _BSD_SOURCE is define. Current glibc however, warn that _BSD_SOURCE is deprecated. Migrate to the GNU style of tcphdr fields to make the code compatible with any glibc version. 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 Signed-off-by: Baruch Siach --- v2: Use GNU tcphdr fields Note: build tested only. --- iptables/xtables-monitor.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/iptables/xtables-monitor.c b/iptables/xtables-monitor.c index 3b1ca777a28a..5d1611122df5 100644 --- a/iptables/xtables-monitor.c +++ b/iptables/xtables-monitor.c @@ -403,26 +403,24 @@ static void trace_print_packet(const struct nftnl_trace *nlt, struct cb_arg *arg case IPPROTO_UDP: if (len < 4) break; - printf("SPORT=%d DPORT=%d ", ntohs(tcph->th_sport), ntohs(tcph->th_dport)); + printf("SPORT=%d DPORT=%d ", ntohs(tcph->source), ntohs(tcph->dest)); break; case IPPROTO_TCP: if (len < sizeof(*tcph)) break; - printf("SPORT=%d DPORT=%d ", ntohs(tcph->th_sport), ntohs(tcph->th_dport)); - if (tcph->th_flags & (TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG)) { - if (tcph->th_flags & TH_SYN) - printf("SYN "); - if (tcph->th_flags & TH_ACK) - printf("ACK "); - if (tcph->th_flags & TH_FIN) - printf("FIN "); - if (tcph->th_flags & TH_RST) - printf("RST "); - if (tcph->th_flags & TH_PUSH) - printf("PSH "); - if (tcph->th_flags & TH_URG) - printf("URG "); - } + printf("SPORT=%d DPORT=%d ", ntohs(tcph->source), ntohs(tcph->dest)); + if (tcph->syn) + printf("SYN "); + if (tcph->ack) + printf("ACK "); + if (tcph->fin) + printf("FIN "); + if (tcph->rst) + printf("RST "); + if (tcph->psh) + printf("PSH "); + if (tcph->urg) + printf("URG "); break; default: break;