cvs: php4 /ext/standard dns.c
| From: | Jani Taskinen | Date: | Fri, 10 Aug 2001 02:19:06 +0000 |
| Subject: | cvs: php4 /ext/standard dns.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-6688@lists.php.net to get a copy of this message | ||
sniper Thu Aug 9 22:19:06 2001 EDT
Modified files:
/php4/ext/standard dns.c
Log:
Cleanup. Also make gethostnamel() to return FALSE on error and not just empty array.
Index: php4/ext/standard/dns.c
diff -u php4/ext/standard/dns.c:1.31 php4/ext/standard/dns.c:1.32
--- php4/ext/standard/dns.c:1.31 Mon Jul 30 01:36:14 2001
+++ php4/ext/standard/dns.c Thu Aug 9 22:19:05 2001
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: dns.c,v 1.31 2001/07/30 05:36:14 zeev Exp $ */
+/* $Id: dns.c,v 1.32 2001/08/10 02:19:05 sniper Exp $ */
/* {{{ includes
*/
@@ -63,45 +63,52 @@
#include "dns.h"
/* }}} */
-char *php_gethostbyaddr(char *ip);
-char *php_gethostbyname(char *name);
+static char *php_gethostbyaddr(char *ip);
+static char *php_gethostbyname(char *name);
/* {{{ proto string gethostbyaddr(string ip_address)
Get the Internet host name corresponding to a given IP address */
PHP_FUNCTION(gethostbyaddr)
{
- pval **arg;
+ zval **arg;
+ char *addr;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
+ ZEND_WRONG_PARAM_COUNT();
}
+
convert_to_string_ex(arg);
+
+ addr = php_gethostbyaddr(Z_STRVAL_PP(arg));
- RETVAL_STRING(php_gethostbyaddr(Z_STRVAL_PP(arg)), 0);
+ if(addr == NULL) {
+ php_error(E_WARNING, "Address is not in a.b.c.d form");
+ RETVAL_FALSE;
+ } else {
+ RETVAL_STRING(addr, 0);
+ }
}
/* }}} */
/* {{{ php_gethostbyaddr
*/
-char *php_gethostbyaddr(char *ip)
+static char *php_gethostbyaddr(char *ip)
{
struct in_addr addr;
struct hostent *hp;
addr.s_addr = inet_addr(ip);
+
if (addr.s_addr == -1) {
-#if PHP_DEBUG
- php_error(E_WARNING, "address not in a.b.c.d form");
-#endif
- return estrdup(ip);
+ return NULL;
}
+
hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET);
+
if (!hp) {
-#if PHP_DEBUG
- php_error(E_WARNING, "Unable to resolve %s\n", ip);
-#endif
return estrdup(ip);
}
+
return estrdup(hp->h_name);
}
/* }}} */
@@ -110,11 +117,12 @@
Get the IP address corresponding to a given Internet host name */
PHP_FUNCTION(gethostbyname)
{
- pval **arg;
+ zval **arg;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
+ ZEND_WRONG_PARAM_COUNT();
}
+
convert_to_string_ex(arg);
RETVAL_STRING(php_gethostbyname(Z_STRVAL_PP(arg)), 0);
@@ -125,13 +133,13 @@
Return a list of IP addresses that a given hostname resolves to. */
PHP_FUNCTION(gethostbynamel)
{
- pval **arg;
+ zval **arg;
struct hostent *hp;
struct in_addr in;
int i;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
+ ZEND_WRONG_PARAM_COUNT();
}
convert_to_string_ex(arg);
@@ -141,36 +149,31 @@
hp = gethostbyname(Z_STRVAL_PP(arg));
if (hp == NULL || hp->h_addr_list == NULL) {
-#if PHP_DEBUG
- php_error(E_WARNING, "Unable to resolve %s\n", Z_STRVAL_PP(arg));
-#endif
- return;
+ RETURN_FALSE;
}
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);
}
-
- return;
}
/* }}} */
/* {{{ php_gethostbyname
*/
-char *php_gethostbyname(char *name)
+static char *php_gethostbyname(char *name)
{
struct hostent *hp;
struct in_addr in;
hp = gethostbyname(name);
+
if (!hp || !hp->h_addr_list) {
-#if PHP_DEBUG
- php_error(E_WARNING, "Unable to resolve %s\n", name);
-#endif
return estrdup(name);
}
+
memcpy(&in.s_addr, *(hp->h_addr_list), sizeof(in.s_addr));
+
return estrdup(inet_ntoa(in));
}
/* }}} */
@@ -181,7 +184,7 @@
Check DNS records corresponding to a given Internet host name or IP address */
PHP_FUNCTION(checkdnsrr)
{
- pval **arg1,**arg2;
+ zval **arg1,**arg2;
int type,i;
#ifndef MAXPACKET
#define MAXPACKET 8192 /* max packet size used internally by BIND */