Skip to content

Commit

Permalink
test 4
Browse files Browse the repository at this point in the history
  • Loading branch information
nmoinvaz committed Dec 12, 2023
1 parent 7e17b5f commit 896c7df
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions net_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,44 @@
// Resolve a host name to its addresses with a filter and custom separator
static char *dns_resolve_filter(const char *host, int32_t family, uint8_t max_addrs, int32_t *error) {
char name[HOST_MAX] = {0};
struct addrinfo hints = {0};
struct addrinfo *address_info = NULL;
struct addrinfo *address = NULL;
char *ai_string = NULL;
size_t ai_string_len = 0;
int32_t err = 0;

// If no host supplied, then use local machine name
if (!host) {
/*if (!host) {
err = gethostname(name, sizeof(name));
if (err != 0) {
LOG_ERROR("gethostname fail \n");

goto dns_resolve_error;
}
LOG_ERROR("gethostname: %s\n", name);
} else {
// Otherwise copy the host provided
strncat(name, host, sizeof(name) - 1);
}*/
hints.ai_flags = AI_NUMERICHOST;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
if (!host)
hints.ai_flags |= AI_PASSIVE;

err = getaddrinfo(host, 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(host);
}
err = getaddrinfo(name, NULL, NULL, &address_info);
hints.ai_flags = 0;
err = getaddrinfo(host, NULL, NULL, &address_info);*/
if (err != 0) {
LOG_ERROR("getaddr fail\n");
goto dns_resolve_error;
Expand Down

0 comments on commit 896c7df

Please sign in to comment.