From da8bbc0ad0fae2460176e0d77786b30ad1eb959c Mon Sep 17 00:00:00 2001 From: Scott MacVicar Date: Thu, 6 Aug 2009 04:37:07 +0000 Subject: [PATCH] Deal with moving to res_nsearch(). dns_search() on OSX lacks an error handler, might revert to using straight bind9. --- ext/standard/dns.c | 52 +++++++++++++++++++++++------------------- ext/standard/php_dns.h | 12 ++++++++-- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/ext/standard/dns.c b/ext/standard/dns.c index 64f5e466be..08d2ae7970 100644 --- a/ext/standard/dns.c +++ b/ext/standard/dns.c @@ -809,10 +809,14 @@ PHP_FUNCTION(dns_get_record) n = php_dns_search(handle, hostname, C_IN, type_to_fetch, answer.qb2, sizeof answer); - if (n < 0 ) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "res_nsearch() failed"); - zval_dtor(return_value); + if (n < 0) { + if (php_dns_errno(handle) == NO_DATA) { + php_dns_free_handle(handle); + continue; + } + php_dns_free_handle(handle); + zval_dtor(return_value); RETURN_FALSE; } @@ -845,33 +849,33 @@ PHP_FUNCTION(dns_get_record) add_next_index_zval(return_value, retval); } } - php_dns_free_handle(handle); - } - } - if (authns || addtl) { - /* List of Authoritative Name Servers - * Process when only requesting addtl so that we can skip through the section - */ - while (ns-- > 0 && cp && cp < end) { - zval *retval = NULL; + if (authns || addtl) { + /* List of Authoritative Name Servers + * Process when only requesting addtl so that we can skip through the section + */ + while (ns-- > 0 && cp && cp < end) { + zval *retval = NULL; - cp = php_parserr(cp, &answer, DNS_T_ANY, authns != NULL, &retval TSRMLS_CC); - if (retval != NULL) { - add_next_index_zval(authns, retval); + cp = php_parserr(cp, &answer, DNS_T_ANY, authns != NULL, &retval TSRMLS_CC); + if (retval != NULL) { + add_next_index_zval(authns, retval); + } + } } - } - } - if (addtl) { - /* Additional records associated with authoritative name servers */ - while (ar-- > 0 && cp && cp < end) { - zval *retval = NULL; + if (addtl) { + /* Additional records associated with authoritative name servers */ + while (ar-- > 0 && cp && cp < end) { + zval *retval = NULL; - cp = php_parserr(cp, &answer, DNS_T_ANY, 1, &retval TSRMLS_CC); - if (retval != NULL) { - add_next_index_zval(addtl, retval); + cp = php_parserr(cp, &answer, DNS_T_ANY, 1, &retval TSRMLS_CC); + if (retval != NULL) { + add_next_index_zval(addtl, retval); + } + } } + php_dns_free_handle(handle); } } } diff --git a/ext/standard/php_dns.h b/ext/standard/php_dns.h index c9a057aace..7e80004071 100644 --- a/ext/standard/php_dns.h +++ b/ext/standard/php_dns.h @@ -28,17 +28,25 @@ ((int)dns_search(res, dname, class, type, answer, anslen, (struct sockaddr *)&from, &fromsize)) #define php_dns_free_handle(res) \ dns_free(res) +#define php_dns_errno(_res) \ + (NO_DATA) #elif defined(HAVE_RES_NSEARCH) #define php_dns_search(res, dname, class, type, answer, anslen) \ res_nsearch(res, dname, class, type, answer, anslen) -#define php_dns_free_handle(res) \ - res_nclose(res) +#define php_dns_free_handle(res) \ + res_nclose(res); \ + php_dns_free_res(*res) + +#define php_dns_errno(res) \ + (res->res_h_errno) #elif defined(HAVE_RES_SEARCH) #define php_dns_search(res, dname, class, type, answer, anslen) \ res_search(dname, class, type, answer, anslen) #define php_dns_free_handle(res) /* noop */ +#define php_dns_errno(res) \ + (_res.res_h_errno) #endif -- 2.50.1