2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2009, 2010 Daniel Borkmann.
5 * Subject to the GPL, version 2.
11 #include <netinet/in.h> /* for ntohs() */
12 #include <asm/byteorder.h>
16 #include "dissector_eth.h"
25 #if defined(__LITTLE_ENDIAN_BITFIELD)
26 __extension__
uint16_t res1
:4,
36 #elif defined(__BIG_ENDIAN_BITFIELD)
37 __extension__
uint16_t doff
:4,
48 # error "Adjust your <asm/byteorder.h> defines"
53 } __attribute__((packed
));
55 static uint16_t tcp_port(uint16_t src
, uint16_t dst
)
62 /* XXX: Is there a better way to determine? */
63 if (src
< dst
&& src
< 1024) {
65 } else if (dst
< src
&& dst
< 1024) {
68 tmp1
= lookup_port_tcp(src
);
69 tmp2
= lookup_port_tcp(dst
);
72 } else if (!tmp1
&& tmp2
) {
83 static void tcp(struct pkt_buff
*pkt
)
85 struct tcphdr
*tcp
= (struct tcphdr
*) pkt_pull(pkt
, sizeof(*tcp
));
91 tprintf("Port (%u => %u, %s%s%s), ",
92 ntohs(tcp
->source
), ntohs(tcp
->dest
),
94 lookup_port_tcp(tcp_port(tcp
->source
, tcp
->dest
)),
96 tprintf("SN (0x%x), ", ntohl(tcp
->seq
));
97 tprintf("AN (0x%x), ", ntohl(tcp
->ack_seq
));
98 tprintf("DataOff (%u), ", tcp
->doff
);
99 tprintf("Res (%u), ", tcp
->res1
);
118 tprintf("Window (%u), ", ntohs(tcp
->window
));
119 tprintf("CSum (0x%.4x), ", ntohs(tcp
->check
));
120 tprintf("UrgPtr (%u)", ntohs(tcp
->urg_ptr
));
123 pkt_set_proto(pkt
, ð_lay4
, tcp_port(tcp
->source
, tcp
->dest
));
126 static void tcp_less(struct pkt_buff
*pkt
)
128 struct tcphdr
*tcp
= (struct tcphdr
*) pkt_pull(pkt
, sizeof(*tcp
));
133 tprintf(" TCP %s%s%s %u/%u F%s",
134 colorize_start(bold
),
135 lookup_port_tcp(tcp_port(tcp
->source
, tcp
->dest
)),
136 colorize_end(), ntohs(tcp
->source
), ntohs(tcp
->dest
),
137 colorize_start(bold
));
154 tprintf("%s Win %u S/A 0x%x/0x%x", colorize_end(),
155 ntohs(tcp
->window
), ntohl(tcp
->seq
), ntohl(tcp
->ack_seq
));
157 pkt_set_proto(pkt
, ð_lay4
, tcp_port(tcp
->source
, tcp
->dest
));
160 struct protocol tcp_ops
= {
163 .print_less
= tcp_less
,
166 EXPORT_SYMBOL(tcp_ops
);