From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.101.70]) by dpdk.org (Postfix) with ESMTP id A42082BB1 for ; Tue, 28 Aug 2018 22:47:08 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BE66080D; Tue, 28 Aug 2018 13:47:07 -0700 (PDT) Received: from armada8040-2.austin.arm.com (armada8040-2.austin.arm.com [10.118.12.35]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4F0783F5BD; Tue, 28 Aug 2018 13:47:07 -0700 (PDT) From: Malvika Gupta To: konstantin.ananyev@intel.com Cc: dev@dpdk.org, gavin.hu@arm.com, honnappa.nagarahalli@arm.com, brian.brooks@arm.com, nd@arm.com, Malvika Gupta , Malvika Gupta Date: Tue, 28 Aug 2018 15:46:19 -0500 Message-Id: <20180828204620.1862-1-Malvika.Gupta@arm.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH] test/bpf: use hton instead of __builtin_bswap X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Aug 2018 20:47:08 -0000 Convert host machine endianness to networking endianness for comparison of incoming packets with BPF filter Signed-off-by: Malvika Gupta Reviewed-by: Gavin Hu Reviewed-by: Brian Brooks Suggested-by: Brian Brooks --- test/bpf/t1.c | 7 ++++--- test/bpf/t3.c | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/test/bpf/t1.c b/test/bpf/t1.c index 60f9434ab..7943fcf34 100644 --- a/test/bpf/t1.c +++ b/test/bpf/t1.c @@ -28,24 +28,25 @@ #include #include #include +#include uint64_t entry(void *pkt) { struct ether_header *ether_header = (void *)pkt; - if (ether_header->ether_type != __builtin_bswap16(0x0800)) + if (ether_header->ether_type != htons(0x0800)) return 0; struct iphdr *iphdr = (void *)(ether_header + 1); if (iphdr->protocol != 17 || (iphdr->frag_off & 0x1ffff) != 0 || - iphdr->daddr != __builtin_bswap32(0x1020304)) + iphdr->daddr != htonl(0x1020304)) return 0; int hlen = iphdr->ihl * 4; struct udphdr *udphdr = (void *)iphdr + hlen; - if (udphdr->dest != __builtin_bswap16(5000)) + if (udphdr->dest != htons(5000)) return 0; return 1; diff --git a/test/bpf/t3.c b/test/bpf/t3.c index 531b9cb8c..24298b7c7 100644 --- a/test/bpf/t3.c +++ b/test/bpf/t3.c @@ -17,6 +17,7 @@ #include #include #include "mbuf.h" +#include extern void rte_pktmbuf_dump(FILE *, const struct rte_mbuf *, unsigned int); @@ -29,7 +30,7 @@ entry(const void *pkt) mb = pkt; eth = rte_pktmbuf_mtod(mb, const struct ether_header *); - if (eth->ether_type == __builtin_bswap16(ETHERTYPE_ARP)) + if (eth->ether_type == htons(ETHERTYPE_ARP)) rte_pktmbuf_dump(stdout, mb, 64); return 1; -- 2.17.1