From 540242dc2d5d316541c01e935c5bb12032d9368c Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Wed, 31 Dec 2008 14:30:38 +0000 Subject: [PATCH] [DOC] Added gethostname() to return the current system host name. --- NEWS | 1 + configure.in | 1 + ext/standard/basic_functions.c | 9 +++++++++ ext/standard/dns.c | 22 ++++++++++++++++++++++ ext/standard/dns.h | 4 ++++ win32/build/config.w32.h.in | 1 + 6 files changed, 38 insertions(+) diff --git a/NEWS b/NEWS index f579a7be07..a82f7828cd 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,7 @@ PHP NEWS - Added json_last_error() to return any error information from json_decode(). (Scott) +- Added gethostname() to return the current system host name. (Ilia) - Added shm_has_var() function. (Mike) - Added depth parameter to json_decode() to lower the nesting depth from the maximum if required. (Scott) diff --git a/configure.in b/configure.in index 11273a0d0e..d953676f95 100644 --- a/configure.in +++ b/configure.in @@ -575,6 +575,7 @@ getprotobyname \ getprotobynumber \ getservbyname \ getservbyport \ +gethostname \ getrusage \ gettimeofday \ gmtime_r \ diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index c986e8034c..0b8c19f480 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -991,6 +991,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) @@ -2990,6 +2995,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) diff --git a/ext/standard/dns.c b/ext/standard/dns.c index 89771d6439..8a61d1d321 100644 --- a/ext/standard/dns.c +++ b/ext/standard/dns.c @@ -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_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) 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) { diff --git a/ext/standard/dns.h b/ext/standard/dns.h index 38386879a1..3d1a1b21b9 100644 --- a/ext/standard/dns.h +++ b/ext/standard/dns.h @@ -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); diff --git a/win32/build/config.w32.h.in b/win32/build/config.w32.h.in index 820fe3fe8f..a2ebcec0f4 100644 --- a/win32/build/config.w32.h.in +++ b/win32/build/config.w32.h.in @@ -53,6 +53,7 @@ /* its in win32/time.c */ #define HAVE_USLEEP 1 +#define HAVE_GETHOSTNAME 1 #define HAVE_GETCWD 1 #define HAVE_POSIX_READDIR_R 1 #define NEED_ISBLANK 1 -- 2.50.1