|
|
a856a8 |
diff --git a/runtime/net.c b/runtime/net.c
|
|
|
a856a8 |
index 3610fc5..2d8de94 100644
|
|
|
a856a8 |
--- a/runtime/net.c
|
|
|
a856a8 |
+++ b/runtime/net.c
|
|
|
a856a8 |
@@ -1181,26 +1181,24 @@ getLocalHostname(uchar **ppName)
|
|
|
a856a8 |
}
|
|
|
a856a8 |
|
|
|
a856a8 |
char *dot = strstr(hnbuf, ".");
|
|
|
a856a8 |
+ struct addrinfo *res = NULL;
|
|
|
a856a8 |
if(!empty_hostname && dot == NULL) {
|
|
|
a856a8 |
/* we need to (try) to find the real name via resolver */
|
|
|
a856a8 |
- struct hostent *hent = gethostbyname((char*)hnbuf);
|
|
|
a856a8 |
- if(hent) {
|
|
|
a856a8 |
- int i = 0;
|
|
|
a856a8 |
- if(hent->h_aliases) {
|
|
|
a856a8 |
- const size_t hnlen = strlen(hnbuf);
|
|
|
a856a8 |
- for(i = 0; hent->h_aliases[i]; i++) {
|
|
|
a856a8 |
- if(!strncmp(hent->h_aliases[i], hnbuf, hnlen)
|
|
|
a856a8 |
- && hent->h_aliases[i][hnlen] == '.') {
|
|
|
a856a8 |
- break; /* match! */
|
|
|
a856a8 |
- }
|
|
|
a856a8 |
- }
|
|
|
a856a8 |
- }
|
|
|
a856a8 |
- if(hent->h_aliases && hent->h_aliases[i]) {
|
|
|
a856a8 |
- CHKmalloc(fqdn = (uchar*)strdup(hent->h_aliases[i]));
|
|
|
a856a8 |
- } else {
|
|
|
a856a8 |
- CHKmalloc(fqdn = (uchar*)strdup(hent->h_name));
|
|
|
a856a8 |
+ struct addrinfo flags;
|
|
|
a856a8 |
+ memset(&flags, 0, sizeof(flags));
|
|
|
a856a8 |
+ flags.ai_flags = AI_CANONNAME;
|
|
|
a856a8 |
+ int error = getaddrinfo((char*)hnbuf, NULL, &flags, &res;;
|
|
|
a856a8 |
+ if (error != 0) {
|
|
|
a856a8 |
+ dbgprintf("getaddrinfo: %s\n", gai_strerror(error));
|
|
|
a856a8 |
+ ABORT_FINALIZE(RS_RET_IO_ERROR);
|
|
|
a856a8 |
+ }
|
|
|
a856a8 |
+ if (res != NULL) {
|
|
|
a856a8 |
+ /* When AI_CANONNAME is set first member of res linked-list */
|
|
|
a856a8 |
+ /* should contain what we need */
|
|
|
a856a8 |
+ if (res->ai_canonname != NULL && res->ai_canonname[0] != '\0') {
|
|
|
a856a8 |
+ CHKmalloc(fqdn = (uchar*)strdup(res->ai_canonname));
|
|
|
a856a8 |
+ dot = strstr((char*)fqdn, ".");
|
|
|
a856a8 |
}
|
|
|
a856a8 |
- dot = strstr((char*)fqdn, ".");
|
|
|
a856a8 |
}
|
|
|
a856a8 |
}
|
|
|
a856a8 |
|
|
|
a856a8 |
@@ -1215,6 +1213,9 @@ getLocalHostname(uchar **ppName)
|
|
|
a856a8 |
|
|
|
a856a8 |
*ppName = fqdn;
|
|
|
a856a8 |
finalize_it:
|
|
|
a856a8 |
+ if (res != NULL) {
|
|
|
a856a8 |
+ freeaddrinfo(res);
|
|
|
a856a8 |
+ }
|
|
|
a856a8 |
RETiRet;
|
|
|
a856a8 |
}
|
|
|
a856a8 |
|