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 #if _STRING_ARCH_unaligned
19 # define NS_GET16(s, cp) \
21 const uint16_t *t_cp = (const uint16_t *) (cp); \
22 (s) = ntohs (*t_cp); \
27 # define NS_GET32(l, cp) \
29 const uint32_t *t_cp = (const uint32_t *) (cp); \
30 (l) = ntohl (*t_cp); \
35 # define NS_PUT16(s, cp) \
37 uint16_t *t_cp = (uint16_t *) (cp); \
43 # define NS_PUT32(l, cp) \
45 uint32_t *t_cp = (uint32_t *) (cp); \
52 extern unsigned int __ns_get16 (const unsigned char *) __THROW
;
53 extern unsigned long __ns_get32 (const unsigned char *) __THROW
;
54 int __ns_name_ntop (const unsigned char *, char *, size_t) __THROW
;
55 int __ns_name_unpack (const unsigned char *, const unsigned char *,
56 const unsigned char *, unsigned char *, size_t) __THROW
;
58 /* Like ns_samename, but for uncompressed binary names. Return true
59 if the two arguments compare are equal as case-insensitive domain
61 _Bool
__ns_samebinaryname (const unsigned char *, const unsigned char *)
64 #define ns_msg_getflag(handle, flag) \
65 (((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift)
67 libresolv_hidden_proto (ns_get16
)
68 libresolv_hidden_proto (ns_get32
)
69 libresolv_hidden_proto (ns_put16
)
70 libresolv_hidden_proto (ns_put32
)
71 libresolv_hidden_proto (ns_initparse
)
72 libresolv_hidden_proto (ns_skiprr
)
73 libresolv_hidden_proto (ns_parserr
)
74 libresolv_hidden_proto (ns_sprintrr
)
75 libresolv_hidden_proto (ns_sprintrrf
)
76 libresolv_hidden_proto (ns_samedomain
)
77 libresolv_hidden_proto (ns_format_ttl
)
79 extern __typeof (ns_makecanon
) __libc_ns_makecanon
;
80 libc_hidden_proto (__libc_ns_makecanon
)
81 extern __typeof (ns_name_compress
) __ns_name_compress
;
82 libc_hidden_proto (__ns_name_compress
)
83 extern __typeof (ns_name_ntop
) __ns_name_ntop
;
84 libc_hidden_proto (__ns_name_ntop
)
85 extern __typeof (ns_name_pack
) __ns_name_pack
;
86 libc_hidden_proto (__ns_name_pack
)
87 extern __typeof (ns_name_pton
) __ns_name_pton
;
88 libc_hidden_proto (__ns_name_pton
)
89 extern __typeof (ns_name_skip
) __ns_name_skip
;
90 libc_hidden_proto (__ns_name_skip
)
91 extern __typeof (ns_name_uncompress
) __ns_name_uncompress
;
92 libc_hidden_proto (__ns_name_uncompress
)
93 extern __typeof (ns_name_unpack
) __ns_name_unpack
;
94 libc_hidden_proto (__ns_name_unpack
)
95 extern __typeof (ns_samename
) __libc_ns_samename
;
96 libc_hidden_proto (__libc_ns_samename
)
98 /* Packet parser helper functions. */
100 /* Verify that P points to an uncompressed domain name in wire format.
101 On success, return the length of the encoded name, including the
102 terminating null byte. On failure, return -1 and set errno. EOM
103 must point one past the last byte in the packet. */
104 int __ns_name_length_uncompressed (const unsigned char *p
,
105 const unsigned char *eom
) attribute_hidden
;
107 /* Iterator over the resource records in a DNS packet. */
110 /* These members are not changed after initialization. */
111 const unsigned char *begin
; /* First byte of packet. */
112 const unsigned char *end
; /* One past the last byte of the packet. */
113 const unsigned char *first_rr
; /* First resource record (or packet end). */
115 /* Advanced towards the end while reading the packet. */
116 const unsigned char *current
;
119 /* Returns the RCODE field from the DNS header. */
121 ns_rr_cursor_rcode (const struct ns_rr_cursor
*c
)
123 return c
->begin
[3] & 0x0f; /* Lower 4 bits at offset 3. */
126 /* Returns the length of the answer section according to the DNS header. */
128 ns_rr_cursor_ancount (const struct ns_rr_cursor
*c
)
130 return c
->begin
[6] * 256 + c
->begin
[7]; /* 16 bits at offset 6. */
133 /* Returns the length of the authority (name server) section according
134 to the DNS header. */
136 ns_rr_cursor_nscount (const struct ns_rr_cursor
*c
)
138 return c
->begin
[8] * 256 + c
->begin
[9]; /* 16 bits at offset 8. */
141 /* Returns the length of the additional data section according to the
144 ns_rr_cursor_adcount (const struct ns_rr_cursor
*c
)
146 return c
->begin
[10] * 256 + c
->begin
[11]; /* 16 bits at offset 10. */
149 /* Returns a pointer to the uncompressed question name in wire
151 static inline const unsigned char *
152 ns_rr_cursor_qname (const struct ns_rr_cursor
*c
)
154 return c
->begin
+ 12; /* QNAME starts right after the header. */
157 /* Returns the question type of the first and only question. */
158 static inline const int
159 ns_rr_cursor_qtype (const struct ns_rr_cursor
*c
)
161 /* 16 bits 4 bytes back from the first RR header start. */
162 return c
->first_rr
[-4] * 256 + c
->first_rr
[-3];
165 /* Returns the clss of the first and only question (usally C_IN). */
166 static inline const int
167 ns_rr_cursor_qclass (const struct ns_rr_cursor
*c
)
169 /* 16 bits 2 bytes back from the first RR header start. */
170 return c
->first_rr
[-2] * 256 + c
->first_rr
[-1];
173 /* Initializes *C to cover the packet [BUF, BUF+LEN). Returns false
174 if LEN is less than sizeof (*HD), if the packet does not contain a
175 full (uncompressed) question, or if the question count is not 1. */
176 _Bool
__ns_rr_cursor_init (struct ns_rr_cursor
*c
,
177 const unsigned char *buf
, size_t len
)
180 /* Like ns_rr, but the record owner name is not decoded into text format. */
183 unsigned char rname
[NS_MAXCDNAME
]; /* Owner name of the record. */
184 uint16_t rtype
; /* Resource record type (T_*). */
185 uint16_t rclass
; /* Resource record class (C_*). */
186 uint32_t ttl
; /* Time-to-live field. */
187 const unsigned char *rdata
; /* Start of resource record data. */
188 uint16_t rdlength
; /* Length of the data at rdata, in bytes. */
191 /* Attempts to parse the record at C into *RR. On success, return
192 true, and C is advanced past the record, and RR->rdata points to
193 the record data. On failure, errno is set to EMSGSIZE, and false
195 _Bool
__ns_rr_cursor_next (struct ns_rr_cursor
*c
, struct ns_rr_wire
*rr
)
198 # endif /* !_ISOMAC */