--- sbbs/src/xpdev/netwrap.c 2018/04/24 16:41:24 1.1 +++ sbbs/src/xpdev/netwrap.c 2018/04/24 16:45:35 1.1.1.2 @@ -2,13 +2,13 @@ /* Network related wrapper functions */ -/* $Id: netwrap.c,v 1.1 2018/04/24 16:41:24 root Exp $ */ +/* $Id: netwrap.c,v 1.1.1.2 2018/04/24 16:45:35 root Exp $ */ /**************************************************************************** * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2009 Rob Swindell - http://www.synchro.net/copyright.html * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public License * @@ -37,8 +37,10 @@ #include "genwrap.h" /* truncsp */ #include "netwrap.h" /* verify prototypes */ +#include "sockwrap.h" #include /* malloc() */ +#include /* isspace() */ #if defined(_WIN32) #include /* GetNetworkParams */ @@ -95,6 +97,29 @@ str_list_t getNameServerList(void) #endif } +const char* getHostNameByAddr(const char* str) +{ + HOSTENT* h; + uint32_t ip; + +#ifdef _WIN32 + WSADATA wsaData; + WSAStartup(MAKEWORD(2, 2), &wsaData); +#endif + if(str==NULL) + return NULL; + if((ip=inet_addr(str)) == INADDR_NONE) + return str; + if((h=gethostbyaddr((char *)&ip,sizeof(ip),AF_INET))==NULL) + return NULL; + +#ifdef _WIN32 + WSACleanup(); +#endif + + return h->h_name; +} + /* In case we want to DLL-export getNameServerList in the future */ void freeNameServerList(str_list_t list) { @@ -102,7 +127,7 @@ void freeNameServerList(str_list_t list) } #if NETWRAP_TEST -int main(void) +int main(int argc, char** argv) { size_t i; str_list_t list; @@ -113,6 +138,8 @@ int main(void) freeNameServerList(list); } + if(argc>1) + printf("%s\n", getHostNameByAddr(argv[1])); return 0; } #endif