PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/standard - dns.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 105 504 20.8 %
Date: 2015-04-14 Functions: 9 12 75.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2015 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: The typical suspects                                        |
      16             :    |          Pollita <pollita@php.net>                                   |
      17             :    |          Marcus Boerger <helly@php.net>                              |
      18             :    +----------------------------------------------------------------------+
      19             :  */
      20             : 
      21             : /* $Id$ */
      22             : 
      23             : /* {{{ includes */
      24             : #include "php.h"
      25             : #include "php_network.h"
      26             : 
      27             : #if HAVE_SYS_SOCKET_H
      28             : #include <sys/socket.h>
      29             : #endif
      30             : 
      31             : #ifdef PHP_WIN32
      32             : # include "win32/inet.h"
      33             : # include <winsock2.h>
      34             : # include <windows.h>
      35             : # include <Ws2tcpip.h>
      36             : #else   /* This holds good for NetWare too, both for Winsock and Berkeley sockets */
      37             : #include <netinet/in.h>
      38             : #if HAVE_ARPA_INET_H
      39             : #include <arpa/inet.h>
      40             : #endif
      41             : #include <netdb.h>
      42             : #ifdef _OSD_POSIX
      43             : #undef STATUS
      44             : #undef T_UNSPEC
      45             : #endif
      46             : #if HAVE_ARPA_NAMESER_H
      47             : #ifdef DARWIN
      48             : # define BIND_8_COMPAT 1
      49             : #endif
      50             : #include <arpa/nameser.h>
      51             : #endif
      52             : #if HAVE_RESOLV_H
      53             : #include <resolv.h>
      54             : #endif
      55             : #ifdef HAVE_DNS_H
      56             : #include <dns.h>
      57             : #endif
      58             : #endif
      59             : 
      60             : /* Borrowed from SYS/SOCKET.H */
      61             : #if defined(NETWARE) && defined(USE_WINSOCK)
      62             : #define AF_INET 2   /* internetwork: UDP, TCP, etc. */
      63             : #endif
      64             : 
      65             : #ifndef MAXHOSTNAMELEN
      66             : #define MAXHOSTNAMELEN 255
      67             : #endif
      68             : 
      69             : /* For the local hostname obtained via gethostname which is different from the
      70             :    dns-related MAXHOSTNAMELEN constant above */
      71             : #ifndef HOST_NAME_MAX
      72             : #define HOST_NAME_MAX 255
      73             : #endif
      74             : 
      75             : #include "php_dns.h"
      76             : 
      77             : /* type compat */
      78             : #ifndef DNS_T_A
      79             : #define DNS_T_A         1
      80             : #endif
      81             : #ifndef DNS_T_NS
      82             : #define DNS_T_NS        2
      83             : #endif
      84             : #ifndef DNS_T_CNAME
      85             : #define DNS_T_CNAME     5
      86             : #endif
      87             : #ifndef DNS_T_SOA
      88             : #define DNS_T_SOA       6
      89             : #endif
      90             : #ifndef DNS_T_PTR
      91             : #define DNS_T_PTR       12
      92             : #endif
      93             : #ifndef DNS_T_HINFO
      94             : #define DNS_T_HINFO     13
      95             : #endif
      96             : #ifndef DNS_T_MINFO
      97             : #define DNS_T_MINFO     14
      98             : #endif
      99             : #ifndef DNS_T_MX
     100             : #define DNS_T_MX        15
     101             : #endif
     102             : #ifndef DNS_T_TXT
     103             : #define DNS_T_TXT       16
     104             : #endif
     105             : #ifndef DNS_T_AAAA
     106             : #define DNS_T_AAAA      28
     107             : #endif
     108             : #ifndef DNS_T_SRV
     109             : #define DNS_T_SRV       33
     110             : #endif
     111             : #ifndef DNS_T_NAPTR
     112             : #define DNS_T_NAPTR     35
     113             : #endif
     114             : #ifndef DNS_T_A6
     115             : #define DNS_T_A6        38
     116             : #endif
     117             : 
     118             : #ifndef DNS_T_ANY
     119             : #define DNS_T_ANY       255
     120             : #endif
     121             : /* }}} */
     122             : 
     123             : static zend_string *php_gethostbyaddr(char *ip);
     124             : static zend_string *php_gethostbyname(char *name);
     125             : 
     126             : #ifdef HAVE_GETHOSTNAME
     127             : /* {{{ proto string gethostname()
     128             :    Get the host name of the current machine */
     129           0 : PHP_FUNCTION(gethostname)
     130             : {
     131             :         char buf[HOST_NAME_MAX];
     132             : 
     133           0 :         if (zend_parse_parameters_none() == FAILURE) {
     134           0 :                 return;
     135             :         }
     136             : 
     137           0 :         if (gethostname(buf, sizeof(buf) - 1)) {
     138           0 :                 php_error_docref(NULL, E_WARNING, "unable to fetch host [%d]: %s", errno, strerror(errno));
     139           0 :                 RETURN_FALSE;
     140             :         }
     141             : 
     142           0 :         RETURN_STRING(buf);
     143             : }
     144             : /* }}} */
     145             : #endif
     146             : 
     147             : /* TODO: Reimplement the gethostby* functions using the new winxp+ API, in dns_win32.c, then
     148             :  we can have a dns.c, dns_unix.c and dns_win32.c instead of a messy dns.c full of #ifdef
     149             : */
     150             : 
     151             : /* {{{ proto string gethostbyaddr(string ip_address)
     152             :    Get the Internet host name corresponding to a given IP address */
     153           6 : PHP_FUNCTION(gethostbyaddr)
     154             : {
     155             :         char *addr;
     156             :         size_t addr_len;
     157             :         zend_string *hostname;
     158             : 
     159           6 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &addr, &addr_len) == FAILURE) {
     160           2 :                 return;
     161             :         }
     162             : 
     163           4 :         hostname = php_gethostbyaddr(addr);
     164             : 
     165           4 :         if (hostname == NULL) {
     166             : #if HAVE_IPV6 && HAVE_INET_PTON
     167           3 :                 php_error_docref(NULL, E_WARNING, "Address is not a valid IPv4 or IPv6 address");
     168             : #else
     169             :                 php_error_docref(NULL, E_WARNING, "Address is not in a.b.c.d form");
     170             : #endif
     171           3 :                 RETVAL_FALSE;
     172             :         } else {
     173           1 :                 RETVAL_STR(hostname);
     174             :         }
     175             : }
     176             : /* }}} */
     177             : 
     178             : /* {{{ php_gethostbyaddr */
     179           4 : static zend_string *php_gethostbyaddr(char *ip)
     180             : {
     181             : #if HAVE_IPV6 && HAVE_INET_PTON
     182             :         struct in6_addr addr6;
     183             : #endif
     184             :         struct in_addr addr;
     185             :         struct hostent *hp;
     186             : 
     187             : #if HAVE_IPV6 && HAVE_INET_PTON
     188           4 :         if (inet_pton(AF_INET6, ip, &addr6)) {
     189           0 :                 hp = gethostbyaddr((char *) &addr6, sizeof(addr6), AF_INET6);
     190           4 :         } else if (inet_pton(AF_INET, ip, &addr)) {
     191           1 :                 hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET);
     192             :         } else {
     193           3 :                 return NULL;
     194             :         }
     195             : #else
     196             :         addr.s_addr = inet_addr(ip);
     197             : 
     198             :         if (addr.s_addr == -1) {
     199             :                 return NULL;
     200             :         }
     201             : 
     202             :         hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET);
     203             : #endif
     204             : 
     205           1 :         if (!hp || hp->h_name == NULL || hp->h_name[0] == '\0') {
     206           0 :                 return zend_string_init(ip, strlen(ip), 0);
     207             :         }
     208             : 
     209           2 :         return zend_string_init(hp->h_name, strlen(hp->h_name), 0);
     210             : }
     211             : /* }}} */
     212             : 
     213             : /* {{{ proto string gethostbyname(string hostname)
     214             :    Get the IP address corresponding to a given Internet host name */
     215          13 : PHP_FUNCTION(gethostbyname)
     216             : {
     217             :         char *hostname;
     218             :         size_t hostname_len;
     219             : 
     220          13 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &hostname, &hostname_len) == FAILURE) {
     221           1 :                 return;
     222             :         }
     223             : 
     224          12 :         if(hostname_len > MAXFQDNLEN) {
     225             :                 /* name too long, protect from CVE-2015-0235 */
     226           1 :                 php_error_docref(NULL, E_WARNING, "Host name is too long, the limit is %d characters", MAXFQDNLEN);
     227           2 :                 RETURN_STRINGL(hostname, hostname_len);
     228             :         }
     229             : 
     230          11 :         RETURN_STR(php_gethostbyname(hostname));
     231             : }
     232             : /* }}} */
     233             : 
     234             : /* {{{ proto array gethostbynamel(string hostname)
     235             :    Return a list of IP addresses that a given hostname resolves to. */
     236           4 : PHP_FUNCTION(gethostbynamel)
     237             : {
     238             :         char *hostname;
     239             :         size_t hostname_len;
     240             :         struct hostent *hp;
     241             :         struct in_addr in;
     242             :         int i;
     243             : 
     244           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &hostname, &hostname_len) == FAILURE) {
     245           2 :                 return;
     246             :         }
     247             : 
     248           2 :         if(hostname_len > MAXFQDNLEN) {
     249             :                 /* name too long, protect from CVE-2015-0235 */
     250           1 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Host name is too long, the limit is %d characters", MAXFQDNLEN);
     251           1 :                 RETURN_FALSE;
     252             :         }
     253             : 
     254           1 :         hp = gethostbyname(hostname);
     255           1 :         if (hp == NULL || hp->h_addr_list == NULL) {
     256           0 :                 RETURN_FALSE;
     257             :         }
     258             : 
     259           1 :         array_init(return_value);
     260             : 
     261           3 :         for (i = 0 ; hp->h_addr_list[i] != 0 ; i++) {
     262           2 :                 in = *(struct in_addr *) hp->h_addr_list[i];
     263           2 :                 add_next_index_string(return_value, inet_ntoa(in));
     264             :         }
     265             : }
     266             : /* }}} */
     267             : 
     268             : /* {{{ php_gethostbyname */
     269          11 : static zend_string *php_gethostbyname(char *name)
     270             : {
     271             :         struct hostent *hp;
     272             :         struct in_addr in;
     273             :         char *address;
     274             : 
     275          11 :         hp = gethostbyname(name);
     276             : 
     277          11 :         if (!hp || !*(hp->h_addr_list)) {
     278          10 :                 return zend_string_init(name, strlen(name), 0);
     279             :         }
     280             : 
     281           6 :         memcpy(&in.s_addr, *(hp->h_addr_list), sizeof(in.s_addr));
     282             : 
     283           6 :         address = inet_ntoa(in);
     284          12 :         return zend_string_init(address, strlen(address), 0);
     285             : }
     286             : /* }}} */
     287             : 
     288             : #if HAVE_FULL_DNS_FUNCS || defined(PHP_WIN32)
     289             : # define PHP_DNS_NUM_TYPES      12      /* Number of DNS Types Supported by PHP currently */
     290             : 
     291             : # define PHP_DNS_A      0x00000001
     292             : # define PHP_DNS_NS     0x00000002
     293             : # define PHP_DNS_CNAME  0x00000010
     294             : # define PHP_DNS_SOA    0x00000020
     295             : # define PHP_DNS_PTR    0x00000800
     296             : # define PHP_DNS_HINFO  0x00001000
     297             : # define PHP_DNS_MX     0x00004000
     298             : # define PHP_DNS_TXT    0x00008000
     299             : # define PHP_DNS_A6     0x01000000
     300             : # define PHP_DNS_SRV    0x02000000
     301             : # define PHP_DNS_NAPTR  0x04000000
     302             : # define PHP_DNS_AAAA   0x08000000
     303             : # define PHP_DNS_ANY    0x10000000
     304             : # define PHP_DNS_ALL    (PHP_DNS_A|PHP_DNS_NS|PHP_DNS_CNAME|PHP_DNS_SOA|PHP_DNS_PTR|PHP_DNS_HINFO|PHP_DNS_MX|PHP_DNS_TXT|PHP_DNS_A6|PHP_DNS_SRV|PHP_DNS_NAPTR|PHP_DNS_AAAA)
     305             : #endif /* HAVE_FULL_DNS_FUNCS || defined(PHP_WIN32) */
     306             : 
     307             : /* Note: These functions are defined in ext/standard/dns_win32.c for Windows! */
     308             : #if !defined(PHP_WIN32) && (HAVE_DNS_SEARCH_FUNC && !(defined(__BEOS__) || defined(NETWARE)))
     309             : 
     310             : #ifndef HFIXEDSZ
     311             : #define HFIXEDSZ        12      /* fixed data in header <arpa/nameser.h> */
     312             : #endif /* HFIXEDSZ */
     313             : 
     314             : #ifndef QFIXEDSZ
     315             : #define QFIXEDSZ        4       /* fixed data in query <arpa/nameser.h> */
     316             : #endif /* QFIXEDSZ */
     317             : 
     318             : #undef MAXHOSTNAMELEN
     319             : #define MAXHOSTNAMELEN  1024
     320             : 
     321             : #ifndef MAXRESOURCERECORDS
     322             : #define MAXRESOURCERECORDS      64
     323             : #endif /* MAXRESOURCERECORDS */
     324             : 
     325             : typedef union {
     326             :         HEADER qb1;
     327             :         u_char qb2[65536];
     328             : } querybuf;
     329             : 
     330             : /* just a hack to free resources allocated by glibc in __res_nsend()
     331             :  * See also:
     332             :  *   res_thread_freeres() in glibc/resolv/res_init.c
     333             :  *   __libc_res_nsend()   in resolv/res_send.c
     334             :  * */
     335             : 
     336             : #if defined(__GLIBC__) && !defined(HAVE_DEPRECATED_DNS_FUNCS)
     337             : #define php_dns_free_res(__res__) _php_dns_free_res(__res__)
     338           2 : static void _php_dns_free_res(struct __res_state *res) { /* {{{ */
     339             :         int ns;
     340           8 :         for (ns = 0; ns < MAXNS; ns++) {
     341           6 :                 if (res->_u._ext.nsaddrs[ns] != NULL) {
     342           0 :                         free (res->_u._ext.nsaddrs[ns]);
     343           0 :                         res->_u._ext.nsaddrs[ns] = NULL;
     344             :                 }
     345             :         }
     346           2 : } /* }}} */
     347             : #else
     348             : #define php_dns_free_res(__res__)
     349             : #endif
     350             : 
     351             : /* {{{ proto bool dns_check_record(string host [, string type])
     352             :    Check DNS records corresponding to a given Internet host name or IP address */
     353           1 : PHP_FUNCTION(dns_check_record)
     354             : {
     355             : #ifndef MAXPACKET
     356             : #define MAXPACKET  8192 /* max packet size used internally by BIND */
     357             : #endif
     358             :         u_char ans[MAXPACKET];
     359           1 :         char *hostname, *rectype = NULL;
     360           1 :         size_t hostname_len, rectype_len = 0;
     361           1 :         int type = T_MX, i;
     362             : #if defined(HAVE_DNS_SEARCH)
     363             :         struct sockaddr_storage from;
     364             :         uint32_t fromsize = sizeof(from);
     365             :         dns_handle_t handle;
     366             : #elif defined(HAVE_RES_NSEARCH)
     367             :         struct __res_state state;
     368           1 :         struct __res_state *handle = &state;
     369             : #endif
     370             : 
     371           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", &hostname, &hostname_len, &rectype, &rectype_len) == FAILURE) {
     372           0 :                 return;
     373             :         }
     374             : 
     375           1 :         if (hostname_len == 0) {
     376           1 :                 php_error_docref(NULL, E_WARNING, "Host cannot be empty");
     377           1 :                 RETURN_FALSE;
     378             :         }
     379             : 
     380           0 :         if (rectype) {
     381           0 :                 if (!strcasecmp("A",     rectype)) type = T_A;
     382           0 :                 else if (!strcasecmp("NS",    rectype)) type = DNS_T_NS;
     383           0 :                 else if (!strcasecmp("MX",    rectype)) type = DNS_T_MX;
     384           0 :                 else if (!strcasecmp("PTR",   rectype)) type = DNS_T_PTR;
     385           0 :                 else if (!strcasecmp("ANY",   rectype)) type = DNS_T_ANY;
     386           0 :                 else if (!strcasecmp("SOA",   rectype)) type = DNS_T_SOA;
     387           0 :                 else if (!strcasecmp("TXT",   rectype)) type = DNS_T_TXT;
     388           0 :                 else if (!strcasecmp("CNAME", rectype)) type = DNS_T_CNAME;
     389           0 :                 else if (!strcasecmp("AAAA",  rectype)) type = DNS_T_AAAA;
     390           0 :                 else if (!strcasecmp("SRV",   rectype)) type = DNS_T_SRV;
     391           0 :                 else if (!strcasecmp("NAPTR", rectype)) type = DNS_T_NAPTR;
     392           0 :                 else if (!strcasecmp("A6",    rectype)) type = DNS_T_A6;
     393             :                 else {
     394           0 :                         php_error_docref(NULL, E_WARNING, "Type '%s' not supported", rectype);
     395           0 :                         RETURN_FALSE;
     396             :                 }
     397             :         }
     398             : 
     399             : #if defined(HAVE_DNS_SEARCH)
     400             :         handle = dns_open(NULL);
     401             :         if (handle == NULL) {
     402             :                 RETURN_FALSE;
     403             :         }
     404             : #elif defined(HAVE_RES_NSEARCH)
     405           0 :     memset(&state, 0, sizeof(state));
     406           0 :     if (res_ninit(handle)) {
     407           0 :                         RETURN_FALSE;
     408             :         }
     409             : #else
     410             :         res_init();
     411             : #endif
     412             : 
     413           0 :         RETVAL_TRUE;
     414           0 :         i = php_dns_search(handle, hostname, C_IN, type, ans, sizeof(ans));
     415             : 
     416           0 :         if (i < 0) {
     417           0 :                 RETVAL_FALSE;
     418             :         }
     419             : 
     420           0 :         php_dns_free_handle(handle);
     421             : }
     422             : /* }}} */
     423             : 
     424             : #if HAVE_FULL_DNS_FUNCS
     425             : 
     426             : #define CHECKCP(n) do { \
     427             :         if (cp + n > end) { \
     428             :                 return NULL; \
     429             :         } \
     430             : } while (0)
     431             : 
     432             : /* {{{ php_parserr */
     433           0 : static u_char *php_parserr(u_char *cp, u_char *end, querybuf *answer, int type_to_fetch, int store, int raw, zval *subarray)
     434             : {
     435             :         u_short type, class, dlen;
     436             :         u_long ttl;
     437             :         long n, i;
     438             :         u_short s;
     439             :         u_char *tp, *p;
     440             :         char name[MAXHOSTNAMELEN];
     441           0 :         int have_v6_break = 0, in_v6_break = 0;
     442             : 
     443           0 :         ZVAL_UNDEF(subarray);
     444             : 
     445           0 :         n = dn_expand(answer->qb2, end, cp, name, sizeof(name) - 2);
     446           0 :         if (n < 0) {
     447           0 :                 return NULL;
     448             :         }
     449           0 :         cp += n;
     450             : 
     451           0 :         CHECKCP(10);
     452           0 :         GETSHORT(type, cp);
     453           0 :         GETSHORT(class, cp);
     454           0 :         GETLONG(ttl, cp);
     455           0 :         GETSHORT(dlen, cp);
     456           0 :         CHECKCP(dlen);
     457           0 :         if (type_to_fetch != T_ANY && type != type_to_fetch) {
     458           0 :                 cp += dlen;
     459           0 :                 return cp;
     460             :         }
     461             : 
     462           0 :         if (!store) {
     463           0 :                 cp += dlen;
     464           0 :                 return cp;
     465             :         }
     466             : 
     467           0 :         array_init(subarray);
     468             : 
     469           0 :         add_assoc_string(subarray, "host", name);
     470           0 :         add_assoc_string(subarray, "class", "IN");
     471           0 :         add_assoc_long(subarray, "ttl", ttl);
     472             :         (void) class;
     473             : 
     474           0 :         if (raw) {
     475           0 :                 add_assoc_long(subarray, "type", type);
     476           0 :                 add_assoc_stringl(subarray, "data", (char*) cp, (uint) dlen);
     477           0 :                 cp += dlen;
     478           0 :                 return cp;
     479             :         }
     480             : 
     481           0 :         switch (type) {
     482             :                 case DNS_T_A:
     483           0 :                         CHECKCP(4);
     484           0 :                         add_assoc_string(subarray, "type", "A");
     485           0 :                         snprintf(name, sizeof(name), "%d.%d.%d.%d", cp[0], cp[1], cp[2], cp[3]);
     486           0 :                         add_assoc_string(subarray, "ip", name);
     487           0 :                         cp += dlen;
     488           0 :                         break;
     489             :                 case DNS_T_MX:
     490           0 :                         CHECKCP(2);
     491           0 :                         add_assoc_string(subarray, "type", "MX");
     492           0 :                         GETSHORT(n, cp);
     493           0 :                         add_assoc_long(subarray, "pri", n);
     494             :                         /* no break; */
     495             :                 case DNS_T_CNAME:
     496           0 :                         if (type == DNS_T_CNAME) {
     497           0 :                                 add_assoc_string(subarray, "type", "CNAME");
     498             :                         }
     499             :                         /* no break; */
     500             :                 case DNS_T_NS:
     501           0 :                         if (type == DNS_T_NS) {
     502           0 :                                 add_assoc_string(subarray, "type", "NS");
     503             :                         }
     504             :                         /* no break; */
     505             :                 case DNS_T_PTR:
     506           0 :                         if (type == DNS_T_PTR) {
     507           0 :                                 add_assoc_string(subarray, "type", "PTR");
     508             :                         }
     509           0 :                         n = dn_expand(answer->qb2, end, cp, name, (sizeof name) - 2);
     510           0 :                         if (n < 0) {
     511           0 :                                 return NULL;
     512             :                         }
     513           0 :                         cp += n;
     514           0 :                         add_assoc_string(subarray, "target", name);
     515           0 :                         break;
     516             :                 case DNS_T_HINFO:
     517             :                         /* See RFC 1010 for values */
     518           0 :                         add_assoc_string(subarray, "type", "HINFO");
     519           0 :                         CHECKCP(1);
     520           0 :                         n = *cp & 0xFF;
     521           0 :                         cp++;
     522           0 :                         CHECKCP(n);
     523           0 :                         add_assoc_stringl(subarray, "cpu", (char*)cp, n);
     524           0 :                         cp += n;
     525           0 :                         CHECKCP(1);
     526           0 :                         n = *cp & 0xFF;
     527           0 :                         cp++;
     528           0 :                         CHECKCP(n);
     529           0 :                         add_assoc_stringl(subarray, "os", (char*)cp, n);
     530           0 :                         cp += n;
     531           0 :                         break;
     532             :                 case DNS_T_TXT:
     533             :                         {
     534           0 :                                 int l1 = 0, l2 = 0;
     535             :                                 zval entries;
     536             :                                 zend_string *tp;
     537             : 
     538           0 :                                 add_assoc_string(subarray, "type", "TXT");
     539           0 :                                 tp = zend_string_alloc(dlen, 0);
     540             : 
     541           0 :                                 array_init(&entries);
     542             : 
     543           0 :                                 while (l1 < dlen) {
     544           0 :                                         n = cp[l1];
     545           0 :                                         if ((l1 + n) >= dlen) {
     546             :                                                 // Invalid chunk length, truncate
     547           0 :                                                 n = dlen - (l1 + 1);
     548             :                                         }
     549           0 :                                         if (n) {
     550           0 :                                                 memcpy(tp->val + l2 , cp + l1 + 1, n);
     551           0 :                                                 add_next_index_stringl(&entries, (char *) cp + l1 + 1, n);
     552             :                                         }
     553           0 :                                         l1 = l1 + n + 1;
     554           0 :                                         l2 = l2 + n;
     555             :                                 }
     556           0 :                                 tp->val[l2] = '\0';
     557           0 :                                 tp->len = l2;
     558           0 :                                 cp += dlen;
     559             : 
     560           0 :                                 add_assoc_str(subarray, "txt", tp);
     561           0 :                                 add_assoc_zval(subarray, "entries", &entries);
     562             :                         }
     563           0 :                         break;
     564             :                 case DNS_T_SOA:
     565           0 :                         add_assoc_string(subarray, "type", "SOA");
     566           0 :                         n = dn_expand(answer->qb2, end, cp, name, (sizeof name) -2);
     567           0 :                         if (n < 0) {
     568           0 :                                 return NULL;
     569             :                         }
     570           0 :                         cp += n;
     571           0 :                         add_assoc_string(subarray, "mname", name);
     572           0 :                         n = dn_expand(answer->qb2, end, cp, name, (sizeof name) -2);
     573           0 :                         if (n < 0) {
     574           0 :                                 return NULL;
     575             :                         }
     576           0 :                         cp += n;
     577           0 :                         add_assoc_string(subarray, "rname", name);
     578           0 :                         CHECKCP(5*4);
     579           0 :                         GETLONG(n, cp);
     580           0 :                         add_assoc_long(subarray, "serial", n);
     581           0 :                         GETLONG(n, cp);
     582           0 :                         add_assoc_long(subarray, "refresh", n);
     583           0 :                         GETLONG(n, cp);
     584           0 :                         add_assoc_long(subarray, "retry", n);
     585           0 :                         GETLONG(n, cp);
     586           0 :                         add_assoc_long(subarray, "expire", n);
     587           0 :                         GETLONG(n, cp);
     588           0 :                         add_assoc_long(subarray, "minimum-ttl", n);
     589           0 :                         break;
     590             :                 case DNS_T_AAAA:
     591           0 :                         tp = (u_char*)name;
     592           0 :                         CHECKCP(8*2);
     593           0 :                         for(i=0; i < 8; i++) {
     594           0 :                                 GETSHORT(s, cp);
     595           0 :                                 if (s != 0) {
     596           0 :                                         if (tp > (u_char *)name) {
     597           0 :                                                 in_v6_break = 0;
     598           0 :                                                 tp[0] = ':';
     599           0 :                                                 tp++;
     600             :                                         }
     601           0 :                                         tp += sprintf((char*)tp,"%x",s);
     602             :                                 } else {
     603           0 :                                         if (!have_v6_break) {
     604           0 :                                                 have_v6_break = 1;
     605           0 :                                                 in_v6_break = 1;
     606           0 :                                                 tp[0] = ':';
     607           0 :                                                 tp++;
     608           0 :                                         } else if (!in_v6_break) {
     609           0 :                                                 tp[0] = ':';
     610           0 :                                                 tp++;
     611           0 :                                                 tp[0] = '0';
     612           0 :                                                 tp++;
     613             :                                         }
     614             :                                 }
     615             :                         }
     616           0 :                         if (have_v6_break && in_v6_break) {
     617           0 :                                 tp[0] = ':';
     618           0 :                                 tp++;
     619             :                         }
     620           0 :                         tp[0] = '\0';
     621           0 :                         add_assoc_string(subarray, "type", "AAAA");
     622           0 :                         add_assoc_string(subarray, "ipv6", name);
     623           0 :                         break;
     624             :                 case DNS_T_A6:
     625           0 :                         p = cp;
     626           0 :                         add_assoc_string(subarray, "type", "A6");
     627           0 :                         CHECKCP(1);
     628           0 :                         n = ((int)cp[0]) & 0xFF;
     629           0 :                         cp++;
     630           0 :                         add_assoc_long(subarray, "masklen", n);
     631           0 :                         tp = (u_char*)name;
     632           0 :                         if (n > 15) {
     633           0 :                                 have_v6_break = 1;
     634           0 :                                 in_v6_break = 1;
     635           0 :                                 tp[0] = ':';
     636           0 :                                 tp++;
     637             :                         }
     638           0 :                         if (n % 16 > 8) {
     639             :                                 /* Partial short */
     640           0 :                                 if (cp[0] != 0) {
     641           0 :                                         if (tp > (u_char *)name) {
     642           0 :                                                 in_v6_break = 0;
     643           0 :                                                 tp[0] = ':';
     644           0 :                                                 tp++;
     645             :                                         }
     646           0 :                                         sprintf((char*)tp, "%x", cp[0] & 0xFF);
     647             :                                 } else {
     648           0 :                                         if (!have_v6_break) {
     649           0 :                                                 have_v6_break = 1;
     650           0 :                                                 in_v6_break = 1;
     651           0 :                                                 tp[0] = ':';
     652           0 :                                                 tp++;
     653           0 :                                         } else if (!in_v6_break) {
     654           0 :                                                 tp[0] = ':';
     655           0 :                                                 tp++;
     656           0 :                                                 tp[0] = '0';
     657           0 :                                                 tp++;
     658             :                                         }
     659             :                                 }
     660           0 :                                 cp++;
     661             :                         }
     662           0 :                         for (i = (n + 8) / 16; i < 8; i++) {
     663           0 :                                 CHECKCP(2);
     664           0 :                                 GETSHORT(s, cp);
     665           0 :                                 if (s != 0) {
     666           0 :                                         if (tp > (u_char *)name) {
     667           0 :                                                 in_v6_break = 0;
     668           0 :                                                 tp[0] = ':';
     669           0 :                                                 tp++;
     670             :                                         }
     671           0 :                                         tp += sprintf((char*)tp,"%x",s);
     672             :                                 } else {
     673           0 :                                         if (!have_v6_break) {
     674           0 :                                                 have_v6_break = 1;
     675           0 :                                                 in_v6_break = 1;
     676           0 :                                                 tp[0] = ':';
     677           0 :                                                 tp++;
     678           0 :                                         } else if (!in_v6_break) {
     679           0 :                                                 tp[0] = ':';
     680           0 :                                                 tp++;
     681           0 :                                                 tp[0] = '0';
     682           0 :                                                 tp++;
     683             :                                         }
     684             :                                 }
     685             :                         }
     686           0 :                         if (have_v6_break && in_v6_break) {
     687           0 :                                 tp[0] = ':';
     688           0 :                                 tp++;
     689             :                         }
     690           0 :                         tp[0] = '\0';
     691           0 :                         add_assoc_string(subarray, "ipv6", name);
     692           0 :                         if (cp < p + dlen) {
     693           0 :                                 n = dn_expand(answer->qb2, end, cp, name, (sizeof name) - 2);
     694           0 :                                 if (n < 0) {
     695           0 :                                         return NULL;
     696             :                                 }
     697           0 :                                 cp += n;
     698           0 :                                 add_assoc_string(subarray, "chain", name);
     699             :                         }
     700           0 :                         break;
     701             :                 case DNS_T_SRV:
     702           0 :                         CHECKCP(3*2);
     703           0 :                         add_assoc_string(subarray, "type", "SRV");
     704           0 :                         GETSHORT(n, cp);
     705           0 :                         add_assoc_long(subarray, "pri", n);
     706           0 :                         GETSHORT(n, cp);
     707           0 :                         add_assoc_long(subarray, "weight", n);
     708           0 :                         GETSHORT(n, cp);
     709           0 :                         add_assoc_long(subarray, "port", n);
     710           0 :                         n = dn_expand(answer->qb2, end, cp, name, (sizeof name) - 2);
     711           0 :                         if (n < 0) {
     712           0 :                                 return NULL;
     713             :                         }
     714           0 :                         cp += n;
     715           0 :                         add_assoc_string(subarray, "target", name);
     716           0 :                         break;
     717             :                 case DNS_T_NAPTR:
     718           0 :                         CHECKCP(2*2);
     719           0 :                         add_assoc_string(subarray, "type", "NAPTR");
     720           0 :                         GETSHORT(n, cp);
     721           0 :                         add_assoc_long(subarray, "order", n);
     722           0 :                         GETSHORT(n, cp);
     723           0 :                         add_assoc_long(subarray, "pref", n);
     724             : 
     725           0 :                         CHECKCP(1);
     726           0 :                         n = (cp[0] & 0xFF);
     727           0 :                         cp++;
     728           0 :                         CHECKCP(n);
     729           0 :                         add_assoc_stringl(subarray, "flags", (char*)cp, n);
     730           0 :                         cp += n;
     731             : 
     732           0 :                         CHECKCP(1);
     733           0 :                         n = (cp[0] & 0xFF);
     734           0 :                         cp++;
     735           0 :                         CHECKCP(n);
     736           0 :                         add_assoc_stringl(subarray, "services", (char*)cp, n);
     737           0 :                         cp += n;
     738             : 
     739           0 :                         CHECKCP(1);
     740           0 :                         n = (cp[0] & 0xFF);
     741           0 :                         cp++;
     742           0 :                         CHECKCP(n);
     743           0 :                         add_assoc_stringl(subarray, "regex", (char*)cp, n);
     744           0 :                         cp += n;
     745             : 
     746           0 :                         n = dn_expand(answer->qb2, end, cp, name, (sizeof name) - 2);
     747           0 :                         if (n < 0) {
     748           0 :                                 return NULL;
     749             :                         }
     750           0 :                         cp += n;
     751           0 :                         add_assoc_string(subarray, "replacement", name);
     752           0 :                         break;
     753             :                 default:
     754           0 :                         zval_ptr_dtor(subarray);
     755           0 :                         ZVAL_UNDEF(subarray);
     756           0 :                         cp += dlen;
     757             :                         break;
     758             :         }
     759             : 
     760           0 :         return cp;
     761             : }
     762             : /* }}} */
     763             : 
     764             : /* {{{ proto array|false dns_get_record(string hostname [, int type[, array authns, array addtl]])
     765             :    Get any Resource Record corresponding to a given Internet host name */
     766           0 : PHP_FUNCTION(dns_get_record)
     767             : {
     768             :         char *hostname;
     769             :         size_t hostname_len;
     770           0 :         long type_param = PHP_DNS_ANY;
     771           0 :         zval *authns = NULL, *addtl = NULL;
     772             :         int type_to_fetch;
     773             : #if defined(HAVE_DNS_SEARCH)
     774             :         struct sockaddr_storage from;
     775             :         uint32_t fromsize = sizeof(from);
     776             :         dns_handle_t handle;
     777             : #elif defined(HAVE_RES_NSEARCH)
     778             :         struct __res_state state;
     779           0 :         struct __res_state *handle = &state;
     780             : #endif
     781             :         HEADER *hp;
     782             :         querybuf answer;
     783           0 :         u_char *cp = NULL, *end = NULL;
     784           0 :         int n, qd, an, ns = 0, ar = 0;
     785           0 :         int type, first_query = 1, store_results = 1;
     786           0 :         zend_bool raw = 0;
     787             : 
     788           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|lz!z!b",
     789             :                         &hostname, &hostname_len, &type_param, &authns, &addtl, &raw) == FAILURE) {
     790           0 :                 return;
     791             :         }
     792             : 
     793           0 :         if (authns) {
     794           0 :                 zval_dtor(authns);
     795           0 :                 array_init(authns);
     796             :         }
     797           0 :         if (addtl) {
     798           0 :                 zval_dtor(addtl);
     799           0 :                 array_init(addtl);
     800             :         }
     801             : 
     802           0 :         if (!raw) {
     803           0 :                 if ((type_param & ~PHP_DNS_ALL) && (type_param != PHP_DNS_ANY)) {
     804           0 :                         php_error_docref(NULL, E_WARNING, "Type '%ld' not supported", type_param);
     805           0 :                         RETURN_FALSE;
     806             :                 }
     807             :         } else {
     808           0 :                 if ((type_param < 1) || (type_param > 0xFFFF)) {
     809           0 :                         php_error_docref(NULL, E_WARNING,
     810             :                                 "Numeric DNS record type must be between 1 and 65535, '%ld' given", type_param);
     811           0 :                         RETURN_FALSE;
     812             :                 }
     813             :         }
     814             : 
     815             :         /* Initialize the return array */
     816           0 :         array_init(return_value);
     817             : 
     818             :         /* - We emulate an or'ed type mask by querying type by type. (Steps 0 - NUMTYPES-1 )
     819             :          *   If additional info is wanted we check again with DNS_T_ANY (step NUMTYPES / NUMTYPES+1 )
     820             :          *   store_results is used to skip storing the results retrieved in step
     821             :          *   NUMTYPES+1 when results were already fetched.
     822             :          * - In case of PHP_DNS_ANY we use the directly fetch DNS_T_ANY. (step NUMTYPES+1 )
     823             :          * - In case of raw mode, we query only the requestd type instead of looping type by type
     824             :          *   before going with the additional info stuff.
     825             :          */
     826             : 
     827           0 :         if (raw) {
     828           0 :                 type = -1;
     829           0 :         } else if (type_param == PHP_DNS_ANY) {
     830           0 :                 type = PHP_DNS_NUM_TYPES + 1;
     831             :         } else {
     832           0 :                 type = 0;
     833             :         }
     834             : 
     835           0 :         for ( ;
     836           0 :                 type < (addtl ? (PHP_DNS_NUM_TYPES + 2) : PHP_DNS_NUM_TYPES) || first_query;
     837             :                 type++
     838           0 :         ) {
     839           0 :                 first_query = 0;
     840           0 :                 switch (type) {
     841             :                         case -1: /* raw */
     842           0 :                                 type_to_fetch = type_param;
     843             :                                 /* skip over the rest and go directly to additional records */
     844           0 :                                 type = PHP_DNS_NUM_TYPES - 1;
     845           0 :                                 break;
     846             :                         case 0:
     847           0 :                                 type_to_fetch = type_param&PHP_DNS_A     ? DNS_T_A     : 0;
     848           0 :                                 break;
     849             :                         case 1:
     850           0 :                                 type_to_fetch = type_param&PHP_DNS_NS    ? DNS_T_NS    : 0;
     851           0 :                                 break;
     852             :                         case 2:
     853           0 :                                 type_to_fetch = type_param&PHP_DNS_CNAME ? DNS_T_CNAME : 0;
     854           0 :                                 break;
     855             :                         case 3:
     856           0 :                                 type_to_fetch = type_param&PHP_DNS_SOA   ? DNS_T_SOA   : 0;
     857           0 :                                 break;
     858             :                         case 4:
     859           0 :                                 type_to_fetch = type_param&PHP_DNS_PTR   ? DNS_T_PTR   : 0;
     860           0 :                                 break;
     861             :                         case 5:
     862           0 :                                 type_to_fetch = type_param&PHP_DNS_HINFO ? DNS_T_HINFO : 0;
     863           0 :                                 break;
     864             :                         case 6:
     865           0 :                                 type_to_fetch = type_param&PHP_DNS_MX    ? DNS_T_MX    : 0;
     866           0 :                                 break;
     867             :                         case 7:
     868           0 :                                 type_to_fetch = type_param&PHP_DNS_TXT   ? DNS_T_TXT   : 0;
     869           0 :                                 break;
     870             :                         case 8:
     871           0 :                                 type_to_fetch = type_param&PHP_DNS_AAAA      ? DNS_T_AAAA  : 0;
     872           0 :                                 break;
     873             :                         case 9:
     874           0 :                                 type_to_fetch = type_param&PHP_DNS_SRV   ? DNS_T_SRV   : 0;
     875           0 :                                 break;
     876             :                         case 10:
     877           0 :                                 type_to_fetch = type_param&PHP_DNS_NAPTR ? DNS_T_NAPTR : 0;
     878           0 :                                 break;
     879             :                         case 11:
     880           0 :                                 type_to_fetch = type_param&PHP_DNS_A6        ? DNS_T_A6 : 0;
     881           0 :                                 break;
     882             :                         case PHP_DNS_NUM_TYPES:
     883           0 :                                 store_results = 0;
     884           0 :                                 continue;
     885             :                         default:
     886             :                         case (PHP_DNS_NUM_TYPES + 1):
     887           0 :                                 type_to_fetch = DNS_T_ANY;
     888             :                                 break;
     889             :                 }
     890             : 
     891           0 :                 if (type_to_fetch) {
     892             : #if defined(HAVE_DNS_SEARCH)
     893             :                         handle = dns_open(NULL);
     894             :                         if (handle == NULL) {
     895             :                                 zval_dtor(return_value);
     896             :                                 RETURN_FALSE;
     897             :                         }
     898             : #elif defined(HAVE_RES_NSEARCH)
     899           0 :                     memset(&state, 0, sizeof(state));
     900           0 :                     if (res_ninit(handle)) {
     901             :                         zval_dtor(return_value);
     902           0 :                                 RETURN_FALSE;
     903             :                         }
     904             : #else
     905             :                         res_init();
     906             : #endif
     907             : 
     908           0 :                         n = php_dns_search(handle, hostname, C_IN, type_to_fetch, answer.qb2, sizeof answer);
     909             : 
     910           0 :                         if (n < 0) {
     911           0 :                                 php_dns_free_handle(handle);
     912           0 :                                 switch (h_errno) {
     913             :                                         case NO_DATA:
     914             :                                         case HOST_NOT_FOUND:
     915           0 :                                                 continue;
     916             : 
     917             :                                         case NO_RECOVERY:
     918           0 :                                                 php_error_docref(NULL, E_WARNING, "An unexpected server failure occurred.");
     919           0 :                                                 break;
     920             : 
     921             :                                         case TRY_AGAIN:
     922           0 :                                                 php_error_docref(NULL, E_WARNING, "A temporary server error occurred.");
     923           0 :                                                 break;
     924             : 
     925             :                                         default:
     926           0 :                                                 php_error_docref(NULL, E_WARNING, "DNS Query failed");
     927             :                                 }
     928             :                                 zval_dtor(return_value);
     929           0 :                                 RETURN_FALSE;
     930             :                         }
     931             : 
     932           0 :                         cp = answer.qb2 + HFIXEDSZ;
     933           0 :                         end = answer.qb2 + n;
     934           0 :                         hp = (HEADER *)&answer;
     935           0 :                         qd = ntohs(hp->qdcount);
     936           0 :                         an = ntohs(hp->ancount);
     937           0 :                         ns = ntohs(hp->nscount);
     938           0 :                         ar = ntohs(hp->arcount);
     939             : 
     940             :                         /* Skip QD entries, they're only used by dn_expand later on */
     941           0 :                         while (qd-- > 0) {
     942           0 :                                 n = dn_skipname(cp, end);
     943           0 :                                 if (n < 0) {
     944           0 :                                         php_error_docref(NULL, E_WARNING, "Unable to parse DNS data received");
     945             :                                         zval_dtor(return_value);
     946           0 :                                         php_dns_free_handle(handle);
     947           0 :                                         RETURN_FALSE;
     948             :                                 }
     949           0 :                                 cp += n + QFIXEDSZ;
     950             :                         }
     951             : 
     952             :                         /* YAY! Our real answers! */
     953           0 :                         while (an-- && cp && cp < end) {
     954             :                                 zval retval;
     955             : 
     956           0 :                                 cp = php_parserr(cp, end, &answer, type_to_fetch, store_results, raw, &retval);
     957           0 :                                 if (Z_TYPE(retval) != IS_UNDEF && store_results) {
     958           0 :                                         add_next_index_zval(return_value, &retval);
     959             :                                 }
     960             :                         }
     961             : 
     962           0 :                         if (authns || addtl) {
     963             :                                 /* List of Authoritative Name Servers
     964             :                                  * Process when only requesting addtl so that we can skip through the section
     965             :                                  */
     966           0 :                                 while (ns-- > 0 && cp && cp < end) {
     967             :                                         zval retval;
     968             : 
     969           0 :                                         cp = php_parserr(cp, end, &answer, DNS_T_ANY, authns != NULL, raw, &retval);
     970           0 :                                         if (Z_TYPE(retval) != IS_UNDEF) {
     971           0 :                                                 add_next_index_zval(authns, &retval);
     972             :                                         }
     973             :                                 }
     974             :                         }
     975             : 
     976           0 :                         if (addtl) {
     977             :                                 /* Additional records associated with authoritative name servers */
     978           0 :                                 while (ar-- > 0 && cp && cp < end) {
     979             :                                         zval retval;
     980             : 
     981           0 :                                         cp = php_parserr(cp, end, &answer, DNS_T_ANY, 1, raw, &retval);
     982           0 :                                         if (Z_TYPE(retval) != IS_UNDEF) {
     983           0 :                                                 add_next_index_zval(addtl, &retval);
     984             :                                         }
     985             :                                 }
     986             :                         }
     987           0 :                         php_dns_free_handle(handle);
     988             :                 }
     989             :         }
     990             : }
     991             : /* }}} */
     992             : 
     993             : /* {{{ proto bool dns_get_mx(string hostname, array mxhosts [, array weight])
     994             :    Get MX records corresponding to a given Internet host name */
     995           2 : PHP_FUNCTION(dns_get_mx)
     996             : {
     997             :         char *hostname;
     998             :         size_t hostname_len;
     999           2 :         zval *mx_list, *weight_list = NULL;
    1000             :         int count, qdc;
    1001             :         u_short type, weight;
    1002             :         u_char ans[MAXPACKET];
    1003             :         char buf[MAXHOSTNAMELEN];
    1004             :         HEADER *hp;
    1005             :         u_char *cp, *end;
    1006             :         int i;
    1007             : #if defined(HAVE_DNS_SEARCH)
    1008             :         struct sockaddr_storage from;
    1009             :         uint32_t fromsize = sizeof(from);
    1010             :         dns_handle_t handle;
    1011             : #elif defined(HAVE_RES_NSEARCH)
    1012             :         struct __res_state state;
    1013           2 :         struct __res_state *handle = &state;
    1014             : #endif
    1015             : 
    1016           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz/|z/", &hostname, &hostname_len, &mx_list, &weight_list) == FAILURE) {
    1017           0 :                 return;
    1018             :         }
    1019             : 
    1020           2 :         zval_dtor(mx_list);
    1021           2 :         array_init(mx_list);
    1022             : 
    1023           2 :         if (weight_list) {
    1024           2 :                 zval_dtor(weight_list);
    1025           2 :                 array_init(weight_list);
    1026             :         }
    1027             : 
    1028             : #if defined(HAVE_DNS_SEARCH)
    1029             :         handle = dns_open(NULL);
    1030             :         if (handle == NULL) {
    1031             :                 RETURN_FALSE;
    1032             :         }
    1033             : #elif defined(HAVE_RES_NSEARCH)
    1034           2 :     memset(&state, 0, sizeof(state));
    1035           2 :     if (res_ninit(handle)) {
    1036           0 :                         RETURN_FALSE;
    1037             :         }
    1038             : #else
    1039             :         res_init();
    1040             : #endif
    1041             : 
    1042           2 :         i = php_dns_search(handle, hostname, C_IN, DNS_T_MX, (u_char *)&ans, sizeof(ans));
    1043           2 :         if (i < 0) {
    1044           0 :                 RETURN_FALSE;
    1045             :         }
    1046           2 :         if (i > (int)sizeof(ans)) {
    1047           0 :                 i = sizeof(ans);
    1048             :         }
    1049           2 :         hp = (HEADER *)&ans;
    1050           2 :         cp = (u_char *)&ans + HFIXEDSZ;
    1051           2 :         end = (u_char *)&ans +i;
    1052           4 :         for (qdc = ntohs((unsigned short)hp->qdcount); qdc--; cp += i + QFIXEDSZ) {
    1053           2 :                 if ((i = dn_skipname(cp, end)) < 0 ) {
    1054           0 :                         php_dns_free_handle(handle);
    1055           0 :                         RETURN_FALSE;
    1056             :                 }
    1057             :         }
    1058           2 :         count = ntohs((unsigned short)hp->ancount);
    1059           7 :         while (--count >= 0 && cp < end) {
    1060           3 :                 if ((i = dn_skipname(cp, end)) < 0 ) {
    1061           0 :                         php_dns_free_handle(handle);
    1062           0 :                         RETURN_FALSE;
    1063             :                 }
    1064           3 :                 cp += i;
    1065           3 :                 GETSHORT(type, cp);
    1066           3 :                 cp += INT16SZ + INT32SZ;
    1067           3 :                 GETSHORT(i, cp);
    1068           3 :                 if (type != DNS_T_MX) {
    1069           0 :                         cp += i;
    1070           0 :                         continue;
    1071             :                 }
    1072           3 :                 GETSHORT(weight, cp);
    1073           3 :                 if ((i = dn_expand(ans, end, cp, buf, sizeof(buf)-1)) < 0) {
    1074           0 :                         php_dns_free_handle(handle);
    1075           0 :                         RETURN_FALSE;
    1076             :                 }
    1077           3 :                 cp += i;
    1078           3 :                 add_next_index_string(mx_list, buf);
    1079           3 :                 if (weight_list) {
    1080           3 :                         add_next_index_long(weight_list, weight);
    1081             :                 }
    1082             :         }
    1083           2 :         php_dns_free_handle(handle);
    1084           2 :         RETURN_TRUE;
    1085             : }
    1086             : /* }}} */
    1087             : #endif /* HAVE_FULL_DNS_FUNCS */
    1088             : #endif /* !defined(PHP_WIN32) && (HAVE_DNS_SEARCH_FUNC && !(defined(__BEOS__) || defined(NETWARE))) */
    1089             : 
    1090             : #if HAVE_FULL_DNS_FUNCS || defined(PHP_WIN32)
    1091       20871 : PHP_MINIT_FUNCTION(dns) {
    1092       20871 :         REGISTER_LONG_CONSTANT("DNS_A",     PHP_DNS_A,     CONST_CS | CONST_PERSISTENT);
    1093       20871 :         REGISTER_LONG_CONSTANT("DNS_NS",    PHP_DNS_NS,    CONST_CS | CONST_PERSISTENT);
    1094       20871 :         REGISTER_LONG_CONSTANT("DNS_CNAME", PHP_DNS_CNAME, CONST_CS | CONST_PERSISTENT);
    1095       20871 :         REGISTER_LONG_CONSTANT("DNS_SOA",   PHP_DNS_SOA,   CONST_CS | CONST_PERSISTENT);
    1096       20871 :         REGISTER_LONG_CONSTANT("DNS_PTR",   PHP_DNS_PTR,   CONST_CS | CONST_PERSISTENT);
    1097       20871 :         REGISTER_LONG_CONSTANT("DNS_HINFO", PHP_DNS_HINFO, CONST_CS | CONST_PERSISTENT);
    1098       20871 :         REGISTER_LONG_CONSTANT("DNS_MX",    PHP_DNS_MX,    CONST_CS | CONST_PERSISTENT);
    1099       20871 :         REGISTER_LONG_CONSTANT("DNS_TXT",   PHP_DNS_TXT,   CONST_CS | CONST_PERSISTENT);
    1100       20871 :         REGISTER_LONG_CONSTANT("DNS_SRV",   PHP_DNS_SRV,   CONST_CS | CONST_PERSISTENT);
    1101       20871 :         REGISTER_LONG_CONSTANT("DNS_NAPTR", PHP_DNS_NAPTR, CONST_CS | CONST_PERSISTENT);
    1102       20871 :         REGISTER_LONG_CONSTANT("DNS_AAAA",  PHP_DNS_AAAA,  CONST_CS | CONST_PERSISTENT);
    1103       20871 :         REGISTER_LONG_CONSTANT("DNS_A6",    PHP_DNS_A6,    CONST_CS | CONST_PERSISTENT);
    1104       20871 :         REGISTER_LONG_CONSTANT("DNS_ANY",   PHP_DNS_ANY,   CONST_CS | CONST_PERSISTENT);
    1105       20871 :         REGISTER_LONG_CONSTANT("DNS_ALL",   PHP_DNS_ALL,   CONST_CS | CONST_PERSISTENT);
    1106       20871 :         return SUCCESS;
    1107             : }
    1108             : #endif /* HAVE_FULL_DNS_FUNCS */
    1109             : 
    1110             : /*
    1111             :  * Local variables:
    1112             :  * tab-width: 4
    1113             :  * c-basic-offset: 4
    1114             :  * End:
    1115             :  * vim600: sw=4 ts=4 fdm=marker
    1116             :  * vim<600: sw=4 ts=4
    1117             :  */

Generated by: LCOV version 1.10

Generated at Tue, 14 Apr 2015 11:48:53 +0000 (11 days ago)

Copyright © 2005-2015 The PHP Group
All rights reserved.