]>
The Tcpdump Group git mirrors - tcpdump/blob - print-dhcp6.c
2 * Copyright (C) 1998 and 1999 WIDE Project.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 static const char rcsid
[] =
32 "@(#) $Header: /tcpdump/master/tcpdump/print-dhcp6.c,v 1.9 2000-07-01 03:39:02 assar Exp $";
39 #include <sys/param.h>
41 #include <sys/socket.h>
47 #include <netinet/in.h>
52 #include <arpa/inet.h>
54 #include "interface.h"
55 #include "addrtoname.h"
60 static void dhcp6opttab_init
__P((void));
61 static struct dhcp6_opt
*dhcp6opttab_byname
__P((char *));
63 static struct dhcp6_opt
*dhcp6opttab_bycode
__P((u_int
));
65 static char tstr
[] = " [|dhcp6]";
67 static struct dhcp6_opt dh6opttab
[] = {
68 /* IP Address Extension */
69 { 1, OL6_N
, "IP Address", OT6_NONE
, },
71 /* General Extension */
72 { 8193, OL6_N
, "IEEE 1003.1 POSIX Timezone", OT6_STR
, },
73 { 8194, OL6_16N
, "Domain Name Server", OT6_V6
, },
74 { 8195, OL6_N
, "Domain Name", OT6_STR
, },
76 { 8196, OL6_N
, "SLP Agent", OT6_NONE
, },
77 { 8197, OL6_N
, "SLP Scope" , OT6_NONE
, },
78 { 8198, OL6_16N
, "Network Time Protocol Servers", OT6_V6
, },
79 { 8199, OL6_N
, "NIS Domain", OT6_STR
, },
80 { 8200, OL6_16N
, "NIS Servers", OT6_V6
, },
81 { 8201, OL6_N
, "NIS+ Domain", OT6_STR
, },
82 { 8202, OL6_16N
, "NIS+ Servers", OT6_V6
, },
85 { 8203, 4, "TCP Keepalive Interval", OT6_NUM
, },
87 /* DHCPv6 Extensions */
88 { 8204, 4, "Maximum DHCPv6 Message Size", OT6_NUM
, },
89 { 8205, OL6_N
, "DHCP Retransmission and Configuration Parameter",
91 { 8206, OL6_N
, "Extension Request", OT6_NONE
, },
92 { 8207, OL6_N
, "Subnet Prefix", OT6_NONE
, },
93 { 8208, OL6_N
, "Platform Specific Information", OT6_NONE
, },
94 { 8209, OL6_N
, "Platform Class Identifier", OT6_STR
, },
95 { 8210, OL6_N
, "Class Identifier", OT6_STR
, },
96 { 8211, 16, "Reconfigure Multicast Address", OT6_V6
, },
97 { 8212, 16, "Renumber DHCPv6 Server Address",
99 { 8213, OL6_N
, "Client-Server Authentication", OT6_NONE
, },
100 { 8214, 4, "Client Key Selection", OT6_NUM
, },
103 { 65536, OL6_Z
, "End", OT6_NONE
, },
109 static struct dhcp6_opt
*dh6o_pad
;
110 static struct dhcp6_opt
*dh6o_end
;
115 dh6o_pad
= dhcp6opttab_bycode(0);
116 dh6o_end
= dhcp6opttab_bycode(65536);
121 static struct dhcp6_opt
*
122 dhcp6opttab_byname(name
)
127 for (p
= dh6opttab
; p
->code
; p
++)
128 if (strcmp(name
, p
->name
) == 0)
134 static struct dhcp6_opt
*
135 dhcp6opttab_bycode(code
)
140 for (p
= dh6opttab
; p
->code
; p
++)
147 dhcp6ext_print(u_char
*cp
, u_char
*ep
)
158 if (ep
- cp
< sizeof(u_int16_t
))
160 code
= ntohs(*(u_int16_t
*)&cp
[0]);
161 if (ep
- cp
< sizeof(u_int16_t
) * 2)
164 len
= ntohs(*(u_int16_t
*)&cp
[2]);
167 if (ep
- cp
< len
+ 4)
169 p
= dhcp6opttab_bycode(code
);
171 printf("(unknown, len=%d)", len
);
176 /* sanity check on length */
193 if (cp
+ 4 + len
> ep
) {
194 printf("[|%s]", p
->name
);
198 printf("(%s, ", p
->name
);
201 for (i
= 0; i
< len
; i
+= 16) {
202 inet_ntop(AF_INET6
, &cp
[4 + i
], buf
,
210 memset(&buf
, 0, sizeof(buf
));
211 strncpy(buf
, &cp
[4], len
);
215 printf("%d", (u_int32_t
)ntohl(*(u_int32_t
*)&cp
[4]));
218 for (i
= 0; i
< len
; i
++)
219 printf("%02x", cp
[4 + i
] & 0xff);
227 printf("[|dhcp6ext]");
231 * Print dhcp6 requests
234 dhcp6_print(register const u_char
*cp
, u_int length
,
235 u_int16_t sport
, u_int16_t dport
)
244 ep
= (u_char
*)snapend
;
246 dh6
= (union dhcp6
*)cp
;
247 TCHECK(dh6
->dh6_msgtype
);
248 switch (dh6
->dh6_msgtype
) {
250 if (!(vflag
&& TTEST(dh6
->dh6_sol
.dh6sol_relayaddr
))) {
255 printf(" solicit("); /*)*/
256 if (dh6
->dh6_sol
.dh6sol_flags
!= 0) {
257 u_int8_t f
= dh6
->dh6_sol
.dh6sol_flags
;
259 (f
& DH6SOL_PREFIX
) ? "P" : "",
260 (f
& DH6SOL_CLOSE
) ? "C" : "");
263 memcpy(&field16
, &dh6
->dh6_sol
.dh6sol_plen_id
,
265 field16
= ntohs(field16
);
266 if (field16
& ~DH6SOL_SOLICIT_PLEN_MASK
)
267 printf("plen=%d ", DH6SOL_SOLICIT_PLEN(field16
));
268 printf("solicit-ID=%d", DH6SOL_SOLICIT_ID(field16
));
270 printf(" cliaddr=%s",
271 ip6addr_string(&dh6
->dh6_sol
.dh6sol_cliaddr
));
272 printf(" relayaddr=%s",
273 ip6addr_string(&dh6
->dh6_sol
.dh6sol_relayaddr
));
278 if (!(vflag
&& TTEST(dh6
->dh6_adv
.dh6adv_serveraddr
))) {
282 printf(" advert("); /*)*/
283 memcpy(&field16
, &dh6
->dh6_adv
.dh6adv_rsv_id
, sizeof(field16
));
284 printf("solicit-ID=%d",
285 ntohs(field16
) & DH6SOL_SOLICIT_ID_MASK
);
286 printf(" pref=%u", dh6
->dh6_adv
.dh6adv_pref
);
287 printf(" cliaddr=%s",
288 ip6addr_string(&dh6
->dh6_adv
.dh6adv_cliaddr
));
289 printf(" relayaddr=%s",
290 ip6addr_string(&dh6
->dh6_adv
.dh6adv_relayaddr
));
291 printf(" servaddr=%s",
292 ip6addr_string(&dh6
->dh6_adv
.dh6adv_serveraddr
));
293 extp
= (u_char
*)((&dh6
->dh6_adv
) + 1);
294 dhcp6ext_print(extp
, ep
);
299 if (!(vflag
&& TTEST(dh6
->dh6_req
.dh6req_relayaddr
))) {
303 printf(" request("); /*)*/
304 if (dh6
->dh6_req
.dh6req_flags
!= 0) {
305 u_int8_t f
= dh6
->dh6_req
.dh6req_flags
;
307 (f
& DH6REQ_CLOSE
) ? "C" : "",
308 (f
& DH6REQ_REBOOT
) ? "R" : "");
310 printf("xid=0x%04x", dh6
->dh6_req
.dh6req_xid
);
311 printf(" cliaddr=%s",
312 ip6addr_string(&dh6
->dh6_req
.dh6req_cliaddr
));
313 printf(" relayaddr=%s",
314 ip6addr_string(&dh6
->dh6_req
.dh6req_relayaddr
));
315 printf(" servaddr=%s",
316 ip6addr_string(&dh6
->dh6_req
.dh6req_serveraddr
));
317 dhcp6ext_print((char *)(&dh6
->dh6_req
+ 1), ep
);
322 if (!(vflag
&& TTEST(dh6
->dh6_rep
.dh6rep_xid
))) {
326 printf(" reply("); /*)*/
327 if ((dh6
->dh6_rep
.dh6rep_flagandstat
& DH6REP_RELAYPRESENT
) != 0)
329 printf("stat=0x%02x",
330 dh6
->dh6_rep
.dh6rep_flagandstat
& DH6REP_STATMASK
);
331 printf(" xid=0x%04x", dh6
->dh6_rep
.dh6rep_xid
);
332 printf(" cliaddr=%s",
333 ip6addr_string(&dh6
->dh6_rep
.dh6rep_cliaddr
));
334 extp
= (u_char
*)((&dh6
->dh6_rep
) + 1);
335 if ((dh6
->dh6_rep
.dh6rep_flagandstat
& DH6REP_RELAYPRESENT
) !=
337 printf(" relayaddr=%s", ip6addr_string(extp
));
338 extp
+= sizeof(struct in6_addr
);
340 dhcp6ext_print(extp
, ep
);