+static inline char *localhostname(void)
+{
+ char hostname[1024] = {0};
+
+#ifdef PHP_WIN32
+ if (SUCCESS == gethostname(hostname, lenof(hostname))) {
+ return estrdup(hostname);
+ }
+#elif defined(HAVE_UNISTD_H)
+ if (SUCCESS == gethostname(hostname, lenof(hostname))) {
+ size_t hlen = strlen(hostname);
+
+ if (hlen <= lenof(hostname) - lenof("(none)")) {
+ hostname[hlen++] = '.';
+ if (SUCCESS == getdomainname(&hostname[hlen], lenof(hostname) - hlen)) {
+ if (!strcmp(&hostname[hlen], "(none)")) {
+ hostname[hlen - 1] = '\0';
+ }
+ return estrdup(hostname);
+ }
+ }
+ }
+#endif
+ return estrdup("localhost");
+}
+