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"
23 } __attribute__((packed
));
25 static inline uint16_t udp_port(uint16_t src
, uint16_t dst
)
32 /* XXX: Is there a better way to determine? */
33 if (src
< dst
&& src
< 1024) {
35 } else if (dst
< src
&& dst
< 1024) {
38 tmp1
= lookup_port_udp(src
);
39 tmp2
= lookup_port_udp(dst
);
42 } else if (!tmp1
&& tmp2
) {
53 static inline void udp(uint8_t *packet
, size_t len
)
55 struct udphdr
*udp
= (struct udphdr
*) packet
;
57 if (len
< sizeof(struct udphdr
))
61 tprintf("Port (%u => %u, %s%s%s), ",
62 ntohs(udp
->source
), ntohs(udp
->dest
),
64 lookup_port_udp(udp_port(udp
->source
, udp
->dest
)),
66 tprintf("Len (%u), ", ntohs(udp
->len
));
67 tprintf("CSum (0x%.4x)", ntohs(udp
->check
));
71 static inline void udp_less(uint8_t *packet
, size_t len
)
73 struct udphdr
*udp
= (struct udphdr
*) packet
;
75 if (len
< sizeof(struct udphdr
))
78 tprintf(" UDP %s%s%s %u/%u",
80 lookup_port_udp(udp_port(udp
->source
, udp
->dest
)),
81 colorize_end(), ntohs(udp
->source
), ntohs(udp
->dest
));
84 static inline void udp_next(uint8_t *packet
, size_t len
,
85 struct hash_table
**table
,
86 unsigned int *key
, size_t *off
)
88 struct udphdr
*udp
= (struct udphdr
*) packet
;
90 if (len
< sizeof(struct udphdr
))
93 (*off
) = sizeof(struct udphdr
);
94 (*key
) = udp_port(udp
->source
, udp
->dest
);
104 struct protocol udp_ops
= {
106 .offset
= sizeof(struct udphdr
),
108 .print_less
= udp_less
,
109 .print_pay_ascii
= empty
,
110 .print_pay_hex
= empty
,
111 .print_pay_none
= udp
,
112 .print_all_cstyle
= __hex2
,
113 .print_all_hex
= __hex
,
114 .proto_next
= udp_next
,