[PHP-DEV] [PATCH] fix gethostbyname() to return false when hostname not resolved From: Jim Winstead (jimw <email protected>)
Date: 09/25/01

here's a patch to fix bug #13423. think anyone is relying on the
current (vastly lame, imho) behavior?

jim

Index: ext/standard/dns.c
===================================================================
RCS file: /repository/php4/ext/standard/dns.c,v
retrieving revision 1.35
diff -u -r1.35 dns.c
--- ext/standard/dns.c 19 Sep 2001 18:08:15 -0000 1.35
+++ ext/standard/dns.c 25 Sep 2001 20:54:06 -0000
@@ -135,6 +135,7 @@
 PHP_FUNCTION(gethostbyname)
 {
         zval **arg;
+ char *host;
         
         if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
                 ZEND_WRONG_PARAM_COUNT();
@@ -142,7 +143,12 @@
 
         convert_to_string_ex(arg);
 
- RETVAL_STRING(php_gethostbyname(Z_STRVAL_PP(arg)), 0);
+ if ((host = php_gethostbyname(Z_STRVAL_PP(arg)))) {
+ RETVAL_STRING(host, 0);
+ }
+ else {
+ RETURN_FALSE;
+ }
 }
 /* }}} */
 
@@ -186,7 +192,7 @@
         hp = gethostbyname(name);
 
         if (!hp || !hp->h_addr_list) {
- return estrdup(name);
+ return NULL;
         }
 
         memcpy(&in.s_addr, *(hp->h_addr_list), sizeof(in.s_addr));

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
For additional commands, e-mail: php-dev-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>