summaryrefslogtreecommitdiff
path: root/pjlib-util/include
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2007-06-11 16:47:51 +0000
committerBenny Prijono <bennylp@teluu.com>2007-06-11 16:47:51 +0000
commit7ea58155c60008e40e21b47ae3ecdaeb6dba5c94 (patch)
tree8aa450d210709d060200c7be8168c8522ac13906 /pjlib-util/include
parentea2900cb9edc4f75c2b01a55196cf4e1e440de7a (diff)
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
Diffstat (limited to 'pjlib-util/include')
-rw-r--r--pjlib-util/include/pjlib-util/errno.h7
-rw-r--r--pjlib-util/include/pjlib-util/resolver.h40
2 files changed, 47 insertions, 0 deletions
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