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 void tcp(struct pkt_buff
*pkt
)
57 struct tcphdr
*tcp
= (struct tcphdr
*) pkt_pull(pkt
, sizeof(*tcp
));
59 char *src_name
, *dest_name
;
64 src
= ntohs(tcp
->source
);
65 dest
= ntohs(tcp
->dest
);
67 src_name
= lookup_port_tcp(src
);
68 dest_name
= lookup_port_tcp(dest
);
71 tprintf("Port (%u", src
);
73 tprintf(" (%s%s%s)", colorize_start(bold
), src_name
,
75 tprintf(" => %u", dest
);
77 tprintf(" (%s%s%s)", colorize_start(bold
), dest_name
,
80 tprintf("SN (0x%x), ", ntohl(tcp
->seq
));
81 tprintf("AN (0x%x), ", ntohl(tcp
->ack_seq
));
82 tprintf("DataOff (%u), ", tcp
->doff
);
83 tprintf("Res (%u), ", tcp
->res1
);
102 tprintf("Window (%u), ", ntohs(tcp
->window
));
103 tprintf("CSum (0x%.4x), ", ntohs(tcp
->check
));
104 tprintf("UrgPtr (%u)", ntohs(tcp
->urg_ptr
));
108 static void tcp_less(struct pkt_buff
*pkt
)
110 struct tcphdr
*tcp
= (struct tcphdr
*) pkt_pull(pkt
, sizeof(*tcp
));
112 char *src_name
, *dest_name
;
117 src
= ntohs(tcp
->source
);
118 dest
= ntohs(tcp
->dest
);
120 src_name
= lookup_port_tcp(src
);
121 dest_name
= lookup_port_tcp(dest
);
123 tprintf(" TCP %u", src
);
125 tprintf("(%s%s%s)", colorize_start(bold
), src_name
,
127 tprintf("/%u", dest
);
129 tprintf("(%s%s%s)", colorize_start(bold
), dest_name
,
131 tprintf(" F%s",colorize_start(bold
));
148 tprintf("%s Win %u S/A 0x%x/0x%x", colorize_end(),
149 ntohs(tcp
->window
), ntohl(tcp
->seq
), ntohl(tcp
->ack_seq
));
152 struct protocol tcp_ops
= {
155 .print_less
= tcp_less
,
158 EXPORT_SYMBOL(tcp_ops
);