From 30751aece04ba8954513bbb7aca996244e6fa684 Mon Sep 17 00:00:00 2001 From: bonmas14 Date: Sun, 28 Sep 2025 17:53:03 +0000 Subject: changes --- src/d_linux.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/d_linux.c (limited to 'src/d_linux.c') diff --git a/src/d_linux.c b/src/d_linux.c new file mode 100644 index 0000000..5ff6abd --- /dev/null +++ b/src/d_linux.c @@ -0,0 +1,56 @@ +typedef struct DHandle { + u64 type; +} DHandle; + +b32 d_init(void) { + return true; +} + +String d_hostname_ip_get(String host, Allocator alloc) { + char *host_cstr; + Allocator talloc; + int err; + String ip; + + talloc = un_alloc_temp_get(); + host_cstr = (char *) un_string_to_cstring(host, talloc); + + // @note, host_info can return multiple ip addresses? + struct hostent *host_info = gethostbyname(host_cstr); + + if (!host_info) { + err = h_errno; + + switch (err) { + case TRY_AGAIN: + cyn_log_write_cstring(CYN_LOG_ERROR, (u8*) "d_get_hostname_ip: host not found (TRY_AGAIN)."); + break; + case HOST_NOT_FOUND: + cyn_log_write_cstring(CYN_LOG_ERROR, (u8*) "d_get_hostname_ip: host not found (HOST_NOT_FOUND)."); + break; + case NO_DATA: + cyn_log_write_cstring(CYN_LOG_ERROR, (u8*) "d_get_hostname_ip: no host data (NO_DATA)."); + break; + default: + cyn_log_write_cstring(CYN_LOG_ERROR, (u8*) "d_get_hostname_ip: unspecified error."); + break; + } + + return CLITERAL(String) { 0 }; + } + + if (host_info) { + assert(host_info->h_addrtype == AF_INET); + + assert(host_info->h_length >= (s32)sizeof(struct in_addr)); + ip = un_string_from_cstring(inet_ntoa(*(struct in_addr *)*host_info->h_addr_list)); + + return un_string_copy(ip, alloc); + } + + return CLITERAL(String) { 0 }; +} + +DHandle* d_tcp_connect(String ip, u16 port) { + +} -- cgit v1.2.3-70-g09d2