Back to index

php5  5.3.10
Defines | Functions
dns.c File Reference
#include "php.h"
#include "php_network.h"
#include <netinet/in.h>
#include <netdb.h>
#include "php_dns.h"

Go to the source code of this file.

Defines

#define MAXHOSTNAMELEN   255
#define HOST_NAME_MAX   255
#define DNS_T_A   1
#define DNS_T_NS   2
#define DNS_T_CNAME   5
#define DNS_T_SOA   6
#define DNS_T_PTR   12
#define DNS_T_HINFO   13
#define DNS_T_MINFO   14
#define DNS_T_MX   15
#define DNS_T_TXT   16
#define DNS_T_AAAA   28
#define DNS_T_SRV   33
#define DNS_T_NAPTR   35
#define DNS_T_A6   38
#define DNS_T_ANY   255

Functions

static char * php_gethostbyaddr (char *ip)
static char * php_gethostbyname (char *name)
 PHP_FUNCTION (gethostbyaddr)
 PHP_FUNCTION (gethostbyname)
 PHP_FUNCTION (gethostbynamel)

Define Documentation

#define DNS_T_A   1

Definition at line 79 of file dns.c.

#define DNS_T_A6   38

Definition at line 115 of file dns.c.

#define DNS_T_AAAA   28

Definition at line 106 of file dns.c.

#define DNS_T_ANY   255

Definition at line 119 of file dns.c.

#define DNS_T_CNAME   5

Definition at line 85 of file dns.c.

#define DNS_T_HINFO   13

Definition at line 94 of file dns.c.

#define DNS_T_MINFO   14

Definition at line 97 of file dns.c.

#define DNS_T_MX   15

Definition at line 100 of file dns.c.

#define DNS_T_NAPTR   35

Definition at line 112 of file dns.c.

#define DNS_T_NS   2

Definition at line 82 of file dns.c.

#define DNS_T_PTR   12

Definition at line 91 of file dns.c.

#define DNS_T_SOA   6

Definition at line 88 of file dns.c.

#define DNS_T_SRV   33

Definition at line 109 of file dns.c.

#define DNS_T_TXT   16

Definition at line 103 of file dns.c.

#define HOST_NAME_MAX   255

Definition at line 72 of file dns.c.

#define MAXHOSTNAMELEN   255

Definition at line 66 of file dns.c.


Function Documentation

PHP_FUNCTION ( gethostbyaddr  )

Definition at line 153 of file dns.c.

{
       char *addr;
       int addr_len;
       char *hostname;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &addr_len) == FAILURE) {
              return;
       }

       hostname = php_gethostbyaddr(addr);

       if (hostname == NULL) {
#if HAVE_IPV6 && HAVE_INET_PTON
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Address is not a valid IPv4 or IPv6 address");
#else
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Address is not in a.b.c.d form");
#endif
              RETVAL_FALSE;
       } else {
              RETVAL_STRING(hostname, 0);
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( gethostbyname  )

Definition at line 215 of file dns.c.

{
       char *hostname;
       int hostname_len;
       char *addr;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &hostname_len) == FAILURE) {
              return;
       }

       addr = php_gethostbyname(hostname);

       RETVAL_STRING(addr, 0);
}

Here is the call graph for this function:

PHP_FUNCTION ( gethostbynamel  )

Definition at line 233 of file dns.c.

{
       char *hostname;
       int hostname_len;
       struct hostent *hp;
       struct in_addr in;
       int i;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &hostname_len) == FAILURE) {
              return;
       }

       hp = gethostbyname(hostname);
       if (hp == NULL || hp->h_addr_list == NULL) {
              RETURN_FALSE;
       }

       array_init(return_value);

       for (i = 0 ; hp->h_addr_list[i] != 0 ; i++) {
              in = *(struct in_addr *) hp->h_addr_list[i];
              add_next_index_string(return_value, inet_ntoa(in), 1);
       }
}

Here is the call graph for this function:

static char * php_gethostbyaddr ( char *  ip) [static]

Definition at line 179 of file dns.c.

{
#if HAVE_IPV6 && HAVE_INET_PTON
       struct in6_addr addr6;
#endif
       struct in_addr addr;
       struct hostent *hp;

#if HAVE_IPV6 && HAVE_INET_PTON
       if (inet_pton(AF_INET6, ip, &addr6)) {
              hp = gethostbyaddr((char *) &addr6, sizeof(addr6), AF_INET6);
       } else if (inet_pton(AF_INET, ip, &addr)) {
              hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET);
       } else {
              return NULL;
       }
#else
       addr.s_addr = inet_addr(ip);

       if (addr.s_addr == -1) {
              return NULL;
       }

       hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET);
#endif

       if (!hp || hp->h_name == NULL || hp->h_name[0] == '\0') {
              return estrdup(ip);
       }

       return estrdup(hp->h_name);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char * php_gethostbyname ( char *  name) [static]

Definition at line 260 of file dns.c.

{
       struct hostent *hp;
       struct in_addr in;

       hp = gethostbyname(name);

       if (!hp || !*(hp->h_addr_list)) {
              return estrdup(name);
       }

       memcpy(&in.s_addr, *(hp->h_addr_list), sizeof(in.s_addr));

       return estrdup(inet_ntoa(in));
}

Here is the caller graph for this function: