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

dns.h
Go to the documentation of this file.
1 /* $Id: dns.h 5350 2016-06-21 06:55:10Z riza $ */
2 /*
3  * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4  * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 #ifndef __PJLIB_UTIL_DNS_H__
21 #define __PJLIB_UTIL_DNS_H__
22 
23 
28 #include <pjlib-util/types.h>
29 #include <pj/sock.h>
30 
32 
63 enum
64 {
66 };
67 
72 typedef enum pj_dns_type
73 {
122 } pj_dns_type;
123 
124 
125 
134 typedef struct pj_dns_hdr
135 {
142 } pj_dns_hdr;
143 
145 #define PJ_DNS_SET_RCODE(c) ((pj_uint16_t)((c) & 0x0F))
146 
148 #define PJ_DNS_SET_RA(on) ((pj_uint16_t)((on) << 7))
149 
151 #define PJ_DNS_SET_RD(on) ((pj_uint16_t)((on) << 8))
152 
154 #define PJ_DNS_SET_TC(on) ((pj_uint16_t)((on) << 9))
155 
157 #define PJ_DNS_SET_AA(on) ((pj_uint16_t)((on) << 10))
158 
160 #define PJ_DNS_SET_OPCODE(o) ((pj_uint16_t)((o) << 11))
161 
163 #define PJ_DNS_SET_QR(on) ((pj_uint16_t)((on) << 15))
164 
165 
167 #define PJ_DNS_GET_RCODE(val) (((val) & PJ_DNS_SET_RCODE(0x0F)) >> 0)
168 
170 #define PJ_DNS_GET_RA(val) (((val) & PJ_DNS_SET_RA(1)) >> 7)
171 
173 #define PJ_DNS_GET_RD(val) (((val) & PJ_DNS_SET_RD(1)) >> 8)
174 
176 #define PJ_DNS_GET_TC(val) (((val) & PJ_DNS_SET_TC(1)) >> 9)
177 
179 #define PJ_DNS_GET_AA(val) (((val) & PJ_DNS_SET_AA(1)) >> 10)
180 
182 #define PJ_DNS_GET_OPCODE(val) (((val) & PJ_DNS_SET_OPCODE(0x0F)) >> 11)
183 
185 #define PJ_DNS_GET_QR(val) (((val) & PJ_DNS_SET_QR(1)) >> 15)
186 
187 
193 typedef enum pj_dns_rcode
194 {
206 } pj_dns_rcode;
207 
208 
212 typedef struct pj_dns_parsed_query
213 {
218 
219 
224 typedef struct pj_dns_parsed_rr
225 {
231  void *data;
238  union rdata
239  {
241  struct srv {
246  } srv;
247 
249  struct cname {
251  } cname;
252 
254  struct ns {
256  } ns;
257 
259  struct ptr {
261  } ptr;
262 
264  struct a {
266  } a;
267 
269  struct aaaa {
271  } aaaa;
272 
273  } rdata;
274 
276 
277 
283 typedef struct pj_dns_parsed_packet
284 {
291 
292 
298 {
303 };
304 
305 
327 PJ_DECL(pj_status_t) pj_dns_make_query(void *packet,
328  unsigned *size,
329  pj_uint16_t id,
330  int qtype,
331  const pj_str_t *name);
332 
347  const void *packet,
348  unsigned size,
349  pj_dns_parsed_packet **p_res);
350 
359 PJ_DECL(void) pj_dns_packet_dup(pj_pool_t *pool,
360  const pj_dns_parsed_packet*p,
361  unsigned options,
362  pj_dns_parsed_packet **p_dst);
363 
364 
372 PJ_DECL(const char *) pj_dns_get_type_name(int type);
373 
374 
388 PJ_DECL(void) pj_dns_init_srv_rr(pj_dns_parsed_rr *rec,
389  const pj_str_t *res_name,
390  unsigned dnsclass,
391  unsigned ttl,
392  unsigned prio,
393  unsigned weight,
394  unsigned port,
395  const pj_str_t *target);
396 
407 PJ_DECL(void) pj_dns_init_cname_rr(pj_dns_parsed_rr *rec,
408  const pj_str_t *res_name,
409  unsigned dnsclass,
410  unsigned ttl,
411  const pj_str_t *name);
412 
423 PJ_DECL(void) pj_dns_init_a_rr(pj_dns_parsed_rr *rec,
424  const pj_str_t *res_name,
425  unsigned dnsclass,
426  unsigned ttl,
427  const pj_in_addr *ip_addr);
428 
439 PJ_DECL(void) pj_dns_init_aaaa_rr(pj_dns_parsed_rr *rec,
440  const pj_str_t *res_name,
441  unsigned dnsclass,
442  unsigned ttl,
443  const pj_in6_addr *ip_addr);
444 
450 PJ_DECL(void) pj_dns_dump_packet(const pj_dns_parsed_packet *res);
451 
452 
457 PJ_END_DECL
458 
459 
460 #endif /* __PJLIB_UTIL_DNS_H__ */
461 
pj_uint32_t ttl
Definition: dns.h:229
Definition: dns.h:95
pj_dns_rcode
Definition: dns.h:193
Definition: dns.h:118
Definition: dns.h:197
Definition: dns.h:76
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)
Definition: dns.h:203
Definition: dns.h:196
pj_uint16_t rdlength
Definition: dns.h:230
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)
pj_uint16_t weight
Definition: dns.h:243
Definition: dns.h:224
Definition: dns.h:249
Definition: dns.h:198
pj_uint16_t anscount
Definition: dns.h:139
Definition: dns.h:102
Definition: dns.h:300
Definition: dns.h:77
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_uint16_t dnsclass
Definition: dns.h:216
Definition: dns.h:199
pj_uint16_t port
Definition: dns.h:244
Definition: dns.h:119
Definition: dns.h:78
Definition: dns.h:302
Definition: dns.h:92
Definition: dns.h:264
Definition: dns.h:116
Definition: dns.h:83
Definition: dns.h:80
void pj_dns_dump_packet(const pj_dns_parsed_packet *res)
pj_str_t name
Definition: dns.h:214
pj_str_t name
Definition: dns.h:260
Definition: dns.h:299
Definition: dns.h:96
pj_dns_parsed_query * q
Definition: dns.h:286
int pj_status_t
Definition: dns.h:120
Definition: dns.h:115
Definition: dns.h:84
Definition: dns.h:87
Definition: dns.h:114
Definition: dns.h:90
pj_dns_parsed_rr * ns
Definition: dns.h:288
Definition: dns.h:200
Definition: dns.h:108
Definition: dns.h:111
pj_uint16_t arcount
Definition: dns.h:141
Definition: dns.h:238
Definition: dns.h:134
Definition: dns.h:259
Definition: dns.h:204
Definition: dns.h:121
Definition: dns.h:254
Definition: dns.h:195
unsigned int pj_uint32_t
Definition: dns.h:110
Definition: dns.h:112
pj_uint16_t type
Definition: dns.h:227
Definition: dns.h:89
Definition: dns.h:88
pj_dns_hdr hdr
Definition: dns.h:285
Definition: dns.h:117
Definition: dns.h:79
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)
Definition: dns.h:85
pj_dns_parsed_rr * arr
Definition: dns.h:289
pj_in_addr ip_addr
Definition: dns.h:265
Definition: dns.h:98
Definition: dns.h:104
void * data
Definition: dns.h:231
pj_status_t pj_dns_parse_packet(pj_pool_t *pool, const void *packet, unsigned size, pj_dns_parsed_packet **p_res)
Definition: dns.h:99
Definition: dns.h:97
Definition: dns.h:109
#define PJ_BEGIN_DECL
pj_uint16_t qdcount
Definition: dns.h:138
pj_uint16_t prio
Definition: dns.h:242
Definition: dns.h:65
Definition: dns.h:283
Definition: dns.h:269
Definition: dns.h:82
Definition: dns.h:301
pj_in6_addr ip_addr
Definition: dns.h:270
const char * pj_dns_get_type_name(int type)
pj_str_t name
Definition: dns.h:255
void pj_dns_packet_dup(pj_pool_t *pool, const pj_dns_parsed_packet *p, unsigned options, pj_dns_parsed_packet **p_dst)
Definition: dns.h:103
pj_uint16_t flags
Definition: dns.h:137
pj_uint16_t dnsclass
Definition: dns.h:228
pj_uint16_t id
Definition: dns.h:136
Definition: dns.h:105
Definition: dns.h:91
Definition: dns.h:106
Definition: dns.h:107
Definition: dns.h:201
Definition: dns.h:202
pj_str_t target
Definition: dns.h:245
Definition: dns.h:94
pj_str_t name
Definition: dns.h:250
pj_uint16_t type
Definition: dns.h:215
pj_dns_parsed_rr * ans
Definition: dns.h:287
pj_str_t name
Definition: dns.h:226
pj_uint16_t nscount
Definition: dns.h:140
Definition: dns.h:93
Definition: dns.h:212
pj_status_t pj_dns_make_query(void *packet, unsigned *size, pj_uint16_t id, int qtype, const pj_str_t *name)
Definition: dns.h:75
Definition: dns.h:86
pj_dns_type
Definition: dns.h:72
Definition: dns.h:101
unsigned short pj_uint16_t
Definition: dns.h:241
pj_dns_dup_options
Definition: dns.h:297
Definition: dns.h:100
Definition: dns.h:81
Definition: dns.h:74

 


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.