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 } __attribute__((packed
));
26 static inline uint16_t udp_port(uint16_t src
, uint16_t dst
)
33 /* XXX: Is there a better way to determine? */
34 if (src
< dst
&& src
< 1024) {
36 } else if (dst
< src
&& dst
< 1024) {
39 tmp1
= lookup_port_udp(src
);
40 tmp2
= lookup_port_udp(dst
);
43 } else if (!tmp1
&& tmp2
) {
54 static inline void udp(struct pkt_buff
*pkt
)
56 struct udphdr
*udp
= (struct udphdr
*) pkt_pull(pkt
, sizeof(*udp
));
62 tprintf("Port (%u => %u, %s%s%s), ",
63 ntohs(udp
->source
), ntohs(udp
->dest
),
65 lookup_port_udp(udp_port(udp
->source
, udp
->dest
)),
67 tprintf("Len (%u), ", ntohs(udp
->len
));
68 tprintf("CSum (0x%.4x)", ntohs(udp
->check
));
71 pkt_set_proto(pkt
, ð_lay4
, udp_port(udp
->source
, udp
->dest
));
74 static inline void udp_less(struct pkt_buff
*pkt
)
76 struct udphdr
*udp
= (struct udphdr
*) pkt_pull(pkt
, sizeof(*udp
));
81 tprintf(" UDP %s%s%s %u/%u",
83 lookup_port_udp(udp_port(udp
->source
, udp
->dest
)),
84 colorize_end(), ntohs(udp
->source
), ntohs(udp
->dest
));
86 pkt_set_proto(pkt
, ð_lay4
, udp_port(udp
->source
, udp
->dest
));
89 struct protocol udp_ops
= {
92 .print_less
= udp_less
,