2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009, 2010 Daniel Borkmann.
4 * Subject to the GPL, version 2.
9 #include <netinet/in.h> /* for ntohs() */
12 #include "dissector_eth.h"
22 static void udp(struct pkt_buff
*pkt
)
24 struct udphdr
*udp
= (struct udphdr
*) pkt_pull(pkt
, sizeof(*udp
));
27 char *src_name
, *dest_name
;
32 len
= ntohs(udp
->len
) - sizeof(*udp
);
33 src
= ntohs(udp
->source
);
34 dest
= ntohs(udp
->dest
);
36 src_name
= lookup_port_udp(src
);
37 dest_name
= lookup_port_udp(dest
);
40 tprintf("Port (%u", src
);
42 tprintf(" (%s%s%s)", colorize_start(bold
), src_name
,
44 tprintf(" => %u", dest
);
46 tprintf(" (%s%s%s)", colorize_start(bold
), dest_name
,
49 if(len
> pkt_len(pkt
) || len
< 0){
50 tprintf("Len (%u) %s, ", ntohs(udp
->len
),
51 colorize_start_full(black
, red
)
52 "invalid" colorize_end());
54 tprintf("Len (%u Bytes, %zd Bytes Data), ", ntohs(udp
->len
), len
);
55 tprintf("CSum (0x%.4x)", ntohs(udp
->check
));
59 static void udp_less(struct pkt_buff
*pkt
)
61 struct udphdr
*udp
= (struct udphdr
*) pkt_pull(pkt
, sizeof(*udp
));
63 char *src_name
, *dest_name
;
68 src
= ntohs(udp
->source
);
69 dest
= ntohs(udp
->dest
);
71 src_name
= lookup_port_udp(src
);
72 dest_name
= lookup_port_udp(dest
);
74 tprintf(" UDP %u", src
);
76 tprintf("(%s%s%s)", colorize_start(bold
), src_name
,
80 tprintf("(%s%s%s)", colorize_start(bold
), dest_name
,
84 struct protocol udp_ops
= {
87 .print_less
= udp_less
,