2 * Copyright (C) 2001 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-lwres.c,v 1.1 2001-01-29 09:18:50 itojun Exp $ (LBL)";
39 #include <sys/param.h>
42 #include <netinet/in.h>
45 #undef NOERROR /* Solaris sucks */
48 #undef T_UNSPEC /* SINIX does too */
55 #include "interface.h"
56 #include "addrtoname.h"
57 #include "extract.h" /* must come after interface.h */
59 /* BIND9 lib/lwres/include/lwres */
60 typedef u_int32_t lwres_uint32_t
;
61 typedef u_int16_t lwres_uint16_t
;
62 typedef u_int8_t lwres_uint8_t
;
64 struct lwres_lwpacket
{
65 lwres_uint32_t length
;
66 lwres_uint16_t version
;
67 lwres_uint16_t pktflags
;
68 lwres_uint32_t serial
;
69 lwres_uint32_t opcode
;
70 lwres_uint32_t result
;
71 lwres_uint32_t recvlength
;
72 lwres_uint16_t authtype
;
73 lwres_uint16_t authlength
;
76 #define LWRES_FLAG_TRUSTNOTREQUIRED 0x00000001U
77 #define LWRES_FLAG_SECUREDATA 0x00000002U
82 #define LWRES_OPCODE_NOOP 0x00000000U
86 lwres_uint16_t datalength
;
88 } lwres_nooprequest_t
;
92 lwres_uint16_t datalength
;
94 } lwres_noopresponse_t
;
97 * get addresses by name
99 #define LWRES_OPCODE_GETADDRSBYNAME 0x00010001U
103 lwres_uint32_t flags
;
104 lwres_uint32_t addrtypes
;
105 lwres_uint16_t namelen
;
107 } lwres_gabnrequest_t
;
111 lwres_uint32_t flags
;
112 lwres_uint16_t naliases
;
113 lwres_uint16_t naddrs
;
116 lwres_uint16_t realnamelen
;
117 lwres_uint16_t
*aliaslen
;
119 lwres_addrlist_t addrs
;
120 /* if base != NULL, it will be freed when this structure is freed. */
124 } lwres_gabnresponse_t
;
127 * get name by address
129 #define LWRES_OPCODE_GETNAMEBYADDR 0x00010002U
132 lwres_uint32_t flags
;
136 } lwres_gnbarequest_t
;
140 lwres_uint32_t flags
;
141 lwres_uint16_t naliases
;
145 lwres_uint16_t realnamelen
;
146 lwres_uint16_t
*aliaslen
;
147 /* if base != NULL, it will be freed when this structure is freed. */
151 } lwres_gnbaresponse_t
;
156 #define LWRES_OPCODE_GETRDATABYNAME 0x00010003U
160 lwres_uint32_t flags
;
161 lwres_uint16_t rdclass
;
162 lwres_uint16_t rdtype
;
163 lwres_uint16_t namelen
;
167 } lwres_grbnrequest_t
;
171 lwres_uint32_t flags
;
172 lwres_uint16_t rdclass
;
173 lwres_uint16_t rdtype
;
175 lwres_uint16_t nrdatas
;
176 lwres_uint16_t nsigs
;
179 lwres_uint16_t realnamelen
;
180 unsigned char **rdatas
;
181 lwres_uint16_t
*rdatalen
;
182 unsigned char **sigs
;
183 lwres_uint16_t
*siglen
;
184 /* if base != NULL, it will be freed when this structure is freed. */
188 } lwres_grbnresponse_t
;
190 #define LWRDATA_VALIDATED 0x00000001
192 #define LWRES_ADDRTYPE_V4 0x00000001U /* ipv4 */
193 #define LWRES_ADDRTYPE_V6 0x00000002U /* ipv6 */
195 #define LWRES_MAX_ALIASES 16 /* max # of aliases */
196 #define LWRES_MAX_ADDRS 64 /* max # of addrs */
203 struct vstr opcode
[] = {
204 { LWRES_OPCODE_NOOP
, "noop", },
205 { LWRES_OPCODE_GETADDRSBYNAME
, "getaddrsbyname", },
206 { LWRES_OPCODE_GETNAMEBYADDR
, "getnamebyaddr", },
207 { LWRES_OPCODE_GETRDATABYNAME
, "getrdatabyname", },
211 static const char *vtostr(struct vstr
*, u_int32_t
, const char *);
214 vtostr(p
, v
, lastresort
)
217 const char *lastresort
;
230 lwres_print(register const u_char
*bp
, u_int length
)
232 const struct lwres_lwpacket
*np
;
237 lwres_gabnrequest_t
*gabn
;
241 np
= (const struct lwres_lwpacket
*)bp
;
242 TCHECK(np
->authlength
);
246 printf(" v%u", ntohs(np
->version
));
249 v
= (u_int32_t
)ntohl(np
->opcode
);
250 s
= vtostr(opcode
, v
, NULL
);
259 v
= ntohs(np
->pktflags
);
262 (v
& LWRES_FLAG_TRUSTNOTREQUIRED
) ? "t" : "",
263 (v
& LWRES_FLAG_SECUREDATA
) ? "S" : "");
268 printf("serial:0x%x", (unsigned int)ntohl(np
->serial
));
269 printf(" result:0x%x", (unsigned int)ntohl(np
->result
));
270 printf(" recvlen:%u", (unsigned int)ntohl(np
->recvlength
));
271 printf(" authtype:0x%x", ntohs(np
->authtype
));
272 printf(" authlen:%u", ntohs(np
->authlength
));
277 #if 0 /*not completed yet*/
278 /* per-opcode content */
279 switch (ntohl(np
->opcode
)) {
280 case LWRES_OPCODE_NOOP
:
282 case LWRES_OPCODE_GETADDRSBYNAME
:
283 gabn
= (lwres_gabnrequest_t
*)(np
+ 1);
284 TCHECK(gabn
->namelen
);
285 /* XXX gabn points to packed struct */
286 s
= (const char *)&gabn
->namelen
+ sizeof(gabn
->namelen
);
287 l
= ntohs(gabn
->namelen
);
288 if (s
+ l
> (const char *)snapend
)
291 printf(" flags:0x%x", (unsigned int)ntohl(gabn
->flags
));
292 v
= (u_int32_t
)ntohl(gabn
->addrtypes
);
293 switch (v
& (LWRES_ADDRTYPE_V4
| LWRES_ADDRTYPE_V6
)) {
294 case LWRES_ADDRTYPE_V4
:
297 case LWRES_ADDRTYPE_V6
:
300 case LWRES_ADDRTYPE_V4
| LWRES_ADDRTYPE_V6
:
304 if (v
& ~(LWRES_ADDRTYPE_V4
| LWRES_ADDRTYPE_V6
))
307 for (i
= 0; i
< l
; i
++)
310 case LWRES_OPCODE_GETNAMEBYADDR
:
312 case LWRES_OPCODE_GETRDATABYNAME
:
319 /* length mismatch */
320 if (ntohl(np
->length
) != length
)
321 printf(" [len: %u != %u]", (unsigned int)ntohl(np
->length
), length
);