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>
15 #include "dissector_eth.h"
24 #if defined(__LITTLE_ENDIAN_BITFIELD)
25 __extension__
uint16_t res1
:4,
35 #elif defined(__BIG_ENDIAN_BITFIELD)
36 __extension__
uint16_t doff
:4,
47 # error "Adjust your <asm/byteorder.h> defines"
54 static void tcp(struct pkt_buff
*pkt
)
56 struct tcphdr
*tcp
= (struct tcphdr
*) pkt_pull(pkt
, sizeof(*tcp
));
58 char *src_name
, *dest_name
;
63 src
= ntohs(tcp
->source
);
64 dest
= ntohs(tcp
->dest
);
66 src_name
= lookup_port_tcp(src
);
67 dest_name
= lookup_port_tcp(dest
);
70 tprintf("Port (%u", src
);
72 tprintf(" (%s%s%s)", colorize_start(bold
), src_name
,
74 tprintf(" => %u", dest
);
76 tprintf(" (%s%s%s)", colorize_start(bold
), dest_name
,
79 tprintf("SN (0x%x), ", ntohl(tcp
->seq
));
80 tprintf("AN (0x%x), ", ntohl(tcp
->ack_seq
));
81 tprintf("DataOff (%u), ", tcp
->doff
);
82 tprintf("Res (%u), ", tcp
->res1
);
101 tprintf("Window (%u), ", ntohs(tcp
->window
));
102 tprintf("CSum (0x%.4x), ", ntohs(tcp
->check
));
103 tprintf("UrgPtr (%u)", ntohs(tcp
->urg_ptr
));
107 static void tcp_less(struct pkt_buff
*pkt
)
109 struct tcphdr
*tcp
= (struct tcphdr
*) pkt_pull(pkt
, sizeof(*tcp
));
111 char *src_name
, *dest_name
;
116 src
= ntohs(tcp
->source
);
117 dest
= ntohs(tcp
->dest
);
119 src_name
= lookup_port_tcp(src
);
120 dest_name
= lookup_port_tcp(dest
);
122 tprintf(" TCP %u", src
);
124 tprintf("(%s%s%s)", colorize_start(bold
), src_name
,
126 tprintf("/%u", dest
);
128 tprintf("(%s%s%s)", colorize_start(bold
), dest_name
,
130 tprintf(" F%s",colorize_start(bold
));
147 tprintf("%s Win %u S/A 0x%x/0x%x", colorize_end(),
148 ntohs(tcp
->window
), ntohl(tcp
->seq
), ntohl(tcp
->ack_seq
));
151 struct protocol tcp_ops
= {
154 .print_less
= tcp_less
,