Changeset 753 for pjproject/trunk/pjlib-util/include/pjlib-util/dns.h
- Timestamp:
- Oct 8, 2006 12:39:34 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib-util/include/pjlib-util/dns.h
r745 r753 23 23 /** 24 24 * @file dns.h 25 * @brief Asynchronous DNS Name Resolution/resolver25 * @brief Low level DNS message parsing and packetization. 26 26 */ 27 27 #include <pj/types.h> … … 32 32 33 33 /** 34 * @defgroup PJ_DNS _RESOLVER Asynchronous DNS Name Resolution/resolver34 * @defgroup PJ_DNS Low-level DNS message parsing and packetization 35 35 * @ingroup PJ 36 36 * @{ 37 37 * 38 * This module provides services to performing asynchronous DNS resolution. 39 */ 38 * This module provides low-level services to parse and packetize DNS queries 39 * and responses. The functions support building a DNS query packet and parse 40 * the data in the DNS response. 41 * 42 * To create a DNS query packet, application should call #pj_dns_make_query() 43 * function, specifying the desired DNS query type, the name to be resolved, 44 * and the buffer where the DNS packet will be built into. 45 * 46 * When incoming DNS query or response packet arrives, application can use 47 * #pj_dns_parse_packet() to parse the TCP/UDP payload into parsed DNS packet 48 * structure. 49 * 50 * This module does not provide any networking functionalities to send or 51 * receive DNS packets. This functionality should be provided by higher layer 52 * modules such as @ref PJ_DNS_RESOLVER. 53 */ 54 55 enum 56 { 57 PJ_DNS_CLASS_IN = 1 /**< DNS class IN. */ 58 }; 40 59 41 60 /** 42 61 * This enumeration describes standard DNS record types as described by 43 * RFC 1035 .62 * RFC 1035, RFC 2782, and others. 44 63 */ 45 64 typedef enum pj_dns_type … … 159 178 160 179 161 162 /** 163 * This constants describes record types in the DNS packet. 164 */ 165 typedef enum pj_dns_rec_type 166 { 167 DNS_QUERY_REC, /**< The record is a query record */ 168 DNS_RR_REC, /**< The record is resource record */ 169 DNS_NS_REC, /**< The record is name server record */ 170 DNS_REC_AR, /**< The record is additional RR. */ 171 } pj_dns_rec_type; 172 173 174 /** 175 * This structure describes a Resource Record parsed from the DNS response. 180 /** 181 * These constants describe DNS RCODEs. Application can fold these constants 182 * into PJLIB pj_status_t namespace by calling #PJ_STATUS_FROM_DNS_RCODE() 183 * macro. 184 */ 185 typedef enum pj_dns_rcode 186 { 187 PJ_DNS_RCODE_FORMERR = 1, /**< Format error. */ 188 PJ_DNS_RCODE_SERVFAIL = 2, /**< Server failure. */ 189 PJ_DNS_RCODE_NXDOMAIN = 3, /**< Name Error. */ 190 PJ_DNS_RCODE_NOTIMPL = 4, /**< Not Implemented. */ 191 PJ_DNS_RCODE_REFUSED = 5, /**< Refused. */ 192 PJ_DNS_RCODE_YXDOMAIN = 6, /**< The name exists. */ 193 PJ_DNS_RCODE_YXRRSET = 7, /**< The RRset (name, type) exists. */ 194 PJ_DNS_RCODE_NXRRSET = 8, /**< The RRset (name, type) doesn't exist*/ 195 PJ_DNS_RCODE_NOTAUTH = 9, /**< Not authorized. */ 196 PJ_DNS_RCODE_NOTZONE = 10 /**< The zone specified is not a zone. */ 197 198 } pj_dns_rcode; 199 200 201 /** 202 * This constant specifies the maximum names to keep in the temporary name 203 * table when performing name compression scheme when duplicating DNS packet 204 * (the #pj_dns_packet_dup() function). 205 * 206 * Generally name compression is desired, since it saves some memory (see 207 * PJ_DNS_RESOLVER_RES_BUF_SIZE setting). However it comes at the expense of 208 * a little processing overhead to perform name scanning and also a little 209 * bit more stack usage (8 bytes per entry on 32bit platform). 210 * 211 * Default: 16 212 */ 213 #ifndef PJ_DNS_MAX_NAMES_IN_NAMETABLE 214 # define PJ_DNS_MAX_NAMES_IN_NAMETABLE 16 215 #endif 216 217 218 /** 219 * This structure describes a DNS query record. 220 */ 221 typedef struct pj_dns_parsed_query 222 { 223 pj_str_t name; /**< The domain in the query. */ 224 pj_uint16_t type; /**< Type of the query (pj_dns_type) */ 225 pj_uint16_t dnsclass; /**< Network class (PJ_DNS_CLASS_IN=1) */ 226 } pj_dns_parsed_query; 227 228 229 /** 230 * This structure describes a Resource Record parsed from the DNS packet. 176 231 * All integral values are in host byte order. 177 232 */ … … 180 235 pj_str_t name; /**< The domain name which this rec pertains. */ 181 236 pj_uint16_t type; /**< RR type code. */ 182 pj_uint16_t class_; /**< Class of data (normally 1, for IN). */237 pj_uint16_t dnsclass; /**< Class of data (PJ_DNS_CLASS_IN=1). */ 183 238 pj_uint32_t ttl; /**< Time to live. */ 184 239 pj_uint16_t rdlength; /**< Resource data length. */ 185 void *data; /**< Pointer to the raw resource data. */ 240 void *data; /**< Pointer to the raw resource data, only 241 when the type is not known. If it is known, 242 the data will be put in rdata below. */ 186 243 187 244 /** For resource types that are recognized/supported by this library, … … 224 281 225 282 /** 226 * This structure describes the response parsed from the raw DNS response.227 * Note that all integral values in the parsed responseare represented in283 * This structure describes the parsed repersentation of the raw DNS packet. 284 * Note that all integral values in the parsed packet are represented in 228 285 * host byte order. 229 286 */ 230 typedef struct pj_dns_parsed_response 231 { 232 pj_dns_hdr hdr; /**< Pointer to DNS hdr, in host byte order */ 233 pj_dns_parsed_rr *ans; /**< Array of DNS RR answer. */ 234 pj_dns_parsed_rr *ns; /**< Array of NS record in the answer. */ 235 pj_dns_parsed_rr *arr; /**< Array of additional RR answer. */ 236 } pj_dns_parsed_response; 237 238 239 /** 240 * Create DNS query packet to resolve the specified names. 287 typedef struct pj_dns_parsed_packet 288 { 289 pj_dns_hdr hdr; /**< Pointer to DNS hdr, in host byte order */ 290 pj_dns_parsed_query *q; /**< Array of DNS queries. */ 291 pj_dns_parsed_rr *ans; /**< Array of DNS RR answer. */ 292 pj_dns_parsed_rr *ns; /**< Array of NS record in the answer. */ 293 pj_dns_parsed_rr *arr; /**< Array of additional RR answer. */ 294 } pj_dns_parsed_packet; 295 296 297 /** 298 * Create DNS query packet to resolve the specified names. This function 299 * can be used to build any types of DNS query, such as A record or DNS SRV 300 * record. 301 * 302 * Application specifies the type of record and the name to be queried, 303 * and the function will build the DNS query packet into the buffer 304 * specified. Once the packet is successfully built, application can send 305 * the packet via TCP or UDP connection. 241 306 * 242 307 * @param packet The buffer to put the DNS query packet. … … 246 311 * @param id DNS query ID to associate DNS response with the 247 312 * query. 248 * @param qtype DNS type of record to be queried .313 * @param qtype DNS type of record to be queried (see #pj_dns_type). 249 314 * @param name Name to be queried from the DNS server. 250 315 * … … 254 319 unsigned *size, 255 320 pj_uint16_t id, 256 pj_dns_typeqtype,321 int qtype, 257 322 const pj_str_t *name); 258 323 259 324 /** 260 * Parse raw DNS response packet into DNS response structure. 261 * 262 * @param pool Pool to allocate memory for the parsed response. 263 * @param packet 264 * @param size 265 * @param p_res 325 * Parse raw DNS packet into parsed DNS packet structure. This function is 326 * able to parse few DNS resource records such as A record, PTR record, 327 * CNAME record, NS record, and SRV record. 328 * 329 * @param pool Pool to allocate memory for the parsed packet. 330 * @param packet Pointer to the DNS packet (the TCP/UDP payload of 331 * the raw packet). 332 * @param size The size of the DNS packet. 333 * @param p_res Pointer to store the resulting parsed packet. 266 334 * 267 335 * @return PJ_SUCCESS on success, or the appropriate error code. 268 336 */ 269 PJ_DECL(pj_status_t) pj_dns_parse_response(pj_pool_t *pool, 270 const void *packet, 271 unsigned size, 272 pj_dns_parsed_response **p_res); 273 274 /** 275 * Dump DNS response to standard log. 276 * 277 * @param res The DNS response. 278 */ 279 PJ_DECL(void) pj_dns_dump_response(const pj_dns_parsed_response *res); 337 PJ_DECL(pj_status_t) pj_dns_parse_packet(pj_pool_t *pool, 338 const void *packet, 339 unsigned size, 340 pj_dns_parsed_packet **p_res); 341 342 /** 343 * Duplicate DNS packet. 344 * 345 * @param pool The pool to allocate memory for the duplicated packet. 346 * @param p The DNS packet to be cloned. 347 * @p_dst Pointer to store the cloned DNS packet. 348 */ 349 PJ_DECL(void) pj_dns_packet_dup(pj_pool_t *pool, 350 const pj_dns_parsed_packet*p, 351 pj_dns_parsed_packet **p_dst); 352 353 354 /** 355 * Utility function to get the type name string of the specified DNS type. 356 * 357 * @param type DNS type (see #pj_dns_type). 358 * 359 * @return String name of the type (e.g. "A", "SRV", etc.). 360 */ 361 PJ_DECL(const char *) pj_dns_get_type_name(int type); 362 363 364 /** 365 * Dump DNS packet to standard log. 366 * 367 * @param res The DNS packet. 368 */ 369 PJ_DECL(void) pj_dns_dump_packet(const pj_dns_parsed_packet *res); 280 370 281 371
Note: See TracChangeset
for help on using the changeset viewer.