Skip to content

Commit 4737399

Browse files
replace gethostbyname with getaddrinfo
#217
1 parent 11809e3 commit 4737399

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/common/networking.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ void ffNetworkingGetHttp(const char* host, const char* path, uint32_t timeout, F
1111
struct addrinfo hints = {0};
1212
hints.ai_family = AF_INET;
1313
hints.ai_socktype = SOCK_STREAM;
14-
hints.ai_protocol = 0;
1514

1615
struct addrinfo* addr;
1716

src/detection/title.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,25 @@ const FFTitleResult* ffDetectTitle(const FFinstance* instance)
2727
ffStrbufAppendS(&result.hostname, instance->state.utsname.nodename);
2828

2929
ffStrbufInitA(&result.fqdn, HOST_NAME_MAX);
30-
struct hostent* host = gethostbyname(result.hostname.chars);
31-
if(host != NULL)
32-
ffStrbufAppendS(&result.fqdn, host->h_name);
30+
31+
struct addrinfo hints = {0};
32+
hints.ai_socktype = SOCK_STREAM;
33+
hints.ai_flags = AI_CANONNAME;
34+
35+
struct addrinfo* info = NULL;
36+
37+
if(getaddrinfo(result.hostname.chars, "80", &hints, &info) == 0)
38+
{
39+
struct addrinfo* current = info;
40+
while(result.fqdn.length == 0 && current != NULL)
41+
{
42+
ffStrbufAppendS(&result.fqdn, current->ai_canonname);
43+
current = current->ai_next;
44+
}
45+
46+
freeaddrinfo(info);
47+
}
48+
3349
if(result.fqdn.length == 0)
3450
ffStrbufAppend(&result.fqdn, &result.hostname);
3551

0 commit comments

Comments
 (0)