Skip to content

Commit

Permalink
replace gethostbyname with getaddrinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusDierheimer committed Aug 21, 2022
1 parent 11809e3 commit 4737399
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/common/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ void ffNetworkingGetHttp(const char* host, const char* path, uint32_t timeout, F
struct addrinfo hints = {0};
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;

struct addrinfo* addr;

Expand Down
22 changes: 19 additions & 3 deletions src/detection/title.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,25 @@ const FFTitleResult* ffDetectTitle(const FFinstance* instance)
ffStrbufAppendS(&result.hostname, instance->state.utsname.nodename);

ffStrbufInitA(&result.fqdn, HOST_NAME_MAX);
struct hostent* host = gethostbyname(result.hostname.chars);
if(host != NULL)
ffStrbufAppendS(&result.fqdn, host->h_name);

struct addrinfo hints = {0};
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_CANONNAME;

struct addrinfo* info = NULL;

if(getaddrinfo(result.hostname.chars, "80", &hints, &info) == 0)
{
struct addrinfo* current = info;
while(result.fqdn.length == 0 && current != NULL)
{
ffStrbufAppendS(&result.fqdn, current->ai_canonname);
current = current->ai_next;
}

freeaddrinfo(info);
}

if(result.fqdn.length == 0)
ffStrbufAppend(&result.fqdn, &result.hostname);

Expand Down

0 comments on commit 4737399

Please sign in to comment.