2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009 - 2013 Daniel Borkmann.
4 * Subject to the GPL, version 2.
12 #include <sys/socket.h>
13 #include <linux/if_packet.h>
25 #define PRINT_HEX_ASCII 4
28 extern char *if_indextoname(unsigned ifindex
, char *ifname
);
30 static const char * const packet_types
[256] = {
31 [0 ... 255] = "?", /* Unknown */
32 [PACKET_HOST
] = "<", /* Incoming */
33 [PACKET_BROADCAST
] = "B", /* Broadcast */
34 [PACKET_MULTICAST
] = "M", /* Multicast */
35 [PACKET_OTHERHOST
] = "P", /* Promisc */
36 [PACKET_OUTGOING
] = ">", /* Outgoing */
37 [PACKET_USER
] = ">U", /* To Userspace */
38 [PACKET_KERNEL
] = ">K", /* To Kernelspace */
41 static inline const char *__show_ts_source(uint32_t status
)
43 if (status
& TP_STATUS_TS_RAW_HARDWARE
)
45 else if (status
& TP_STATUS_TS_SYS_HARDWARE
)
47 else if (status
& TP_STATUS_TS_SOFTWARE
)
53 static inline void __show_frame_hdr(struct sockaddr_ll
*s_ll
,
54 void *raw
, int mode
, bool v3
)
57 union tpacket_uhdr hdr
;
59 if (mode
== PRINT_NONE
)
66 packet_types
[s_ll
->sll_pkttype
] ? : "?",
67 if_indextoname(s_ll
->sll_ifindex
, tmp
) ? : "?",
68 v3
? hdr
.h3
->tp_len
: hdr
.h2
->tp_len
);
71 tprintf("%s %s %u %us.%uns %s\n",
72 packet_types
[s_ll
->sll_pkttype
] ? : "?",
73 if_indextoname(s_ll
->sll_ifindex
, tmp
) ? : "?",
74 v3
? hdr
.h3
->tp_len
: hdr
.h2
->tp_len
,
75 v3
? hdr
.h3
->tp_sec
: hdr
.h2
->tp_sec
,
76 v3
? hdr
.h3
->tp_nsec
: hdr
.h2
->tp_nsec
,
77 v3
? "" : __show_ts_source(hdr
.h2
->tp_status
));
82 static inline void show_frame_hdr(struct frame_map
*hdr
, int mode
)
84 __show_frame_hdr(&hdr
->s_ll
, &hdr
->tp_h
, mode
, false);
87 extern void dissector_init_all(int fnttype
);
88 extern void dissector_entry_point(uint8_t *packet
, size_t len
, int linktype
, int mode
);
89 extern void dissector_cleanup_all(void);
90 extern int dissector_set_print_type(void *ptr
, int type
);
92 #endif /* DISSECTOR_H */