From 58f49a6ac6df31c614b1953d2532bd5bdad2752b Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Mon, 28 Jan 2013 13:40:51 +0100 Subject: [PATCH] dissector: remove redundant code, clean up a bit Signed-off-by: Daniel Borkmann --- dissector.h | 155 +++++++++++++++++++++++++++--------------------------------- pcap.h | 7 --- 2 files changed, 70 insertions(+), 92 deletions(-) rewrite dissector.h (60%) diff --git a/dissector.h b/dissector.h dissimilarity index 60% index a3ba8da7..200ef4c5 100644 --- a/dissector.h +++ b/dissector.h @@ -1,85 +1,70 @@ -/* - * netsniff-ng - the packet sniffing beast - * By Daniel Borkmann - * Copyright 2009, 2010 Daniel Borkmann. - * Subject to the GPL, version 2. - */ - -#ifndef DISSECTOR_H -#define DISSECTOR_H - -#include -#include - -#include "ring.h" -#include "tprintf.h" - -#define LINKTYPE_NULL 0 /* BSD loopback encapsulation */ -#define LINKTYPE_EN10MB 1 /* Ethernet (10Mb) */ -#define LINKTYPE_EN3MB 2 /* Experimental Ethernet (3Mb) */ -#define LINKTYPE_AX25 3 /* Amateur Radio AX.25 */ -#define LINKTYPE_PRONET 4 /* Proteon ProNET Token Ring */ -#define LINKTYPE_CHAOS 5 /* Chaos */ -#define LINKTYPE_IEEE802 6 /* 802.5 Token Ring */ -#define LINKTYPE_ARCNET 7 /* ARCNET, with BSD-style header */ -#define LINKTYPE_SLIP 8 /* Serial Line IP */ -#define LINKTYPE_PPP 9 /* Point-to-point Protocol */ -#define LINKTYPE_FDDI 10 /* FDDI */ -#define LINKTYPE_IEEE802_11 105 /* IEEE 802.11 wireless */ - -#define PRINT_NORM 0 -#define PRINT_LESS 1 -#define PRINT_HEX 2 -#define PRINT_ASCII 3 -#define PRINT_HEX_ASCII 4 -#define PRINT_NONE 5 - -extern void dissector_init_all(int fnttype); -extern void dissector_entry_point(uint8_t *packet, size_t len, int linktype, int mode); -extern void dissector_cleanup_all(void); -extern int dissector_set_print_type(void *ptr, int type); - -static const char * const packet_types[]={ - "<", /* Incoming */ - "B", /* Broadcast */ - "M", /* Multicast */ - "P", /* Promisc */ - ">", /* Outgoing */ - "?", /* Unknown */ -}; - -static inline void show_frame_hdr(struct frame_map *hdr, int mode, - enum ring_mode rmode) -{ - if (mode == PRINT_NONE) - return; - - switch (mode) { - case PRINT_LESS: - if (rmode == RING_MODE_INGRESS) { - tprintf("%s %d %u", - packet_types[hdr->s_ll.sll_pkttype], - hdr->s_ll.sll_ifindex, hdr->tp_h.tp_len); - } else { - tprintf("%u ", hdr->tp_h.tp_len); - } - break; - case PRINT_NORM: - case PRINT_HEX: - case PRINT_ASCII: - case PRINT_HEX_ASCII: - default: - if (rmode == RING_MODE_INGRESS) { - tprintf("%s %d %u %us.%uns\n", - packet_types[hdr->s_ll.sll_pkttype], - hdr->s_ll.sll_ifindex, hdr->tp_h.tp_len, - hdr->tp_h.tp_sec, hdr->tp_h.tp_nsec); - } else { - tprintf("%u %us.%uns\n", hdr->tp_h.tp_len, - hdr->tp_h.tp_sec, hdr->tp_h.tp_nsec); - } - break; - } -} - -#endif /* DISSECTOR_H */ +/* + * netsniff-ng - the packet sniffing beast + * By Daniel Borkmann + * Copyright 2009 - 2013 Daniel Borkmann. + * Subject to the GPL, version 2. + */ + +#ifndef DISSECTOR_H +#define DISSECTOR_H + +#include +#include + +#include "ring.h" +#include "tprintf.h" +#include "pcap.h" + +#define PRINT_NORM 0 +#define PRINT_LESS 1 +#define PRINT_HEX 2 +#define PRINT_ASCII 3 +#define PRINT_HEX_ASCII 4 +#define PRINT_NONE 5 + +static const char * const packet_types[256]={ + "<", /* Incoming */ + "B", /* Broadcast */ + "M", /* Multicast */ + "P", /* Promisc */ + ">", /* Outgoing */ + "?", /* Unknown */ +}; + +extern char *if_indextoname(unsigned ifindex, char *ifname); + +static inline void show_frame_hdr(struct frame_map *hdr, int mode, + enum ring_mode rmode) +{ + char tmp[IFNAMSIZ]; + + if (mode == PRINT_NONE) + return; + + switch (mode) { + case PRINT_LESS: + tprintf("%s %s %u", + packet_types[hdr->s_ll.sll_pkttype] ? : "?", + if_indextoname(hdr->s_ll.sll_ifindex, tmp) ? : "?", + hdr->tp_h.tp_len); + break; + case PRINT_NORM: + case PRINT_HEX: + case PRINT_ASCII: + case PRINT_HEX_ASCII: + default: + tprintf("%s %s %u %us.%uns\n", + packet_types[hdr->s_ll.sll_pkttype] ? : "?", + if_indextoname(hdr->s_ll.sll_ifindex, tmp) ? : "?", + hdr->tp_h.tp_len, hdr->tp_h.tp_sec, + hdr->tp_h.tp_nsec); + break; + } +} + +extern void dissector_init_all(int fnttype); +extern void dissector_entry_point(uint8_t *packet, size_t len, int linktype, int mode); +extern void dissector_cleanup_all(void); +extern int dissector_set_print_type(void *ptr, int type); + +#endif /* DISSECTOR_H */ diff --git a/pcap.h b/pcap.h index 23afd972..e1cd5b3b 100644 --- a/pcap.h +++ b/pcap.h @@ -270,9 +270,6 @@ static inline void pcap_pkthdr_to_tpacket_hdr(pcap_pkthdr_t *phdr, thdr->tp_nsec = phdr->ppk.ts.tv_usec * 1000; thdr->tp_snaplen = phdr->ppk.caplen; thdr->tp_len = phdr->ppk.len; - sll->sll_ifindex = phdr->ppk.ifindex; - sll->sll_protocol = phdr->ppk.protocol; - sll->sll_pkttype = phdr->ppk.pkttype; break; case BORKMANN: @@ -280,10 +277,6 @@ static inline void pcap_pkthdr_to_tpacket_hdr(pcap_pkthdr_t *phdr, thdr->tp_nsec = phdr->ppb.ts.tv_nsec; thdr->tp_snaplen = phdr->ppb.caplen; thdr->tp_len = phdr->ppb.len; - sll->sll_ifindex = (int) phdr->ppb.ifindex; - sll->sll_protocol = phdr->ppb.protocol; - sll->sll_hatype = phdr->ppb.hatype; - sll->sll_pkttype = phdr->ppb.pkttype; break; default: -- 2.11.4.GIT