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() */
23 static void udp(struct pkt_buff
*pkt
)
25 struct udphdr
*udp
= (struct udphdr
*) pkt_pull(pkt
, sizeof(*udp
));
28 char *src_name
, *dest_name
;
33 len
= ntohs(udp
->len
) - sizeof(*udp
);
34 src
= ntohs(udp
->source
);
35 dest
= ntohs(udp
->dest
);
37 src_name
= lookup_port_udp(src
);
38 dest_name
= lookup_port_udp(dest
);
41 tprintf("Port (%u", src
);
43 tprintf(" (%s%s%s)", colorize_start(bold
), src_name
,
45 tprintf(" => %u", dest
);
47 tprintf(" (%s%s%s)", colorize_start(bold
), dest_name
,
50 if(len
> pkt_len(pkt
) || len
< 0){
51 tprintf("Len (%u) %s, ", ntohs(udp
->len
),
52 colorize_start_full(black
, red
)
53 "invalid" colorize_end());
55 tprintf("Len (%u Bytes, %zd Bytes Data), ", ntohs(udp
->len
), len
);
56 tprintf("CSum (0x%.4x)", ntohs(udp
->check
));
60 static void udp_less(struct pkt_buff
*pkt
)
62 struct udphdr
*udp
= (struct udphdr
*) pkt_pull(pkt
, sizeof(*udp
));
64 char *src_name
, *dest_name
;
69 src
= ntohs(udp
->source
);
70 dest
= ntohs(udp
->dest
);
72 src_name
= lookup_port_udp(src
);
73 dest_name
= lookup_port_udp(dest
);
75 tprintf(" UDP %u", src
);
77 tprintf("(%s%s%s)", colorize_start(bold
), src_name
,
81 tprintf("(%s%s%s)", colorize_start(bold
), dest_name
,
85 struct protocol udp_ops
= {
88 .print_less
= udp_less
,