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.
9 #ifndef PROTO_IP_AUTHENTICATION_HDR_H
10 #define PROTO_IP_AUTHENTICATION_HDR_H
14 #include <netinet/in.h> /* for ntohs() */
16 #include "proto_struct.h"
17 #include "dissector_eth.h"
21 uint8_t h_next_header
;
22 uint8_t h_payload_len
;
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
))
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
));
44 for (uint8_t i
= sizeof(struct auth_hdrhdr
); i
< hdr_payload_len
; i
++)
45 tprintf("%02x",(uint8_t) packet
[i
]);
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
))
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
))
72 (*off
) = hdr_payload_len
;
73 (*key
) = auth_hdr
->h_next_header
;
77 struct protocol ip_auth_hdr_ops
= {
79 .print_full
= auth_hdr
,
80 .print_less
= auth_hdr_less
,
81 .proto_next
= auth_hdr_next
,
84 #endif /* PROTO_IP_AUTHENTICATION_HDR_H */