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.
13 #include <netinet/in.h> /* for ntohs() */
15 #include "proto_struct.h"
16 #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"
52 } __attribute__((packed
));
54 static inline uint16_t tcp_port(uint16_t src
, uint16_t dst
)
61 /* XXX: Is there a better way to determine? */
62 if (src
< dst
&& src
< 1024) {
64 } else if (dst
< src
&& dst
< 1024) {
67 tmp1
= lookup_port_tcp(src
);
68 tmp2
= lookup_port_tcp(dst
);
71 } else if (!tmp1
&& tmp2
) {
82 static inline void tcp(struct pkt_buff
*pkt
)
84 struct tcphdr
*tcp
= (struct tcphdr
*) pkt_pull(pkt
, sizeof(*tcp
));
90 tprintf("Port (%u => %u, %s%s%s), ",
91 ntohs(tcp
->source
), ntohs(tcp
->dest
),
93 lookup_port_tcp(tcp_port(tcp
->source
, tcp
->dest
)),
95 tprintf("SN (0x%x), ", ntohl(tcp
->seq
));
96 tprintf("AN (0x%x), ", ntohl(tcp
->ack_seq
));
97 tprintf("DataOff (%u), ", tcp
->doff
);
98 tprintf("Res (%u), ", tcp
->res1
);
117 tprintf("Window (%u), ", ntohs(tcp
->window
));
118 tprintf("CSum (0x%.4x), ", ntohs(tcp
->check
));
119 tprintf("UrgPtr (%u)", ntohs(tcp
->urg_ptr
));
122 pkt_set_proto(pkt
, ð_lay4
, tcp_port(tcp
->source
, tcp
->dest
));
125 static inline void tcp_less(struct pkt_buff
*pkt
)
127 struct tcphdr
*tcp
= (struct tcphdr
*) pkt_pull(pkt
, sizeof(*tcp
));
132 tprintf(" TCP %s%s%s %u/%u F%s",
133 colorize_start(bold
),
134 lookup_port_tcp(tcp_port(tcp
->source
, tcp
->dest
)),
135 colorize_end(), ntohs(tcp
->source
), ntohs(tcp
->dest
),
136 colorize_start(bold
));
153 tprintf("%s Win %u S/A 0x%x/0x%x", colorize_end(),
154 ntohs(tcp
->window
), ntohl(tcp
->seq
), ntohl(tcp
->ack_seq
));
156 pkt_set_proto(pkt
, ð_lay4
, tcp_port(tcp
->source
, tcp
->dest
));
159 struct protocol tcp_ops
= {
162 .print_less
= tcp_less
,