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.
10 #include <netinet/in.h> /* for ntohs() */
14 #include "dissector_eth.h"
22 } __attribute__((packed
));
24 static void udp(struct pkt_buff
*pkt
)
26 struct udphdr
*udp
= (struct udphdr
*) pkt_pull(pkt
, sizeof(*udp
));
29 char *src_name
, *dest_name
;
34 len
= ntohs(udp
->len
) - sizeof(*udp
);
35 src
= ntohs(udp
->source
);
36 dest
= ntohs(udp
->dest
);
38 src_name
= lookup_port_udp(src
);
39 dest_name
= lookup_port_udp(dest
);
42 tprintf("Port (%u", src
);
44 tprintf(" (%s%s%s)", colorize_start(bold
), src_name
,
46 tprintf(" => %u", dest
);
48 tprintf(" (%s%s%s)", colorize_start(bold
), dest_name
,
51 if(len
> pkt_len(pkt
) || len
< 0){
52 tprintf("Len (%u) %s, ", ntohs(udp
->len
),
53 colorize_start_full(black
, red
)
54 "invalid" colorize_end());
56 tprintf("Len (%u Bytes, %zd Bytes Data), ", ntohs(udp
->len
), len
);
57 tprintf("CSum (0x%.4x)", ntohs(udp
->check
));
61 static void udp_less(struct pkt_buff
*pkt
)
63 struct udphdr
*udp
= (struct udphdr
*) pkt_pull(pkt
, sizeof(*udp
));
65 char *src_name
, *dest_name
;
70 src
= ntohs(udp
->source
);
71 dest
= ntohs(udp
->dest
);
73 src_name
= lookup_port_udp(src
);
74 dest_name
= lookup_port_udp(dest
);
76 tprintf(" UDP %u", src
);
78 tprintf("(%s%s%s)", colorize_start(bold
), src_name
,
82 tprintf("(%s%s%s)", colorize_start(bold
), dest_name
,
86 struct protocol udp_ops
= {
89 .print_less
= udp_less
,
92 EXPORT_SYMBOL(udp_ops
);