Merge from vendor branch TNFTP:
[dragonfly.git] / contrib / bind-9.3 / lib / lwres / include / lwres / lwpacket.h
1 /*
2  * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2001  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /* $Id: lwpacket.h,v 1.17.206.1 2004/03/06 08:15:35 marka Exp $ */
19
20 #ifndef LWRES_LWPACKET_H
21 #define LWRES_LWPACKET_H 1
22
23 #include <lwres/lang.h>
24 #include <lwres/lwbuffer.h>
25 #include <lwres/result.h>
26
27 typedef struct lwres_lwpacket lwres_lwpacket_t;
28
29 struct lwres_lwpacket {
30         lwres_uint32_t          length;
31         lwres_uint16_t          version;
32         lwres_uint16_t          pktflags;
33         lwres_uint32_t          serial;
34         lwres_uint32_t          opcode;
35         lwres_uint32_t          result;
36         lwres_uint32_t          recvlength;
37         lwres_uint16_t          authtype;
38         lwres_uint16_t          authlength;
39 };
40
41 #define LWRES_LWPACKET_LENGTH           (4 * 5 + 2 * 4)
42
43 #define LWRES_LWPACKETFLAG_RESPONSE     0x0001U /* if set, pkt is a response */
44
45
46 #define LWRES_LWPACKETVERSION_0         0
47
48 /*
49  * "length" is the overall packet length, including the entire packet header.
50  *
51  * "version" specifies the header format.  Currently, there is only one
52  * format, LWRES_LWPACKETVERSION_0.
53  *
54  * "flags" specifies library-defined flags for this packet.  None of these
55  * are definable by the caller, but library-defined values can be set by
56  * the caller.  For example, one bit in this field indicates if the packet
57  * is a request or a response.
58  *
59  * "serial" is set by the requestor and is returned in all replies.  If two
60  * packets from the same source have the same serial number and are from
61  * the same source, they are assumed to be duplicates and the latter ones
62  * may be dropped.  (The library does not do this by default on replies, but
63  * does so on requests.)
64  *
65  * "opcode" is application defined.  Opcodes between 0x04000000 and 0xffffffff
66  * are application defined.  Opcodes between 0x00000000 and 0x03ffffff are
67  * reserved for library use.
68  *
69  * "result" is application defined, and valid only on replies.
70  * Results between 0x04000000 and 0xffffffff are application defined.
71  * Results between 0x00000000 and 0x03ffffff are reserved for library use.
72  * (This is the same reserved range defined in <isc/resultclass.h>, so it
73  * would be trivial to map ISC_R_* result codes into packet result codes
74  * when appropriate.)
75  *
76  * "recvlength" is set to the maximum buffer size that the receiver can
77  * handle on requests, and the size of the buffer needed to satisfy a request
78  * when the buffer is too large for replies.
79  *
80  * "authtype" is the packet level auth type used.
81  * Authtypes between 0x1000 and 0xffff are application defined.  Authtypes
82  * between 0x0000 and 0x0fff are reserved for library use.  This is currently
83  * unused and MUST be set to zero.
84  *
85  * "authlen" is the length of the authentication data.  See the specific
86  * authtypes for more information on what is contained in this field.  This
87  * is currently unused, and MUST be set to zero.
88  *
89  * The remainder of the packet consists of two regions, one described by
90  * "authlen" and one of "length - authlen - sizeof(lwres_lwpacket_t)".
91  *
92  * That is:
93  *
94  *      pkt header
95  *      authlen bytes of auth information
96  *      data bytes
97  */
98
99 /*
100  * Currently defined opcodes:
101  *
102  *      NOOP.  Success is always returned, with the packet contents echoed.
103  *
104  *      GETADDRSBYNAME.  Return all known addresses for a given name.
105  *              This may return NIS or /etc/hosts info as well as DNS
106  *              information.  Flags will be provided to indicate ip4/ip6
107  *              addresses are desired.
108  *
109  *      GETNAMEBYADDR.  Return the hostname for the given address.  Once
110  *              again, it will return data from multiple sources.
111  */
112
113 LWRES_LANG_BEGINDECLS
114
115 /* XXXMLG document */
116 lwres_result_t
117 lwres_lwpacket_renderheader(lwres_buffer_t *b, lwres_lwpacket_t *pkt);
118
119 lwres_result_t
120 lwres_lwpacket_parseheader(lwres_buffer_t *b, lwres_lwpacket_t *pkt);
121
122 LWRES_LANG_ENDDECLS
123
124 #endif /* LWRES_LWPACKET_H */