]> granicus.if.org Git - php/commitdiff
MFB: Added gethostname() to return the current system host name.
authorIlia Alshanetsky <iliaa@php.net>
Wed, 31 Dec 2008 14:33:41 +0000 (14:33 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Wed, 31 Dec 2008 14:33:41 +0000 (14:33 +0000)
configure.in
ext/standard/basic_functions.c
ext/standard/dns.c
ext/standard/dns.h

index 861ef41cde2ad445477d02af0b29bff616fd046f..f0092397a6f063802ce9e480b618cb7f231a9138 100644 (file)
@@ -575,6 +575,7 @@ getprotobyname \
 getprotobynumber \
 getservbyname \
 getservbyport \
+gethostname \
 getrusage \
 gettimeofday \
 gmtime_r \
index baad25677597b3f404a7503c4281a5604a495f97..2ca86276896136b85b409964e12b82955945c228 100644 (file)
@@ -980,6 +980,11 @@ ZEND_BEGIN_ARG_INFO(arginfo_gethostbynamel, 0)
        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)
@@ -3006,6 +3011,10 @@ const zend_function_entry basic_functions[] = { /* {{{ */
        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 0967b1bd19cf6750b7c9c0e325be9fc9e49a7c74..68db592597254b2044fa0fa29a068837e9b205cd 100644 (file)
 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_parse_parameters_none() == FAILURE) {
+               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) U
    Get the Internet host name corresponding to a given IP address */
 PHP_FUNCTION(gethostbyaddr)
@@ -134,6 +156,7 @@ PHP_FUNCTION(gethostbyaddr)
 }
 /* }}} */
 
+
 /* {{{ php_gethostbyaddr */
 static char *php_gethostbyaddr(char *ip)
 {
index 38386879a1cd1768a440604563618728584cd060..3d1a1b21b9357c21efb99353985f3c276222cc9f 100644 (file)
@@ -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);