Skip to content

Commit

Permalink
netsniff-ng: Show packet number
Browse files Browse the repository at this point in the history
Show the packet number as part of the dissector output.

Example:

> wlp3s0 107 1430159373s.693002029ns  (#5)
 [ Eth MAC (6c:88:14:ac:51:e4 => 10:fe:ed:90:22:12), Proto (0x0800, IPv4) ]

Signed-off-by: Vadim Kochan <[email protected]>
Signed-off-by: Tobias Klauser <[email protected]>
  • Loading branch information
vkochan authored and tklauser committed May 2, 2015
1 parent f17e4b9 commit 6b85cfe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
18 changes: 11 additions & 7 deletions dissector.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static inline const char *__show_ts_source(uint32_t status)

static inline void __show_frame_hdr(uint8_t *packet, size_t len, int linktype,
struct sockaddr_ll *s_ll, void *raw_hdr,
int mode, bool v3)
int mode, bool v3, unsigned long count)
{
char tmp[IFNAMSIZ];
union tpacket_uhdr hdr;
Expand All @@ -76,27 +76,31 @@ static inline void __show_frame_hdr(uint8_t *packet, size_t len, int linktype,
hdr.raw = raw_hdr;
switch (mode) {
case PRINT_LESS:
tprintf("%s %s %u",
tprintf("%s %s %u (#%lu) ",
packet_types[pkttype] ? : "?",
if_indextoname(s_ll->sll_ifindex, tmp) ? : "?",
tpacket_uhdr(hdr, tp_len, v3));
tpacket_uhdr(hdr, tp_len, v3),
count);
break;
default:
tprintf("%s %s %u %us.%uns %s\n",
tprintf("%s %s %u %us.%uns %s (#%lu)\n",
packet_types[pkttype] ? : "?",
if_indextoname(s_ll->sll_ifindex, tmp) ? : "?",
tpacket_uhdr(hdr, tp_len, v3),
tpacket_uhdr(hdr, tp_sec, v3),
tpacket_uhdr(hdr, tp_nsec, v3),
v3 ? "" : __show_ts_source(hdr.h2->tp_status));
v3 ? "" : __show_ts_source(hdr.h2->tp_status),
count);
break;
}
}

static inline void show_frame_hdr(uint8_t *packet, size_t len, int linktype,
struct frame_map *hdr, int mode)
struct frame_map *hdr, int mode,
unsigned long count)
{
__show_frame_hdr(packet, len, linktype, &hdr->s_ll, &hdr->tp_h, mode, false);
__show_frame_hdr(packet, len, linktype, &hdr->s_ll, &hdr->tp_h, mode,
false, count);
}

extern void dissector_init_all(int fnttype);
Expand Down
13 changes: 8 additions & 5 deletions netsniff-ng.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ static void pcap_to_xmit(struct ctx *ctx)
ctx->tx_packets++;

show_frame_hdr(out, hdr->tp_h.tp_snaplen,
ctx->link_type, hdr, ctx->print_mode);
ctx->link_type, hdr, ctx->print_mode,
ctx->tx_packets);

dissector_entry_point(out, hdr->tp_h.tp_snaplen,
ctx->link_type, ctx->print_mode,
Expand Down Expand Up @@ -461,7 +462,8 @@ static void receive_to_xmit(struct ctx *ctx)
}

show_frame_hdr(in, hdr_in->tp_h.tp_snaplen,
ctx->link_type, hdr_in, ctx->print_mode);
ctx->link_type, hdr_in, ctx->print_mode,
frame_count);

dissector_entry_point(in, hdr_in->tp_h.tp_snaplen,
ctx->link_type, ctx->print_mode,
Expand Down Expand Up @@ -645,7 +647,7 @@ static void read_pcap(struct ctx *ctx)
ctx->tx_packets++;

show_frame_hdr(out, fm.tp_h.tp_snaplen, ctx->link_type, &fm,
ctx->print_mode);
ctx->print_mode, ctx->tx_packets);

dissector_entry_point(out, fm.tp_h.tp_snaplen,
ctx->link_type, ctx->print_mode,
Expand Down Expand Up @@ -913,7 +915,7 @@ static void walk_t3_block(struct block_desc *pbd, struct ctx *ctx,
}

__show_frame_hdr(packet, hdr->tp_snaplen, ctx->link_type, sll,
hdr, ctx->print_mode, true);
hdr, ctx->print_mode, true, *frame_count);

dissector_entry_point(packet, hdr->tp_snaplen, ctx->link_type,
ctx->print_mode, sll->sll_protocol);
Expand Down Expand Up @@ -1047,7 +1049,8 @@ static void recv_only_or_dump(struct ctx *ctx)
}

show_frame_hdr(packet, hdr->tp_h.tp_snaplen,
ctx->link_type, hdr, ctx->print_mode);
ctx->link_type, hdr, ctx->print_mode,
frame_count);

dissector_entry_point(packet, hdr->tp_h.tp_snaplen,
ctx->link_type, ctx->print_mode,
Expand Down

0 comments on commit 6b85cfe

Please sign in to comment.