#include #include #include #include #include #include const char *resolve_hostname_to_str(const char *hostname) { struct addrinfo *addrInfo; char str[INET_ADDRSTRLEN]; // Set up hints struct addrinfo hints; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_INET; //TODO: Care about IPv6 hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; hints.ai_flags = AI_CANONNAME; // Get addrinfo int error = getaddrinfo(hostname, "https", &hints, &addrInfo); if (addrInfo == NULL) return NULL; // Return addr struct sockaddr_in *addr = (struct sockaddr_in *)addrInfo->ai_addr; return inet_ntoa((struct in_addr)addr->sin_addr); }