proto_ipv6_mobility_hdr.h: Headerfixing
[netsniff-ng.git] / src / proto_ip_authentication_hdr.h
blob51cf779a9810bb4060af9ad165fef9f194aa5817
1 /*
2 * IP Authentication Header described in RFC4302
3 * programmed by Markus Amend 2012 as a contribution to
4 * netsniff-ng - the packet sniffing beast
5 * Copyright 2012 Markus Amend.
6 * Subject to the GPL, version 2.
7 */
9 #ifndef PROTO_IP_AUTHENTICATION_HDR_H
10 #define PROTO_IP_AUTHENTICATION_HDR_H
12 #include <stdio.h>
13 #include <stdint.h>
14 #include <netinet/in.h> /* for ntohs() */
16 #include "proto_struct.h"
17 #include "dissector_eth.h"
18 #include "built_in.h"
20 struct auth_hdrhdr {
21 uint8_t h_next_header;
22 uint8_t h_payload_len;
23 uint16_t h_reserved;
24 uint32_t h_spi;
25 uint32_t h_snf;
26 } __packed;
28 static inline void auth_hdr(uint8_t *packet, size_t len)
30 uint8_t hdr_payload_len;
31 struct auth_hdrhdr *auth_hdr = (struct auth_hdrhdr *) packet;
33 hdr_payload_len = (auth_hdr->h_payload_len * 4) + 8;
34 if (len < hdr_payload_len || len < sizeof(struct auth_hdrhdr))
35 return;
37 tprintf(" [ Authentication Header ");
38 tprintf("NextHdr (%u), ", auth_hdr->h_next_header);
39 tprintf("HdrLen (%u), ", hdr_payload_len);
40 tprintf("Reserved (0x%x), ", ntohs(auth_hdr->h_reserved));
41 tprintf("SPI (0x%x), ", ntohl(auth_hdr->h_spi));
42 tprintf("SNF (0x%x), ", ntohl(auth_hdr->h_snf));
43 tprintf("ICV 0x");
44 for (uint8_t i = sizeof(struct auth_hdrhdr); i < hdr_payload_len; i++)
45 tprintf("%02x",(uint8_t) packet[i]);
46 tprintf(" ]\n");
49 static inline void auth_hdr_less(uint8_t *packet, size_t len)
51 uint8_t hdr_payload_len;
52 struct auth_hdrhdr *auth_hdr = (struct auth_hdrhdr *) packet;
54 hdr_payload_len = (auth_hdr->h_payload_len * 4) + 8;
55 if (len < hdr_payload_len || len < sizeof(struct auth_hdrhdr))
56 return;
58 tprintf(" AH");
61 static inline void auth_hdr_next(uint8_t *packet, size_t len,
62 struct hash_table **table,
63 unsigned int *key, size_t *off)
65 uint8_t hdr_payload_len;
66 struct auth_hdrhdr *auth_hdr = (struct auth_hdrhdr *) packet;
68 hdr_payload_len = (auth_hdr->h_payload_len * 4) + 8;
69 if (len < hdr_payload_len || len < sizeof(struct auth_hdrhdr))
70 return;
72 (*off) = hdr_payload_len;
73 (*key) = auth_hdr->h_next_header;
74 (*table) = &eth_lay3;
77 struct protocol ip_auth_hdr_ops = {
78 .key = 0x33,
79 .print_full = auth_hdr,
80 .print_less = auth_hdr_less,
81 .proto_next = auth_hdr_next,
84 #endif /* PROTO_IP_AUTHENTICATION_HDR_H */