ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
dns.c
Go to the documentation of this file.
1
9#include <string.h>
10
11bool dns_test_connectivity(const char *hostname) {
12 if (!hostname) {
13 log_warn("NULL hostname provided to DNS connectivity test");
14 return false;
15 }
16
17 struct addrinfo hints, *result = NULL;
18 memset(&hints, 0, sizeof(hints));
19 hints.ai_family = AF_INET; // IPv4
20 hints.ai_socktype = SOCK_STREAM;
21
22 log_debug("Testing DNS connectivity to %s...", hostname);
23 log_info("★ ABOUT TO CALL getaddrinfo for %s", hostname);
24
25 // Use NULL for port to avoid musl strtoul parsing bug with string port numbers
26 // The actual port doesn't matter for connectivity testing - we just need DNS resolution
27 int ret = getaddrinfo(hostname, NULL, &hints, &result);
28 log_info("★ getaddrinfo returned %d", ret);
29 if (ret != 0) {
30 log_warn("DNS resolution failed for %s: %s", hostname, gai_strerror(ret));
31 return false;
32 }
33
34 if (result) {
35 freeaddrinfo(result);
36 }
37
38 log_debug("DNS connectivity test succeeded for %s", hostname);
39 return true;
40}
🌐 DNS resolution utilities
#define log_warn(...)
Log a WARN message.
Definition log/log.h:574
#define log_info(...)
Log an INFO message.
Definition log/log.h:561
#define log_debug(...)
Log a DEBUG message.
Definition log/log.h:548
bool dns_test_connectivity(const char *hostname)
Test DNS connectivity by resolving a hostname.
Definition dns.c:11
📝 Logging API with multiple log levels and terminal output control
Cross-platform network headers and socket definitions.