Here is a pretty simple patch that will provide the indicated function. If no one objects I'll commit it to 5.3/6 branches in the next day or two.

Index: ext/standard/dns.c
===================================================================
RCS file: /repository/php-src/ext/standard/dns.c,v
retrieving revision 1.70.2.7.2.5.2.8
diff -u -p -a -d -r1.70.2.7.2.5.2.8 dns.c
--- ext/standard/dns.c  3 Nov 2008 11:35:11 -0000       1.70.2.7.2.5.2.8
+++ ext/standard/dns.c  29 Dec 2008 23:28:59 -0000
@@ -107,6 +107,27 @@
 static char *php_gethostbyaddr(char *ip);
 static char *php_gethostbyname(char *name);
 
+#ifdef HAVE_GETHOSTNAME
+/* {{{ proto string gethostname()
+   Get the host name of the current machine */
+PHP_FUNCTION(gethostname)
+{
+       char buf[4096];
+
+       if (ZEND_NUM_ARGS()) {
+               WRONG_PARAM_COUNT;
+       }
+
+       if (gethostname(buf, sizeof(buf) - 1)) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to fetch 
host [%d]: %s", errno, strerror(errno));
+               RETURN_FALSE;
+       }
+
+       RETURN_STRING(buf, 1);
+}
+/* }}} */
+#endif
+
 /* {{{ proto string gethostbyaddr(string ip_address)
    Get the Internet host name corresponding to a given IP address */
 PHP_FUNCTION(gethostbyaddr)
@@ -134,6 +155,7 @@ PHP_FUNCTION(gethostbyaddr)
 }
 /* }}} */
 
+
 /* {{{ php_gethostbyaddr */
 static char *php_gethostbyaddr(char *ip)
 {
Index: ext/standard/dns.h
===================================================================
RCS file: /repository/php-src/ext/standard/dns.h,v
retrieving revision 1.19.2.1.2.1.2.1
diff -u -p -a -d -r1.19.2.1.2.1.2.1 dns.h
--- ext/standard/dns.h  31 Dec 2007 07:17:14 -0000      1.19.2.1.2.1.2.1
+++ ext/standard/dns.h  29 Dec 2008 23:28:59 -0000
@@ -31,6 +31,10 @@ PHP_FUNCTION(gethostbyaddr);
 PHP_FUNCTION(gethostbyname);
 PHP_FUNCTION(gethostbynamel);
 
+#ifdef HAVE_GETHOSTNAME
+PHP_FUNCTION(gethostname);
+#endif
+
 #if HAVE_RES_SEARCH && !(defined(__BEOS__)||defined(PHP_WIN32))
 
 PHP_FUNCTION(dns_check_record);
Index: ext/standard/basic_functions.c
===================================================================
RCS file: /repository/php-src/ext/standard/basic_functions.c,v
retrieving revision 1.725.2.31.2.64.2.78
diff -u -p -a -d -r1.725.2.31.2.64.2.78 basic_functions.c
--- ext/standard/basic_functions.c      2 Dec 2008 16:27:14 -0000       
1.725.2.31.2.64.2.78
+++ ext/standard/basic_functions.c      29 Dec 2008 23:28:59 -0000
@@ -991,6 +991,11 @@ ZEND_BEGIN_ARG_INFO(arginfo_gethostbynam
        ZEND_ARG_INFO(0, hostname)
 ZEND_END_ARG_INFO()
 
+#ifdef HAVE_GETHOSTNAME
+ZEND_BEGIN_ARG_INFO(arginfo_gethostname, 0)
+ZEND_END_ARG_INFO()
+#endif
+
 #if HAVE_RES_SEARCH && !(defined(__BEOS__)||defined(PHP_WIN32) || 
defined(NETWARE))
 ZEND_BEGIN_ARG_INFO_EX(arginfo_dns_check_record, 0, 0, 1)
        ZEND_ARG_INFO(0, host)
@@ -2990,6 +2995,10 @@ const zend_function_entry basic_function
        PHP_FE(gethostbyname,                                                   
                                                arginfo_gethostbyname)
        PHP_FE(gethostbynamel,                                                  
                                                arginfo_gethostbynamel)
 
+#ifdef HAVE_GETHOSTNAME
+       PHP_FE(gethostname,                                                     
                                                arginfo_gethostname)
+#endif
+
 #if HAVE_RES_SEARCH && !(defined(__BEOS__) || defined(PHP_WIN32) || 
defined(NETWARE))
        PHP_FE(dns_check_record,                                                
                                                arginfo_dns_check_record)
        PHP_FALIAS(checkdnsrr,                  dns_check_record,               
                                arginfo_dns_check_record)
Index: configure.in
===================================================================
RCS file: /repository/php-src/configure.in,v
retrieving revision 1.579.2.52.2.77.2.38
diff -u -p -a -d -r1.579.2.52.2.77.2.38 configure.in
--- configure.in        12 Dec 2008 23:43:17 -0000      1.579.2.52.2.77.2.38
+++ configure.in        29 Dec 2008 23:29:00 -0000
@@ -575,6 +575,7 @@ getprotobyname \
 getprotobynumber \
 getservbyname \
 getservbyport \
+gethostname \
 getrusage \
 gettimeofday \
 gmtime_r \




On 29-Dec-08, at 4:45 PM, Daniel Brown wrote:

On Mon, Dec 29, 2008 at 16:26, Brian A. Seklecki
<laval...@spiritual-machines.org> wrote:

All:

Is anyone interested in adding POSIX 1003.1-2001 gethostname(2) support? I'm
interested in sponsoring a small contract development initiative.

I need something more reliable than $_ENV[].   Not all shells export
$HOSTNAME by default.

   Brian,

   As you most likely mean the core engine, Brian, this email is
being forwarded to the Internals mailing list.  If you haven't
already, please consider subscribing to that list by sending a blank
email to intern...@lists.php.net.

--
</Daniel P. Brown>
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Unadvertised dedicated server deals, too low to print - email me to find out!

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php


Ilia Alshanetsky





-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to