#include "net/resolve.h" #include #include #include #ifndef _WIN32 #include #include // gethostbyname #include #else #include #include #undef min #undef max #endif namespace net { void Init() { #ifdef _WIN32 WSADATA wsaData = {0}; WSAStartup(MAKEWORD(2, 2), &wsaData); #endif } void Shutdown() { #ifdef _WIN32 WSACleanup(); #endif } char *DNSResolve(const char *host) { struct hostent *hent; if((hent = gethostbyname(host)) == NULL) { perror("Can't get IP"); exit(1); } int iplen = 15; //XXX.XXX.XXX.XXX char *ip = (char *)malloc(iplen+1); memset(ip, 0, iplen+1); if(inet_ntop(AF_INET, (void *)hent->h_addr_list[0], ip, iplen) == NULL) { perror("Can't resolve host"); exit(1); } return ip; } }