From 0535f86bffe97cb99832973706785e3054f97af2 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 24 Jan 2013 08:42:13 +0100 Subject: [PATCH] ipv4: Move struct ipv4hdr definition to separate header proto_ipv4.c and trie.c both define the exact same struct ipv4hdr, so get rid of the duplication and move the definition to a separate header. Signed-off-by: Tobias Klauser --- src/ipv4.h | 37 +++++++++++++++++++++++++++++++++++++ src/proto_ipv4.c | 23 +---------------------- src/trie.c | 22 +--------------------- 3 files changed, 39 insertions(+), 43 deletions(-) create mode 100644 src/ipv4.h diff --git a/src/ipv4.h b/src/ipv4.h new file mode 100644 index 00000000..7e69cd10 --- /dev/null +++ b/src/ipv4.h @@ -0,0 +1,37 @@ +/* + * netsniff-ng - the packet sniffing beast + * By Daniel Borkmann . + * Copyright (C) 2009, 2010 Daniel Borkmann + * Copyright (C) 2012 Christoph Jaeger + * Subject to the GPL, version 2. + */ + +#ifndef IPV4_H +#define IPV4_H + +#include + +#include "built_in.h" + +struct ipv4hdr { +#if defined(__LITTLE_ENDIAN_BITFIELD) + __extension__ uint8_t h_ihl:4, + h_version:4; +#elif defined (__BIG_ENDIAN_BITFIELD) + __extension__ uint8_t h_version:4, + h_ihl:4; +#else +# error "Please fix " +#endif + uint8_t h_tos; + uint16_t h_tot_len; + uint16_t h_id; + uint16_t h_frag_off; + uint8_t h_ttl; + uint8_t h_protocol; + uint16_t h_check; + uint32_t h_saddr; + uint32_t h_daddr; +} __packed; + +#endif /* IPV4_H */ diff --git a/src/proto_ipv4.c b/src/proto_ipv4.c index d9d432a9..af920f9f 100644 --- a/src/proto_ipv4.c +++ b/src/proto_ipv4.c @@ -10,36 +10,15 @@ #include #include /* for ntohs() */ #include /* for inet_ntop() */ -#include #include "proto.h" #include "protos.h" #include "csum.h" #include "dissector_eth.h" +#include "ipv4.h" #include "pkt_buff.h" #include "built_in.h" -struct ipv4hdr { -#if defined(__LITTLE_ENDIAN_BITFIELD) - __extension__ uint8_t h_ihl:4, - h_version:4; -#elif defined (__BIG_ENDIAN_BITFIELD) - __extension__ uint8_t h_version:4, - h_ihl:4; -#else -# error "Please fix " -#endif - uint8_t h_tos; - uint16_t h_tot_len; - uint16_t h_id; - uint16_t h_frag_off; - uint8_t h_ttl; - uint8_t h_protocol; - uint16_t h_check; - uint32_t h_saddr; - uint32_t h_daddr; -} __packed; - #define FRAG_OFF_RESERVED_FLAG(x) ((x) & 0x8000) #define FRAG_OFF_NO_FRAGMENT_FLAG(x) ((x) & 0x4000) #define FRAG_OFF_MORE_FRAGMENT_FLAG(x) ((x) & 0x2000) diff --git a/src/trie.c b/src/trie.c index 29b50b5d..f0af2760 100644 --- a/src/trie.c +++ b/src/trie.c @@ -13,27 +13,7 @@ #include "patricia.h" #include "locking.h" #include "trie.h" - -struct ipv4hdr { -#if defined(__LITTLE_ENDIAN_BITFIELD) - __extension__ uint8_t h_ihl:4, - h_version:4; -#elif defined (__BIG_ENDIAN_BITFIELD) - __extension__ uint8_t h_version:4, - h_ihl:4; -#else -# error "Please fix " -#endif - uint8_t h_tos; - uint16_t h_tot_len; - uint16_t h_id; - uint16_t h_frag_off; - uint8_t h_ttl; - uint8_t h_protocol; - uint16_t h_check; - uint32_t h_saddr; - uint32_t h_daddr; -} __attribute__((packed)); +#include "ipv4.h" struct ipv6hdr { #if defined(__LITTLE_ENDIAN_BITFIELD) -- 2.11.4.GIT