Skip to content

Commit

Permalink
Fixed local dns lookup on macOS GitHub instances.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmoinvaz committed Dec 12, 2023
1 parent 8d75d9c commit 5faa75a
Showing 1 changed file with 10 additions and 28 deletions.
38 changes: 10 additions & 28 deletions net_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,12 @@ static char *dns_resolve_filter(const char *host, int32_t family, uint8_t max_ad
size_t ai_string_len = 0;
int32_t err = 0;

// If no host supplied, then use local machine name
if (!host) {
err = gethostname(name, sizeof(name));
if (err != 0)
goto dns_resolve_error;
} else {
// Otherwise copy the host provided
strncat(name, host, sizeof(name) - 1);
}

hints.ai_flags = AI_NUMERICHOST;
hints.ai_family = PF_UNSPEC;
if (!host)
hints.ai_flags = AI_PASSIVE;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;

err = getaddrinfo(name, NULL, &hints, &address_info);
if (err != EAI_NONAME) {
if (err != 0)
goto dns_resolve_error;

// Name is already an IP address
freeaddrinfo(address_info);
return strdup(name);
}

hints.ai_flags = 0;
err = getaddrinfo(name, NULL, &hints, &address_info);
err = getaddrinfo(host, "http", &hints, &address_info);
if (err != 0)
goto dns_resolve_error;

Expand Down Expand Up @@ -87,11 +66,14 @@ static char *dns_resolve_filter(const char *host, int32_t family, uint8_t max_ad
if (ai_string_len >= max_ai_string)
break;

// Copy address name into return string
// Copy address name into numeric host
err = getnameinfo(address->ai_addr, (socklen_t)address->ai_addrlen, ai_string + ai_string_len,
(uint32_t)(max_ai_string - ai_string_len), NULL, 0, NI_NUMERICHOST);
if (err != 0)
goto dns_resolve_error;
if (err != 0) {
if (ai_string_len < max_ai_string)
ai_string[ai_string_len] = 0;
continue;

Check warning on line 75 in net_util.c

View check run for this annotation

Codecov / codecov/patch

net_util.c#L74-L75

Added lines #L74 - L75 were not covered by tests
}

max_addrs--;

Expand Down

0 comments on commit 5faa75a

Please sign in to comment.