ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
dns.c
Go to the documentation of this file.
6
7#include <ascii-chat/otel.h>
10#include <ascii-chat/log/log.h>
11#include <string.h>
12
13bool dns_test_connectivity(const char *hostname) {
14 ASCII_OTEL_SCOPE(DNS_TEST_CONNECTIVITY);
15 if (!hostname) {
16 log_warn("NULL hostname provided to DNS connectivity test");
17 return false;
18 }
19
20 char ascii_hostname[HOSTNAME_BUFFER_SIZE];
21 asciichat_error_t normalized = hostname_to_ascii(hostname, ascii_hostname, sizeof(ascii_hostname));
22 if (normalized != ASCIICHAT_OK)
23 return false;
24 hostname = ascii_hostname;
25
26 struct addrinfo hints, *result = NULL;
27 memset(&hints, 0, sizeof(hints));
28 /* Connectivity is not IPv4-specific. Restricting this probe to AF_INET
29 * reports a false DNS failure on IPv6-only or IPv6-preferred networks even
30 * though the HTTP client can connect successfully. */
31 hints.ai_family = AF_UNSPEC;
32 hints.ai_socktype = SOCK_STREAM;
33
34 log_debug("Testing DNS connectivity to %s...", hostname);
35 log_debug("★ ABOUT TO CALL getaddrinfo for %s", hostname);
36
37 /* Resolve the same service used by the update request. Passing a NULL
38 * service is rejected by some Windows resolver configurations even though
39 * hostname resolution itself is healthy. */
40 int ret = getaddrinfo(hostname, "443", &hints, &result);
41 log_debug("★ getaddrinfo returned %d", ret);
42 if (ret != 0) {
43 log_warn("DNS resolution failed for %s: %s", hostname, gai_strerror(ret));
44 return false;
45 }
46
47 if (result) {
48 freeaddrinfo(result);
49 }
50
51 log_debug("DNS connectivity test succeeded for %s", hostname);
52 return true;
53}
🌐 DNS resolution utilities
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:48
@ ASCIICHAT_OK
Definition error_codes.h:50
#define HOSTNAME_BUFFER_SIZE
#define log_warn(...)
Log a WARN message.
Definition log/log.h:615
#define log_debug(...)
Log a DEBUG message.
Definition log/log.h:589
bool dns_test_connectivity(const char *hostname)
Test DNS connectivity by resolving a hostname.
Definition dns.c:13
asciichat_error_t hostname_to_ascii(const char *hostname, char *output, size_t capacity)
Definition url.c:103
📝 Logging API with multiple log levels and terminal output control
#define ASCII_OTEL_SCOPE(id)
Definition otel.h:77
🔤 String Manipulation and Shell Escaping Utilities
🌐 Production-Grade URL Validation and Parsing