bump version
[prads.git] / src / ipfp / udp_fp.c
blobd43f187146a43aac9f9e9c87bb659c5dc2b9122d
1 #include "../common.h"
2 #include "../prads.h"
3 #include "ipfp.h"
5 void fp_udp4(packetinfo *pi, ip4_header * ip4, udp_header * udph, const uint8_t * end_ptr)
8 uint8_t *opt_ptr;
9 int32_t ilen, olen;
10 uint32_t quirks = 0;
11 uint8_t *payload = 0;
14 * Decode variable length header options and remaining data in field
16 olen = IP_HL(ip4) - 5;
17 if (olen < 0) { // Check for bad hlen
18 olen = 0;
19 } else {
21 * Option length is number of 32 bit words
23 olen = olen * 4;
24 quirks |= QUIRK_IPOPT;
27 * If the declared length is shorter than the snapshot (etherleak
28 * or such), truncate the package.
30 opt_ptr = (uint8_t *) ip4 + htons(ip4->ip_len);
31 if (end_ptr > opt_ptr)
32 end_ptr = opt_ptr;
34 ilen = ip4->ip_vhl & 15;
36 * B0rked packet
38 if (ilen < 5)
39 return;
41 if (ilen > 5) {
42 quirks |= QUIRK_IPOPT;
45 * If IP header ends past end_ptr
47 if ((uint8_t *) (ip4 + 1) > end_ptr)
48 return;
50 if ((uint8_t *) opt_ptr + ilen < end_ptr) {
51 quirks |= QUIRK_DATA;
52 payload = opt_ptr + ilen;
54 uint8_t udata = (uint8_t *) end_ptr - payload;
56 if (!ip4->ip_id)
57 quirks |= QUIRK_ZEROID;
59 // Fingerprint format: $fplen,$ttl,$df,$io,$if,$fo
60 gen_fp_udp(ntohs(ip4->ip_len - udph->len), udata, ip4->ip_ttl,
61 (ntohs(ip4->ip_off) & IP_DF) != 0, olen, ntohs(ip4->ip_len),
62 ip4->ip_off, ip4->ip_tos, quirks,
63 //ip_src, udph->src_port,AF_INET);
64 pi);
66 //icmp_os_find_match($type,$code,$gttl,$df,$ipopts,$len,$ipflags,$foffset,$tos);