1 /****************************************************************************
2 ** File: ah.c
3 **
4 ** Author: Mike Borella
5 **
6 ** Dump AH payload
7 **
8 ** $Id: ah.c,v 1.10 2002/01/03 00:04:01 mborella Exp $
9 **
10 ** This program is free software; you can redistribute it and/or modify
11 ** it under the terms of the GNU General Public License as published by
12 ** the Free Software Foundation; either version 2 of the License, or
13 ** (at your option) any later version.
14 **
15 ** This program is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ** GNU Library General Public License for more details.
19 **
20 ** You should have received a copy of the GNU General Public License
21 ** along with this program; if not, write to the Free Software
22 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 **
24 *****************************************************************************/
25
26 #include "ah.h"
27 #include "ip_protocols.h"
28
29 #define HOLDER_SIZE 256
30
31 extern struct arg_t *my_args;
32 extern strmap_t ipproto_map[];
33
34 extern void (*ip_proto_func[])(packet_t *);
35
36 /*----------------------------------------------------------------------------
37 **
38 ** dump_ah()
39 **
40 ** Parse AH packet and dump fields.
41 **
42 **----------------------------------------------------------------------------
43 */
44
dump_ah(packet_t * pkt)45 void dump_ah(packet_t *pkt)
46 {
47 ah_header_t ah;
48 char holder[HOLDER_SIZE];
49 u_int16_t ad_length;
50 u_int8_t len;
51 u_int8_t next;
52 u_int16_t reserved;
53
54 /* Set the layer */
55 set_layer(LAYER_NETWORK);
56
57 /*
58 * Stats accounting
59 */
60
61 stats_update(STATS_AH);
62
63 /*
64 * Get the AH header
65 */
66
67 if (get_packet_bytes((u_int8_t *) &ah, pkt, 12) == 0)
68 return;
69
70 /*
71 * Conversions
72 */
73
74 len = ah.length;
75 next = ah.next;
76 reserved = ah.reserved;
77 ah.spi = ntohl(ah.spi);
78 ah.seqno = ntohl(ah.seqno);
79
80 /*
81 * Figure out length of authentication data, hoping its not too big...
82 */
83
84 ad_length = len * 4 - 12;
85 if (get_packet_bytes((u_int8_t *) &holder, pkt, ad_length) == 0)
86 return;
87
88
89 /*
90 * Dump header
91 */
92
93 if (my_args->m && !my_args->n)
94 {
95 display_minimal_string("| AH ");
96 display_minimal((u_int8_t *) &ah.spi, 4, DISP_HEX);
97 display_minimal_string(" ");
98 }
99 else
100 if (!my_args->n)
101 {
102 /* announcement */
103 display_header_banner("Authentication Header");
104
105 /* print fields */
106 snprintf(holder, HOLDER_SIZE, "%d (%s)", next,
107 map2str(ipproto_map, next));
108 display("Next header", holder, strlen(holder), DISP_STRING);
109 display("Reseerved", (u_int8_t *) &reserved, 2, DISP_DEC);
110 display("Header length", (u_int8_t *) &len, 1, DISP_DEC);
111 display("SPI", (u_int8_t *) &ah.spi, 4, DISP_HEX);
112 display("Sequence number", (u_int8_t *) &ah.seqno, 4, DISP_DEC);
113 }
114
115 /*
116 * Figure out the next header
117 */
118
119 if (ip_proto_func[ah.next])
120 ip_proto_func[ah.next](pkt);
121
122 }
123