summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2008-12-31 14:33:41 +0000
committerIlia Alshanetsky <iliaa@php.net>2008-12-31 14:33:41 +0000
commit15aada4fa214f5a54f84c0b885603a1701150a68 (patch)
tree970713e09afdf7589d94156ea172b75c8e832b31
parentc2d1b06567c46d33c4c669b1008b46808b4ae07d (diff)
downloadphp-git-15aada4fa214f5a54f84c0b885603a1701150a68.tar.gz
MFB: Added gethostname() to return the current system host name.
-rw-r--r--configure.in1
-rw-r--r--ext/standard/basic_functions.c9
-rw-r--r--ext/standard/dns.c23
-rw-r--r--ext/standard/dns.h4
4 files changed, 37 insertions, 0 deletions
diff --git a/configure.in b/configure.in
index 861ef41cde..f0092397a6 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 baad256775..2ca8627689 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -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)
diff --git a/ext/standard/dns.c b/ext/standard/dns.c
index 0967b1bd19..68db592597 100644
--- a/ext/standard/dns.c
+++ b/ext/standard/dns.c
@@ -107,6 +107,28 @@
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)
{
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);