netsniff-ng: remove set_sockopt_hwtimestamp call
[netsniff-ng.git] / proto_ip_authentication_hdr.c
blob2d5f57c391b4f126e74c164af818aa258ee35260
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2012 Markus Amend <markus@netsniff-ng.org>, Deutsche Flugsicherung GmbH
4 * Subject to the GPL, version 2.
6 * IP Authentication Header described in RFC4302
7 */
9 #include <stdio.h>
10 #include <stdint.h>
11 #include <netinet/in.h> /* for ntohs() */
13 #include "proto.h"
14 #include "protos.h"
15 #include "dissector_eth.h"
16 #include "built_in.h"
17 #include "pkt_buff.h"
19 struct auth_hdr {
20 uint8_t h_next_header;
21 uint8_t h_payload_len;
22 uint16_t h_reserved;
23 uint32_t h_spi;
24 uint32_t h_snf;
25 } __packed;
27 static void auth_hdr(struct pkt_buff *pkt)
29 ssize_t hdr_len;
30 size_t i;
31 struct auth_hdr *auth_ops;
33 auth_ops = (struct auth_hdr *) pkt_pull(pkt, sizeof(*auth_ops));
34 if (auth_ops == NULL)
35 return;
37 hdr_len = (auth_ops->h_payload_len * 4) + 8;
39 tprintf(" [ Authentication Header ");
40 tprintf("NextHdr (%u), ", auth_ops->h_next_header);
41 if (hdr_len > pkt_len(pkt) || hdr_len < 0){
42 tprintf("HdrLen (%u, %zd Bytes %s), ",
43 auth_ops->h_payload_len, hdr_len,
44 colorize_start_full(black, red)
45 "invalid" colorize_end());
46 return;
48 tprintf("HdrLen (%u, %zd Bytes), ",auth_ops->h_payload_len, hdr_len);
49 tprintf("Reserved (0x%x), ", ntohs(auth_ops->h_reserved));
50 /* TODO
51 * Upgrade for Extended (64-bit) Sequence Number
52 * http://tools.ietf.org/html/rfc4302#section-2.5.1
54 tprintf("SPI (0x%x), ", ntohl(auth_ops->h_spi));
55 tprintf("SNF (0x%x), ", ntohl(auth_ops->h_snf));
56 tprintf("ICV 0x");
57 for (i = sizeof(struct auth_hdr); i < hdr_len; i++)
58 tprintf("%02x", *pkt_pull(pkt, 1));
59 tprintf(" ]\n");
61 pkt_set_proto(pkt, &eth_lay3, auth_ops->h_next_header);
64 static void auth_hdr_less(struct pkt_buff *pkt)
66 ssize_t hdr_len;
67 struct auth_hdr *auth_ops;
69 auth_ops = (struct auth_hdr *) pkt_pull(pkt, sizeof(*auth_ops));
70 if (auth_ops == NULL)
71 return;
73 hdr_len = (auth_ops->h_payload_len * 4) + 8;
74 if (hdr_len > pkt_len(pkt) || hdr_len < 0)
75 return;
77 tprintf(" AH");
79 pkt_pull(pkt, hdr_len - sizeof(*auth_ops));
80 pkt_set_proto(pkt, &eth_lay3, auth_ops->h_next_header);
83 struct protocol ip_auth_ops = {
84 .key = 0x33,
85 .print_full = auth_hdr,
86 .print_less = auth_hdr_less,