1 #ifndef _ARPA_NAMESER_H_
3 #include <resolv/arpa/nameser.h>
7 /* If the machine allows unaligned access we can do better than using
8 the NS_GET16, NS_GET32, NS_PUT16, and NS_PUT32 macros from the
12 #include <netinet/in.h>
14 extern const struct _ns_flagdata _ns_flagdata
[] attribute_hidden
;
16 extern unsigned int __ns_get16 (const unsigned char *) __THROW
;
17 extern unsigned long __ns_get32 (const unsigned char *) __THROW
;
18 int __ns_name_ntop (const unsigned char *, char *, size_t) __THROW
;
19 int __ns_name_unpack (const unsigned char *, const unsigned char *,
20 const unsigned char *, unsigned char *, size_t) __THROW
;
22 /* Like ns_samename, but for uncompressed binary names. Return true
23 if the two arguments compare are equal as case-insensitive domain
25 _Bool
__ns_samebinaryname (const unsigned char *, const unsigned char *)
28 #define ns_msg_getflag(handle, flag) \
29 (((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift)
31 libresolv_hidden_proto (ns_get16
)
32 libresolv_hidden_proto (ns_get32
)
33 libresolv_hidden_proto (ns_put16
)
34 libresolv_hidden_proto (ns_put32
)
35 libresolv_hidden_proto (ns_initparse
)
36 libresolv_hidden_proto (ns_skiprr
)
37 libresolv_hidden_proto (ns_parserr
)
38 libresolv_hidden_proto (ns_sprintrr
)
39 libresolv_hidden_proto (ns_sprintrrf
)
40 libresolv_hidden_proto (ns_samedomain
)
41 libresolv_hidden_proto (ns_format_ttl
)
43 extern __typeof (ns_makecanon
) __libc_ns_makecanon
;
44 libc_hidden_proto (__libc_ns_makecanon
)
45 extern __typeof (ns_name_compress
) __ns_name_compress
;
46 libc_hidden_proto (__ns_name_compress
)
47 extern __typeof (ns_name_ntop
) __ns_name_ntop
;
48 libc_hidden_proto (__ns_name_ntop
)
49 extern __typeof (ns_name_pack
) __ns_name_pack
;
50 libc_hidden_proto (__ns_name_pack
)
51 extern __typeof (ns_name_pton
) __ns_name_pton
;
52 libc_hidden_proto (__ns_name_pton
)
53 extern __typeof (ns_name_skip
) __ns_name_skip
;
54 libc_hidden_proto (__ns_name_skip
)
55 extern __typeof (ns_name_uncompress
) __ns_name_uncompress
;
56 libc_hidden_proto (__ns_name_uncompress
)
57 extern __typeof (ns_name_unpack
) __ns_name_unpack
;
58 libc_hidden_proto (__ns_name_unpack
)
59 extern __typeof (ns_samename
) __libc_ns_samename
;
60 libc_hidden_proto (__libc_ns_samename
)
62 /* Packet parser helper functions. */
64 /* Verify that P points to an uncompressed domain name in wire format.
65 On success, return the length of the encoded name, including the
66 terminating null byte. On failure, return -1 and set errno. EOM
67 must point one past the last byte in the packet. */
68 int __ns_name_length_uncompressed (const unsigned char *p
,
69 const unsigned char *eom
) attribute_hidden
;
71 /* Iterator over the resource records in a DNS packet. */
74 /* These members are not changed after initialization. */
75 const unsigned char *begin
; /* First byte of packet. */
76 const unsigned char *end
; /* One past the last byte of the packet. */
77 const unsigned char *first_rr
; /* First resource record (or packet end). */
79 /* Advanced towards the end while reading the packet. */
80 const unsigned char *current
;
83 /* Returns the RCODE field from the DNS header. */
85 ns_rr_cursor_rcode (const struct ns_rr_cursor
*c
)
87 return c
->begin
[3] & 0x0f; /* Lower 4 bits at offset 3. */
90 /* Returns the length of the answer section according to the DNS header. */
92 ns_rr_cursor_ancount (const struct ns_rr_cursor
*c
)
94 return c
->begin
[6] * 256 + c
->begin
[7]; /* 16 bits at offset 6. */
97 /* Returns the length of the authority (name server) section according
100 ns_rr_cursor_nscount (const struct ns_rr_cursor
*c
)
102 return c
->begin
[8] * 256 + c
->begin
[9]; /* 16 bits at offset 8. */
105 /* Returns the length of the additional data section according to the
108 ns_rr_cursor_adcount (const struct ns_rr_cursor
*c
)
110 return c
->begin
[10] * 256 + c
->begin
[11]; /* 16 bits at offset 10. */
113 /* Returns a pointer to the uncompressed question name in wire
115 static inline const unsigned char *
116 ns_rr_cursor_qname (const struct ns_rr_cursor
*c
)
118 return c
->begin
+ 12; /* QNAME starts right after the header. */
121 /* Returns the question type of the first and only question. */
122 static inline const int
123 ns_rr_cursor_qtype (const struct ns_rr_cursor
*c
)
125 /* 16 bits 4 bytes back from the first RR header start. */
126 return c
->first_rr
[-4] * 256 + c
->first_rr
[-3];
129 /* Returns the clss of the first and only question (usually C_IN). */
130 static inline const int
131 ns_rr_cursor_qclass (const struct ns_rr_cursor
*c
)
133 /* 16 bits 2 bytes back from the first RR header start. */
134 return c
->first_rr
[-2] * 256 + c
->first_rr
[-1];
137 /* Initializes *C to cover the packet [BUF, BUF+LEN). Returns false
138 if LEN is less than sizeof (*HD), if the packet does not contain a
139 full (uncompressed) question, or if the question count is not 1. */
140 _Bool
__ns_rr_cursor_init (struct ns_rr_cursor
*c
,
141 const unsigned char *buf
, size_t len
)
144 /* Like ns_rr, but the record owner name is not decoded into text format. */
147 unsigned char rname
[NS_MAXCDNAME
]; /* Owner name of the record. */
148 uint16_t rtype
; /* Resource record type (T_*). */
149 uint16_t rclass
; /* Resource record class (C_*). */
150 uint32_t ttl
; /* Time-to-live field. */
151 const unsigned char *rdata
; /* Start of resource record data. */
152 uint16_t rdlength
; /* Length of the data at rdata, in bytes. */
155 /* Attempts to parse the record at C into *RR. On success, return
156 true, and C is advanced past the record, and RR->rdata points to
157 the record data. On failure, errno is set to EMSGSIZE, and false
159 _Bool
__ns_rr_cursor_next (struct ns_rr_cursor
*c
, struct ns_rr_wire
*rr
)
162 # endif /* !_ISOMAC */