]>
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.2 1999-11-21 09:36:50 fenner Exp $";
39 #include <sys/param.h>
41 #include <sys/socket.h>
49 #include <netinet/in.h>
58 #include "interface.h"
59 #include "addrtoname.h"
64 static void dhcp6opttab_init
__P((void));
66 static struct dhcp6_opt
*dhcp6opttab_byname
__P((char *));
67 static struct dhcp6_opt
*dhcp6opttab_bycode
__P((u_int
));
69 static char tstr
[] = " [|dhcp6]";
71 static struct dhcp6_opt dh6opttab
[] = {
72 /* IP Address Extension */
73 { 1, OL6_N
, "IP Address", OT6_NONE
, },
75 /* General Extension */
76 { 2, 4, "Time Offset", OT6_NUM
, },
77 { 3, OL6_N
, "IEEE 1003.1 POSIX Timezone", OT6_STR
, },
78 { 6, OL6_16N
, "Domain Name Server", OT6_V6
, },
79 { 10, OL6_N
, "Domain Name", OT6_STR
, },
81 /* Application and Service Parameters */
82 { 16, OL6_N
, "Directory Agent", OT6_NONE
, },
83 { 17, OL6_N
, "Service Scope" , OT6_NONE
, },
84 { 18, OL6_16N
, "Network Time Protocol Servers", OT6_V6
, },
85 { 19, OL6_N
, "NIS Domain", OT6_STR
, },
86 { 20, OL6_16N
, "NIS Servers", OT6_V6
, },
87 { 21, OL6_N
, "NIS+ Domain", OT6_STR
, },
88 { 22, OL6_16N
, "NIS+ Servers", OT6_V6
, },
91 { 32, 4, "TCP Keepalive Interval", OT6_NUM
, },
93 /* DHCPv6 Extensions */
94 { 40, 4, "Maximum DHCPv6 Message Size", OT6_NUM
, },
95 { 41, OL6_N
, "DHCP Retransmission and Configuration Parameter",
97 { 48, OL6_N
, "Platform Specific Information", OT6_NONE
, },
98 { 49, OL6_N
, "Platform Class Identifier", OT6_STR
, },
99 { 64, OL6_N
, "Class Identifier", OT6_STR
, },
100 { 66, 16, "Reconfigure Multicast Address", OT6_V6
, },
101 { 67, 16, "Renumber DHCPv6 Server Address",
103 { 68, OL6_N
, "DHCP Relay ICMP Error Message", OT6_NONE
, },
104 { 84, OL6_N
, "Client-Server Authentication", OT6_NONE
, },
105 { 85, 4, "Client Key Selection", OT6_NUM
, },
108 { 65536, OL6_Z
, "End", OT6_NONE
, },
114 static struct dhcp6_opt
*dh6o_pad
;
115 static struct dhcp6_opt
*dh6o_end
;
120 dh6o_pad
= dhcp6opttab_bycode(0);
121 dh6o_end
= dhcp6opttab_bycode(65536);
125 static struct dhcp6_opt
*
126 dhcp6opttab_byname(name
)
131 for (p
= dh6opttab
; p
->code
; p
++)
132 if (strcmp(name
, p
->name
) == 0)
137 static struct dhcp6_opt
*
138 dhcp6opttab_bycode(code
)
143 for (p
= dh6opttab
; p
->code
; p
++)
150 dhcp6ext_print(u_char
*cp
, u_char
*ep
)
162 code
= ntohs(*(u_int16_t
*)&cp
[0]);
164 len
= ntohs(*(u_int16_t
*)&cp
[2]);
167 p
= dhcp6opttab_bycode(code
);
169 printf("(unknown, len=%d)", len
);
174 /* sanity check on length */
191 if (cp
+ 4 + len
> ep
) {
192 printf("[|%s]", p
->name
);
196 printf("(%s, ", p
->name
);
199 for (i
= 0; i
< len
; i
+= 16) {
200 inet_ntop(AF_INET6
, &cp
[4 + i
], buf
,
208 memset(&buf
, 0, sizeof(buf
));
209 strncpy(buf
, &cp
[4], len
);
213 printf("%d", (u_int32_t
)ntohl(*(u_int32_t
*)&cp
[4]));
216 for (i
= 0; i
< len
; i
++)
217 printf("%02x", cp
[4 + i
] & 0xff);
225 printf("[|dhcp6ext]");
229 * Print dhcp6 requests
232 dhcp6_print(register const u_char
*cp
, u_int length
,
233 u_short sport
, u_short dport
)
241 ep
= (u_char
*)snapend
;
243 dh6
= (union dhcp6
*)cp
;
244 TCHECK(dh6
->dh6_msgtype
);
245 switch (dh6
->dh6_msgtype
) {
247 if (vflag
&& TTEST(dh6
->dh6_sol
.dh6sol_relayaddr
)) {
249 if ((dh6
->dh6_sol
.dh6sol_flags
& DH6SOL_CLOSE
) != 0)
251 if (dh6
->dh6_sol
.dh6sol_flags
!= 0)
254 ip6addr_string(&dh6
->dh6_sol
.dh6sol_cliaddr
));
255 printf(" relayaddr=%s",
256 ip6addr_string(&dh6
->dh6_sol
.dh6sol_relayaddr
));
262 if (!(vflag
&& TTEST(dh6
->dh6_adv
.dh6adv_serveraddr
))) {
267 if ((dh6
->dh6_adv
.dh6adv_flags
& DH6ADV_SERVPRESENT
) != 0)
269 if (dh6
->dh6_adv
.dh6adv_flags
!= 0)
271 printf("pref=%u", dh6
->dh6_adv
.dh6adv_pref
);
272 printf(" cliaddr=%s",
273 ip6addr_string(&dh6
->dh6_adv
.dh6adv_cliaddr
));
274 printf(" relayaddr=%s",
275 ip6addr_string(&dh6
->dh6_adv
.dh6adv_relayaddr
));
276 printf(" servaddr=%s",
277 ip6addr_string(&dh6
->dh6_adv
.dh6adv_serveraddr
));
278 extp
= (u_char
*)((&dh6
->dh6_adv
) + 1);
279 dhcp6ext_print(extp
, ep
);
283 if (!(vflag
&& TTEST(dh6
->dh6_req
.dh6req_relayaddr
))) {
288 if ((dh6
->dh6_req
.dh6req_flags
& DH6REQ_CLOSE
) != 0)
290 if ((dh6
->dh6_req
.dh6req_flags
& DH6REQ_SERVPRESENT
) != 0)
292 if ((dh6
->dh6_req
.dh6req_flags
& DH6REQ_REBOOT
) != 0)
294 if (dh6
->dh6_req
.dh6req_flags
!= 0)
296 printf("xid=0x%04x", dh6
->dh6_req
.dh6req_xid
);
297 printf(" cliaddr=%s",
298 ip6addr_string(&dh6
->dh6_req
.dh6req_cliaddr
));
299 printf(" relayaddr=%s",
300 ip6addr_string(&dh6
->dh6_req
.dh6req_relayaddr
));
301 extp
= (char *)((&dh6
->dh6_req
) + 1);
302 if ((dh6
->dh6_req
.dh6req_flags
& DH6REQ_SERVPRESENT
) != 0) {
303 printf(" servaddr=%s", ip6addr_string(extp
));
306 dhcp6ext_print(extp
, ep
);
310 if (!(vflag
&& TTEST(dh6
->dh6_rep
.dh6rep_xid
))) {
315 if ((dh6
->dh6_rep
.dh6rep_flagandstat
& DH6REP_CLIPRESENT
) != 0)
317 if (dh6
->dh6_rep
.dh6rep_flagandstat
!= 0)
319 printf("stat=0x%02x",
320 dh6
->dh6_rep
.dh6rep_flagandstat
& DH6REP_STATMASK
);
321 extp
= (u_char
*)((&dh6
->dh6_rep
) + 1);
322 if ((dh6
->dh6_rep
.dh6rep_flagandstat
& DH6REP_CLIPRESENT
) != 0) {
323 printf(" cliaddr=%s", ip6addr_string(extp
));
326 dhcp6ext_print(extp
, ep
);