Skip to content

Instantly share code, notes, and snippets.

@kristapsk
Created November 26, 2013 13:41
Show Gist options
  • Save kristapsk/7658381 to your computer and use it in GitHub Desktop.
Save kristapsk/7658381 to your computer and use it in GitHub Desktop.
--- ../hhvm/hphp/runtime/ext/ext_network.cpp 2013-11-26 14:42:19.630297106 +0200
+++ ext_network.cpp 2013-11-26 15:40:24.176773807 +0200
@@ -100,28 +100,14 @@
IMPLEMENT_THREAD_LOCAL(ResolverInit, ResolverInit::s_res);
Variant f_gethostname() {
- struct addrinfo hints, *res;
- char h_name[NI_MAXHOST];
- int error;
- String canon_hname;
+ char buf[HOST_NAME_MAX];
- error = gethostname(h_name, NI_MAXHOST);
- if (error) {
+ if (gethostname(buf, sizeof(buf) - 1)) {
+ raise_warning("unable to fetch host [%d]: %s", errno, strerror(errno));
return false;
}
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = AF_UNSPEC;
- hints.ai_flags = AI_CANONNAME;
-
- error = getaddrinfo(h_name, NULL, &hints, &res);
- if (error) {
- return String(h_name, CopyString);
- }
-
- canon_hname = String(res->ai_canonname, CopyString);
- freeaddrinfo(res);
- return canon_hname;
+ return String(buf);
}
Variant f_gethostbyaddr(const String& ip_address) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment