xref: /freebsd/contrib/tcpdump/print-ah.c (revision b0453382235492c8e30b09659b52d784128ca7d0)
1b0453382SBill Fenner /*	$NetBSD: print-ah.c,v 1.4 1996/05/20 00:41:16 fvdl Exp $	*/
2b0453382SBill Fenner 
3b0453382SBill Fenner /*
4b0453382SBill Fenner  * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994
5b0453382SBill Fenner  *	The Regents of the University of California.  All rights reserved.
6b0453382SBill Fenner  *
7b0453382SBill Fenner  * Redistribution and use in source and binary forms, with or without
8b0453382SBill Fenner  * modification, are permitted provided that: (1) source code distributions
9b0453382SBill Fenner  * retain the above copyright notice and this paragraph in its entirety, (2)
10b0453382SBill Fenner  * distributions including binary code include the above copyright notice and
11b0453382SBill Fenner  * this paragraph in its entirety in the documentation or other materials
12b0453382SBill Fenner  * provided with the distribution, and (3) all advertising materials mentioning
13b0453382SBill Fenner  * features or use of this software display the following acknowledgement:
14b0453382SBill Fenner  * ``This product includes software developed by the University of California,
15b0453382SBill Fenner  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16b0453382SBill Fenner  * the University nor the names of its contributors may be used to endorse
17b0453382SBill Fenner  * or promote products derived from this software without specific prior
18b0453382SBill Fenner  * written permission.
19b0453382SBill Fenner  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20b0453382SBill Fenner  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21b0453382SBill Fenner  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22b0453382SBill Fenner  */
23b0453382SBill Fenner 
24b0453382SBill Fenner #ifndef lint
25b0453382SBill Fenner static const char rcsid[] =
26b0453382SBill Fenner     "@(#) $Header: /tcpdump/master/tcpdump/print-ah.c,v 1.5 1999/12/15 08:10:17 fenner Exp $ (LBL)";
27b0453382SBill Fenner #endif
28b0453382SBill Fenner 
29b0453382SBill Fenner #ifdef HAVE_CONFIG_H
30b0453382SBill Fenner #include "config.h"
31b0453382SBill Fenner #endif
32b0453382SBill Fenner 
33b0453382SBill Fenner #include <sys/param.h>
34b0453382SBill Fenner #include <sys/time.h>
35b0453382SBill Fenner #include <sys/types.h>
36b0453382SBill Fenner #include <sys/socket.h>
37b0453382SBill Fenner 
38b0453382SBill Fenner #include <net/route.h>
39b0453382SBill Fenner #include <net/if.h>
40b0453382SBill Fenner 
41b0453382SBill Fenner #include <netinet/in.h>
42b0453382SBill Fenner #include <netinet/if_ether.h>
43b0453382SBill Fenner #include <netinet/in_systm.h>
44b0453382SBill Fenner #include <netinet/ip.h>
45b0453382SBill Fenner #include <netinet/ip_icmp.h>
46b0453382SBill Fenner #include <netinet/ip_var.h>
47b0453382SBill Fenner #include <netinet/udp.h>
48b0453382SBill Fenner #include <netinet/udp_var.h>
49b0453382SBill Fenner #include <netinet/tcp.h>
50b0453382SBill Fenner 
51b0453382SBill Fenner #include <stdio.h>
52b0453382SBill Fenner 
53b0453382SBill Fenner /* there's no standard definition so we are on our own */
54b0453382SBill Fenner struct ah {
55b0453382SBill Fenner 	u_int8_t	ah_nxt;		/* Next Header */
56b0453382SBill Fenner 	u_int8_t	ah_len;		/* Length of data, in 32bit */
57b0453382SBill Fenner 	u_int16_t	ah_reserve;	/* Reserved for future use */
58b0453382SBill Fenner 	u_int32_t	ah_spi;		/* Security parameter index */
59b0453382SBill Fenner 	/* variable size, 32bit bound*/	/* Authentication data */
60b0453382SBill Fenner };
61b0453382SBill Fenner 
62b0453382SBill Fenner struct newah {
63b0453382SBill Fenner 	u_int8_t	ah_nxt;		/* Next Header */
64b0453382SBill Fenner 	u_int8_t	ah_len;		/* Length of data + 1, in 32bit */
65b0453382SBill Fenner 	u_int16_t	ah_reserve;	/* Reserved for future use */
66b0453382SBill Fenner 	u_int32_t	ah_spi;		/* Security parameter index */
67b0453382SBill Fenner 	u_int32_t	ah_seq;		/* Sequence number field */
68b0453382SBill Fenner 	/* variable size, 32bit bound*/	/* Authentication data */
69b0453382SBill Fenner };
70b0453382SBill Fenner 
71b0453382SBill Fenner #include "interface.h"
72b0453382SBill Fenner #include "addrtoname.h"
73b0453382SBill Fenner 
74b0453382SBill Fenner int
75b0453382SBill Fenner ah_print(register const u_char *bp, register const u_char *bp2)
76b0453382SBill Fenner {
77b0453382SBill Fenner 	register const struct ah *ah;
78b0453382SBill Fenner 	register const u_char *ep;
79b0453382SBill Fenner 	int sumlen;
80b0453382SBill Fenner 	u_int32_t spi;
81b0453382SBill Fenner 
82b0453382SBill Fenner 	ah = (struct ah *)bp;
83b0453382SBill Fenner 	ep = snapend;		/* 'ep' points to the end of avaible data. */
84b0453382SBill Fenner 
85b0453382SBill Fenner 	if ((u_char *)(ah + 1) >= ep - sizeof(struct ah))
86b0453382SBill Fenner 		goto trunc;
87b0453382SBill Fenner 
88b0453382SBill Fenner 	sumlen = ah->ah_len << 2;
89b0453382SBill Fenner 	spi = (u_int32_t)ntohl(ah->ah_spi);
90b0453382SBill Fenner 
91b0453382SBill Fenner 	printf("AH(spi=%u", spi);
92b0453382SBill Fenner 	if (vflag)
93b0453382SBill Fenner 		printf(",sumlen=%d", sumlen);
94b0453382SBill Fenner 	printf(",seq=0x%x", (u_int32_t)ntohl(*(u_int32_t *)(ah + 1)));
95b0453382SBill Fenner 	if (bp + sizeof(struct ah) + sumlen > ep)
96b0453382SBill Fenner 		fputs("[truncated]", stdout);
97b0453382SBill Fenner 	fputs("): ", stdout);
98b0453382SBill Fenner 
99b0453382SBill Fenner 	return sizeof(struct ah) + sumlen;
100b0453382SBill Fenner  trunc:
101b0453382SBill Fenner 	fputs("[|AH]", stdout);
102b0453382SBill Fenner 	return 65535;
103b0453382SBill Fenner }
104