]>
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
30 * draft-ietf-dhc-dhcpv6-22.txt
34 static const char rcsid
[] =
35 "@(#) $Header: /tcpdump/master/tcpdump/print-dhcp6.c,v 1.17 2002-06-01 23:50:30 guy Exp $";
42 #include <sys/param.h>
44 #include <sys/socket.h>
46 #include <netinet/in.h>
51 #include <arpa/inet.h>
53 #include "interface.h"
54 #include "addrtoname.h"
57 #define DH6ERR_FAILURE 16
58 #define DH6ERR_AUTHFAIL 17
59 #define DH6ERR_POORLYFORMED 18
60 #define DH6ERR_UNAVAIL 19
61 #define DH6ERR_OPTUNAVAIL 20
65 #define DH6_INFORM_REQ 11
67 /* DHCP6 base packet format */
73 struct in6_addr dh6_servaddr
;
75 } __attribute__ ((__packed__
));
76 #define dh6_msgtype dh6_msgtypexid.m
77 #define dh6_xid dh6_msgtypexid.x
78 #define DH6_XIDMASK 0x00ffffff
81 #define DH6OPT_DUID 1 /* TBD */
82 #define DH6OPT_DNS 11 /* TBD */
84 u_int16_t dh6opt_type
;
86 /* type-dependent data follows */
87 } __attribute__ ((__packed__
));
90 dhcp6opt_print(u_char
*cp
, u_char
*ep
)
92 struct dhcp6opt
*dh6o
;
100 if (ep
- cp
< sizeof(*dh6o
))
102 dh6o
= (struct dhcp6opt
*)cp
;
103 optlen
= ntohs(dh6o
->dh6opt_len
);
104 if (ep
- cp
< sizeof(*dh6o
) + optlen
)
106 switch (ntohs(dh6o
->dh6opt_type
)) {
108 printf(" (duid"); /*)*/
114 tp
= (u_char
*)(dh6o
+ 1);
115 switch (ntohs(*(u_int16_t
*)tp
)) {
117 if (optlen
>= 2 + 6) {
118 printf(" hwaddr/time time %u type %u ",
119 ntohl(*(u_int32_t
*)&tp
[2]),
120 ntohs(*(u_int16_t
*)&tp
[6]));
121 for (i
= 8; i
< optlen
; i
++)
122 printf("%02x", tp
[i
]);
131 if (optlen
>= 2 + 8) {
133 for (i
= 2; i
< 2 + 8; i
++)
134 printf("%02x", tp
[i
]);
143 if (optlen
>= 2 + 2) {
144 printf(" hwaddr type %u ",
145 ntohs(*(u_int16_t
*)&tp
[2]));
146 for (i
= 4; i
< optlen
; i
++)
147 printf("%02x", tp
[i
]);
157 printf(" (dnsserver"); /*)*/
163 tp
= (u_char
*)(dh6o
+ 1);
164 for (i
= 0; i
< optlen
; i
+= 16)
165 printf(" %s", ip6addr_string(&tp
[i
]));
169 printf(" (opt-%u)", ntohs(dh6o
->dh6opt_type
));
173 cp
+= sizeof(*dh6o
) + optlen
;
178 printf("[|dhcp6ext]");
182 * Print dhcp6 packets
185 dhcp6_print(register const u_char
*cp
, u_int length
,
186 u_int16_t sport
, u_int16_t dport
)
195 ep
= (u_char
*)snapend
;
197 dh6
= (struct dhcp6
*)cp
;
198 TCHECK(dh6
->dh6_servaddr
);
199 switch (dh6
->dh6_msgtype
) {
215 printf(" msgtype-%u", dh6
->dh6_msgtype
);
219 /* XXX relay agent messages have to be handled differently */
222 printf(" %s (", name
); /*)*/
224 printf(" msgtype-%u (", dh6
->dh6_msgtype
); /*)*/
225 printf("xid=%x", ntohl(dh6
->dh6_xid
) & DH6_XIDMASK
);
226 printf(" server=%s", ip6addr_string(&dh6
->dh6_servaddr
));
227 extp
= (u_char
*)(dh6
+ 1);
228 dhcp6opt_print(extp
, ep
);