BLOG | DOCUMENTATION | GITHUB

Home --> Documentations --> PJLIB-UTIL Reference

dns.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#ifndef __PJLIB_UTIL_DNS_H__
20#define __PJLIB_UTIL_DNS_H__
21
22
27#include <pjlib-util/types.h>
28#include <pj/sock.h>
29
31
62enum
63{
65};
66
71typedef enum pj_dns_type
72{
122
123
124
133typedef struct pj_dns_hdr
134{
141} pj_dns_hdr;
142
144#define PJ_DNS_SET_RCODE(c) ((pj_uint16_t)((c) & 0x0F))
145
147#define PJ_DNS_SET_RA(on) ((pj_uint16_t)((on) << 7))
148
150#define PJ_DNS_SET_RD(on) ((pj_uint16_t)((on) << 8))
151
153#define PJ_DNS_SET_TC(on) ((pj_uint16_t)((on) << 9))
154
156#define PJ_DNS_SET_AA(on) ((pj_uint16_t)((on) << 10))
157
159#define PJ_DNS_SET_OPCODE(o) ((pj_uint16_t)((o) << 11))
160
162#define PJ_DNS_SET_QR(on) ((pj_uint16_t)((on) << 15))
163
164
166#define PJ_DNS_GET_RCODE(val) (((val) & PJ_DNS_SET_RCODE(0x0F)) >> 0)
167
169#define PJ_DNS_GET_RA(val) (((val) & PJ_DNS_SET_RA(1)) >> 7)
170
172#define PJ_DNS_GET_RD(val) (((val) & PJ_DNS_SET_RD(1)) >> 8)
173
175#define PJ_DNS_GET_TC(val) (((val) & PJ_DNS_SET_TC(1)) >> 9)
176
178#define PJ_DNS_GET_AA(val) (((val) & PJ_DNS_SET_AA(1)) >> 10)
179
181#define PJ_DNS_GET_OPCODE(val) (((val) & PJ_DNS_SET_OPCODE(0x0F)) >> 11)
182
184#define PJ_DNS_GET_QR(val) (((val) & PJ_DNS_SET_QR(1)) >> 15)
185
186
192typedef enum pj_dns_rcode
193{
206
207
212{
217
218
223typedef struct pj_dns_parsed_rr
224{
230 void *data;
237 union rdata
238 {
240 struct srv {
245 } srv;
248 struct cname {
253 struct ns {
255 } ns;
258 struct ptr {
260 } ptr;
263 struct a {
265 } a;
268 struct aaaa {
272 } rdata;
273
275
276
283{
290
291
297{
301 PJ_DNS_NO_AR = 8
303
304
326PJ_DECL(pj_status_t) pj_dns_make_query(void *packet,
327 unsigned *size,
328 pj_uint16_t id,
329 int qtype,
330 const pj_str_t *name);
331
346 const void *packet,
347 unsigned size,
348 pj_dns_parsed_packet **p_res);
349
358PJ_DECL(void) pj_dns_packet_dup(pj_pool_t *pool,
359 const pj_dns_parsed_packet*p,
360 unsigned options,
361 pj_dns_parsed_packet **p_dst);
362
363
371PJ_DECL(const char *) pj_dns_get_type_name(int type);
372
373
388 const pj_str_t *res_name,
389 unsigned dnsclass,
390 unsigned ttl,
391 unsigned prio,
392 unsigned weight,
393 unsigned port,
394 const pj_str_t *target);
395
407 const pj_str_t *res_name,
408 unsigned dnsclass,
409 unsigned ttl,
410 const pj_str_t *name);
411
423 const pj_str_t *res_name,
424 unsigned dnsclass,
425 unsigned ttl,
426 const pj_in_addr *ip_addr);
427
439 const pj_str_t *res_name,
440 unsigned dnsclass,
441 unsigned ttl,
442 const pj_in6_addr *ip_addr);
443
449PJ_DECL(void) pj_dns_dump_packet(const pj_dns_parsed_packet *res);
450
451
457
458
459#endif /* __PJLIB_UTIL_DNS_H__ */
460
unsigned short pj_uint16_t
int pj_status_t
unsigned int pj_uint32_t
pj_status_t pj_dns_make_query(void *packet, unsigned *size, pj_uint16_t id, int qtype, const pj_str_t *name)
void pj_dns_init_a_rr(pj_dns_parsed_rr *rec, const pj_str_t *res_name, unsigned dnsclass, unsigned ttl, const pj_in_addr *ip_addr)
pj_dns_rcode
Definition: dns.h:193
pj_dns_type
Definition: dns.h:72
void pj_dns_init_aaaa_rr(pj_dns_parsed_rr *rec, const pj_str_t *res_name, unsigned dnsclass, unsigned ttl, const pj_in6_addr *ip_addr)
void pj_dns_init_srv_rr(pj_dns_parsed_rr *rec, const pj_str_t *res_name, unsigned dnsclass, unsigned ttl, unsigned prio, unsigned weight, unsigned port, const pj_str_t *target)
void pj_dns_init_cname_rr(pj_dns_parsed_rr *rec, const pj_str_t *res_name, unsigned dnsclass, unsigned ttl, const pj_str_t *name)
const char * pj_dns_get_type_name(int type)
pj_dns_dup_options
Definition: dns.h:297
void pj_dns_dump_packet(const pj_dns_parsed_packet *res)
void pj_dns_packet_dup(pj_pool_t *pool, const pj_dns_parsed_packet *p, unsigned options, pj_dns_parsed_packet **p_dst)
pj_status_t pj_dns_parse_packet(pj_pool_t *pool, const void *packet, unsigned size, pj_dns_parsed_packet **p_res)
@ PJ_DNS_CLASS_IN
Definition: dns.h:64
@ PJ_DNS_RCODE_YXRRSET
Definition: dns.h:200
@ PJ_DNS_RCODE_NOTZONE
Definition: dns.h:203
@ PJ_DNS_RCODE_REFUSED
Definition: dns.h:198
@ PJ_DNS_RCODE_NXDOMAIN
Definition: dns.h:196
@ PJ_DNS_RCODE_SERVFAIL
Definition: dns.h:195
@ PJ_DNS_RCODE_NOTIMPL
Definition: dns.h:197
@ PJ_DNS_RCODE_NXRRSET
Definition: dns.h:201
@ PJ_DNS_RCODE_YXDOMAIN
Definition: dns.h:199
@ PJ_DNS_RCODE_FORMERR
Definition: dns.h:194
@ PJ_DNS_RCODE_NOTAUTH
Definition: dns.h:202
@ PJ_DNS_TYPE_DNSKEY
Definition: dns.h:120
@ PJ_DNS_TYPE_PX
Definition: dns.h:98
@ PJ_DNS_TYPE_SIG
Definition: dns.h:96
@ PJ_DNS_TYPE_SSHFP
Definition: dns.h:116
@ PJ_DNS_TYPE_WKS
Definition: dns.h:83
@ PJ_DNS_TYPE_MINFO
Definition: dns.h:86
@ PJ_DNS_TYPE_IPSECKEY
Definition: dns.h:117
@ PJ_DNS_TYPE_RT
Definition: dns.h:93
@ PJ_DNS_TYPE_KEY
Definition: dns.h:97
@ PJ_DNS_TYPE_LOC
Definition: dns.h:101
@ PJ_DNS_TYPE_A
Definition: dns.h:73
@ PJ_DNS_TYPE_PTR
Definition: dns.h:84
@ PJ_DNS_TYPE_GPOS
Definition: dns.h:99
@ PJ_DNS_TYPE_SOA
Definition: dns.h:78
@ PJ_DNS_TYPE_RRSIG
Definition: dns.h:118
@ PJ_DNS_TYPE_ISDN
Definition: dns.h:92
@ PJ_DNS_TYPE_DNAME
Definition: dns.h:111
@ PJ_DNS_TYPE_MB
Definition: dns.h:79
@ PJ_DNS_TYPE_CERT
Definition: dns.h:109
@ PJ_DNS_TYPE_SRV
Definition: dns.h:105
@ PJ_DNS_TYPE_AFSB
Definition: dns.h:90
@ PJ_DNS_TYPE_MF
Definition: dns.h:76
@ PJ_DNS_TYPE_X25
Definition: dns.h:91
@ PJ_DNS_TYPE_OPT
Definition: dns.h:113
@ PJ_DNS_TYPE_AAAA
Definition: dns.h:100
@ PJ_DNS_TYPE_APL
Definition: dns.h:114
@ PJ_DNS_TYPE_NULL
Definition: dns.h:82
@ PJ_DNS_TYPE_NIMLOC
Definition: dns.h:104
@ PJ_DNS_TYPE_NAPTR
Definition: dns.h:107
@ PJ_DNS_TYPE_CNAME
Definition: dns.h:77
@ PJ_DNS_TYPE_EID
Definition: dns.h:103
@ PJ_DNS_TYPE_ATMA
Definition: dns.h:106
@ PJ_DNS_TYPE_MX
Definition: dns.h:87
@ PJ_DNS_TYPE_MG
Definition: dns.h:80
@ PJ_DNS_TYPE_KX
Definition: dns.h:108
@ PJ_DNS_TYPE_A6
Definition: dns.h:110
@ PJ_DNS_TYPE_RP
Definition: dns.h:89
@ PJ_DNS_TYPE_DS
Definition: dns.h:115
@ PJ_DNS_TYPE_NS
Definition: dns.h:74
@ PJ_DNS_TYPE_HINFO
Definition: dns.h:85
@ PJ_DNS_TYPE_NSEC
Definition: dns.h:119
@ PJ_DNS_TYPE_TXT
Definition: dns.h:88
@ PJ_DNS_TYPE_NSAP_PTR
Definition: dns.h:95
@ PJ_DNS_TYPE_MD
Definition: dns.h:75
@ PJ_DNS_TYPE_NSAP
Definition: dns.h:94
@ PJ_DNS_TYPE_NXT
Definition: dns.h:102
@ PJ_DNS_TYPE_MR
Definition: dns.h:81
@ PJ_DNS_NO_NS
Definition: dns.h:300
@ PJ_DNS_NO_ANS
Definition: dns.h:299
@ PJ_DNS_NO_AR
Definition: dns.h:301
@ PJ_DNS_NO_QD
Definition: dns.h:298
struct in_addr pj_in_addr
struct in6_addr pj_in6_addr
#define PJ_BEGIN_DECL
#define PJ_END_DECL
Definition: dns.h:134
pj_uint16_t nscount
Definition: dns.h:139
pj_uint16_t id
Definition: dns.h:135
pj_uint16_t qdcount
Definition: dns.h:137
pj_uint16_t flags
Definition: dns.h:136
pj_uint16_t arcount
Definition: dns.h:140
pj_uint16_t anscount
Definition: dns.h:138
Definition: dns.h:283
pj_dns_parsed_query * q
Definition: dns.h:285
pj_dns_hdr hdr
Definition: dns.h:284
pj_dns_parsed_rr * ns
Definition: dns.h:287
pj_dns_parsed_rr * ans
Definition: dns.h:286
pj_dns_parsed_rr * arr
Definition: dns.h:288
Definition: dns.h:212
pj_uint16_t dnsclass
Definition: dns.h:215
pj_str_t name
Definition: dns.h:213
pj_uint16_t type
Definition: dns.h:214
Definition: dns.h:263
pj_in_addr ip_addr
Definition: dns.h:264
Definition: dns.h:268
pj_in6_addr ip_addr
Definition: dns.h:269
Definition: dns.h:248
pj_str_t name
Definition: dns.h:249
Definition: dns.h:253
pj_str_t name
Definition: dns.h:254
Definition: dns.h:258
pj_str_t name
Definition: dns.h:259
Definition: dns.h:240
pj_uint16_t port
Definition: dns.h:243
pj_uint16_t prio
Definition: dns.h:241
pj_uint16_t weight
Definition: dns.h:242
pj_str_t target
Definition: dns.h:244
Definition: dns.h:224
pj_uint16_t type
Definition: dns.h:226
pj_uint16_t rdlength
Definition: dns.h:229
pj_uint16_t dnsclass
Definition: dns.h:227
void * data
Definition: dns.h:230
pj_str_t name
Definition: dns.h:225
pj_uint32_t ttl
Definition: dns.h:228
PJLIB-UTIL types.
Definition: dns.h:238
struct pj_dns_parsed_rr::rdata::aaaa aaaa
struct pj_dns_parsed_rr::rdata::cname cname
struct pj_dns_parsed_rr::rdata::ptr ptr
struct pj_dns_parsed_rr::rdata::a a
struct pj_dns_parsed_rr::rdata::srv srv
struct pj_dns_parsed_rr::rdata::ns ns

 


PJLIB-UTIL Open Source, small footprint, and portable asynchronous/caching DNS resolver, text scanner, STUN client, and XML library
Copyright (C) 2006-2009 Teluu Inc.