From 7ea58155c60008e40e21b47ae3ecdaeb6dba5c94 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Mon, 11 Jun 2007 16:47:51 +0000 Subject: Ticket #329: Added utility function to parse DNS A response in PJLIB-UTIL git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1356 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib-util/include/pjlib-util/errno.h | 7 ++++++ pjlib-util/include/pjlib-util/resolver.h | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) (limited to 'pjlib-util/include') diff --git a/pjlib-util/include/pjlib-util/errno.h b/pjlib-util/include/pjlib-util/errno.h index bff14194..8db99f6a 100644 --- a/pjlib-util/include/pjlib-util/errno.h +++ b/pjlib-util/include/pjlib-util/errno.h @@ -174,6 +174,13 @@ * No answer record in the DNS response. */ #define PJLIB_UTIL_EDNSNOANSWERREC (PJLIB_UTIL_ERRNO_START+47) /* 320047 */ +/** + * @hideinitializer + * Invalid DNS answer. This error is raised for example when the DNS + * answer does not have a query section, or the type of RR in the answer + * doesn't match the query. + */ +#define PJLIB_UTIL_EDNSINANSWER (PJLIB_UTIL_ERRNO_START+48) /* 320048 */ /* DNS ERRORS MAPPED FROM RCODE: */ diff --git a/pjlib-util/include/pjlib-util/resolver.h b/pjlib-util/include/pjlib-util/resolver.h index f7fd9ede..2d33aa3b 100644 --- a/pjlib-util/include/pjlib-util/resolver.h +++ b/pjlib-util/include/pjlib-util/resolver.h @@ -197,6 +197,33 @@ typedef struct pj_dns_settings unsigned bad_ns_ttl; /**< See #PJ_DNS_RESOLVER_BAD_NS_TTL */ } pj_dns_settings; + +/** + * This structure represents DNS A record, as the result of parsing + * DNS response packet using #pj_dns_parse_a_response(). + */ +typedef struct pj_dns_a_record +{ + /** The target name being queried. */ + pj_str_t name; + + /** If target name corresponds to a CNAME entry, the alias contains + * the value of the CNAME entry, otherwise it will be empty. + */ + pj_str_t alias; + + /** Number of IP addresses. */ + unsigned addr_count; + + /** IP addresses of the host found in the response */ + pj_in_addr addr[PJ_DNS_MAX_IP_IN_A_REC]; + + /** Internal buffer for hostname and alias. */ + char buf_[128]; + +} pj_dns_a_record; + + /** * Set default values to the DNS settings. * @@ -365,6 +392,19 @@ PJ_DECL(pj_status_t) pj_dns_resolver_start_query(pj_dns_resolver *resolver, PJ_DECL(pj_status_t) pj_dns_resolver_cancel_query(pj_dns_async_query *query, pj_bool_t notify); +/** + * A utility function to parse a DNS response containing A records into + * DNS A record. + * + * @param pkt The DNS response packet. + * @param rec The structure to be initialized with the parsed + * DNS A record from the packet. + * + * @return PJ_SUCCESS if response can be parsed successfully. + */ +PJ_DECL(pj_status_t) pj_dns_parse_a_response(const pj_dns_parsed_packet *pkt, + pj_dns_a_record *rec); + /** * Put the specified DNS packet into DNS cache. This function is mainly used -- cgit v1.2.3