2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009, 2010 Daniel Borkmann.
4 * Subject to the GPL, version 2.
10 #include <netinet/in.h> /* for ntohs() */
11 #include <asm/byteorder.h>
14 #include "dissector_eth.h"
23 #if defined(__LITTLE_ENDIAN_BITFIELD)
24 __extension__
uint16_t res1
:4,
34 #elif defined(__BIG_ENDIAN_BITFIELD)
35 __extension__
uint16_t doff
:4,
46 # error "Adjust your <asm/byteorder.h> defines"
53 static void tcp(struct pkt_buff
*pkt
)
55 struct tcphdr
*tcp
= (struct tcphdr
*) pkt_pull(pkt
, sizeof(*tcp
));
57 char *src_name
, *dest_name
;
62 src
= ntohs(tcp
->source
);
63 dest
= ntohs(tcp
->dest
);
65 src_name
= lookup_port_tcp(src
);
66 dest_name
= lookup_port_tcp(dest
);
69 tprintf("Port (%u", src
);
71 tprintf(" (%s%s%s)", colorize_start(bold
), src_name
,
73 tprintf(" => %u", dest
);
75 tprintf(" (%s%s%s)", colorize_start(bold
), dest_name
,
78 tprintf("SN (0x%x), ", ntohl(tcp
->seq
));
79 tprintf("AN (0x%x), ", ntohl(tcp
->ack_seq
));
80 tprintf("DataOff (%u), ", tcp
->doff
);
81 tprintf("Res (%u), ", tcp
->res1
);
100 tprintf("Window (%u), ", ntohs(tcp
->window
));
101 tprintf("CSum (0x%.4x), ", ntohs(tcp
->check
));
102 tprintf("UrgPtr (%u)", ntohs(tcp
->urg_ptr
));
106 static void tcp_less(struct pkt_buff
*pkt
)
108 struct tcphdr
*tcp
= (struct tcphdr
*) pkt_pull(pkt
, sizeof(*tcp
));
110 char *src_name
, *dest_name
;
115 src
= ntohs(tcp
->source
);
116 dest
= ntohs(tcp
->dest
);
118 src_name
= lookup_port_tcp(src
);
119 dest_name
= lookup_port_tcp(dest
);
121 tprintf(" TCP %u", src
);
123 tprintf("(%s%s%s)", colorize_start(bold
), src_name
,
125 tprintf("/%u", dest
);
127 tprintf("(%s%s%s)", colorize_start(bold
), dest_name
,
129 tprintf(" F%s",colorize_start(bold
));
146 tprintf("%s Win %u S/A 0x%x/0x%x", colorize_end(),
147 ntohs(tcp
->window
), ntohl(tcp
->seq
), ntohl(tcp
->ack_seq
));
150 struct protocol tcp_ops
= {
153 .print_less
= tcp_less
,