From 5f99e20af8ee089d76eb6e7ed42620a750c5fef6 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sun, 10 Jun 2012 20:03:44 -0400 Subject: [PATCH] Toss pnAddrInfo (one less project!) --- Sources/Plasma/Apps/plClient/CMakeLists.txt | 1 - Sources/Plasma/NucleusLib/CMakeLists.txt | 1 - .../NucleusLib/pnAddrInfo/CMakeLists.txt | 18 -- .../NucleusLib/pnAddrInfo/pnAddrInfo.cpp | 179 ------------------ .../Plasma/NucleusLib/pnAddrInfo/pnAddrInfo.h | 83 -------- .../NucleusLib/pnNetCommon/CMakeLists.txt | 5 +- .../NucleusLib/pnNetCommon/pnNetCommon.cpp | 22 ++- Sources/Tools/MaxMain/CMakeLists.txt | 1 - Sources/Tools/MaxPlasmaLights/CMakeLists.txt | 1 - Sources/Tools/plResBrowser/CMakeLists.txt | 1 - 10 files changed, 18 insertions(+), 294 deletions(-) delete mode 100644 Sources/Plasma/NucleusLib/pnAddrInfo/CMakeLists.txt delete mode 100644 Sources/Plasma/NucleusLib/pnAddrInfo/pnAddrInfo.cpp delete mode 100644 Sources/Plasma/NucleusLib/pnAddrInfo/pnAddrInfo.h diff --git a/Sources/Plasma/Apps/plClient/CMakeLists.txt b/Sources/Plasma/Apps/plClient/CMakeLists.txt index 55e903c7..43d9c7d4 100644 --- a/Sources/Plasma/Apps/plClient/CMakeLists.txt +++ b/Sources/Plasma/Apps/plClient/CMakeLists.txt @@ -134,7 +134,6 @@ target_link_libraries(plClient plSurface) target_link_libraries(plClient plTransform) target_link_libraries(plClient plUnifiedTime) target_link_libraries(plClient plVault) -target_link_libraries(plClient pnAddrInfo) target_link_libraries(plClient pnAsyncCore) target_link_libraries(plClient pnAsyncCoreExe) target_link_libraries(plClient pnDispatch) diff --git a/Sources/Plasma/NucleusLib/CMakeLists.txt b/Sources/Plasma/NucleusLib/CMakeLists.txt index 06e94361..1aa3653e 100644 --- a/Sources/Plasma/NucleusLib/CMakeLists.txt +++ b/Sources/Plasma/NucleusLib/CMakeLists.txt @@ -1,7 +1,6 @@ add_definitions(-D_LIB) add_subdirectory(inc) -add_subdirectory(pnAddrInfo) add_subdirectory(pnAsyncCore) add_subdirectory(pnAsyncCoreExe) add_subdirectory(pnDispatch) diff --git a/Sources/Plasma/NucleusLib/pnAddrInfo/CMakeLists.txt b/Sources/Plasma/NucleusLib/pnAddrInfo/CMakeLists.txt deleted file mode 100644 index 94d2e4ad..00000000 --- a/Sources/Plasma/NucleusLib/pnAddrInfo/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -include_directories(../../CoreLib) - -set(pnAddrInfo_SOURCES - pnAddrInfo.cpp -) - -set(pnAddrInfo_HEADERS - pnAddrInfo.h -) - -add_library(pnAddrInfo STATIC ${pnAddrInfo_SOURCES} ${pnAddrInfo_HEADERS}) -target_link_libraries(pnAddrInfo CoreLib) -if(WIN32) - target_link_libraries(pnAddrInfo ws2_32) -endif(WIN32) - -source_group("Source Files" FILES ${pnAddrInfo_SOURCES}) -source_group("Header Files" FILES ${pnAddrInfo_HEADERS}) diff --git a/Sources/Plasma/NucleusLib/pnAddrInfo/pnAddrInfo.cpp b/Sources/Plasma/NucleusLib/pnAddrInfo/pnAddrInfo.cpp deleted file mode 100644 index 8d5801b8..00000000 --- a/Sources/Plasma/NucleusLib/pnAddrInfo/pnAddrInfo.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -#ifndef SERVER - - -#include "HeadSpin.h" -#include "pnAddrInfo.h" -#include - -#if HS_BUILD_FOR_UNIX -# include -# include -# include -# include -# include -#endif - -const pnAddrInfo* pnAddrInfo::GetInterface() -{ - static pnAddrInfo addrinfo; - return &addrinfo; -} - -struct addrinfo* pnAddrInfo::GetAddrByNameSimple(const char* name, const int family) -{ - struct addrinfo* info; - struct addrinfo hints; - memset(&hints,0,sizeof(hints)); - hints.ai_family = family; - hints.ai_flags = AI_CANONNAME; - if (Get(name,NULL,&hints,&info) != 0) - info = NULL; - return info; -}; - -int pnAddrInfo::Get(const char* node, const char* service, const struct addrinfo* hints, struct addrinfo** res) -{ - return getaddrinfo(node,service,hints,res); -} - -void pnAddrInfo::Free(struct addrinfo* res) -{ - freeaddrinfo(res); -} - -const char* pnAddrInfo::GetErrorString(int errcode) -{ - return gai_strerror(errcode); -} - -////////////////////////////////// -//// UNIX -////////////////////////////////// - -#if HS_BUILD_FOR_UNIX -pnAddrInfo::pnAddrInfo() -{ -} - -pnAddrInfo::~pnAddrInfo() -{ -} - -void pnAddrInfo::GetLocalAddrs(List& addrslist, bool incLoopBack) -{ - struct ifconf info; - struct ifreq infos[128]; - - info.ifc_len = sizeof(infos); - info.ifc_req = infos; - - int s = socket(AF_INET, SOCK_DGRAM, 0); - - if (ioctl(s,SIOCGIFCONF,&info) == 0) - { - int i; - int entries = info.ifc_len / sizeof(struct ifreq); - - for (i = 0; i < entries; i++) - { - struct in_addr addr = ((struct sockaddr_in *)&(infos[i].ifr_addr))->sin_addr; - - if (incLoopBack || (addr.s_addr != htonl(INADDR_LOOPBACK))) - { - addrslist.push_back(inet_ntoa(addr)); - } - } - } - - close(s); -} - -#endif - -//////////////////////////////////// -//// Windows -//////////////////////////////////// - -#if HS_BUILD_FOR_WIN32 -pnAddrInfo::pnAddrInfo() -{ - WSADATA data; - WSAStartup(MAKEWORD( 2, 2 ), &data); -} - -pnAddrInfo::~pnAddrInfo() -{ - WSACleanup(); -} - -void pnAddrInfo::GetLocalAddrs(List& addrslist, bool incLoopBack) -{ - INTERFACE_INFO infos[128]; // get at most 128 interfaces - const unsigned int bufSize = sizeof(infos); - DWORD retSize; - - SOCKET s = socket(AF_INET, SOCK_DGRAM, 0); - - if (WSAIoctl(s, SIO_GET_INTERFACE_LIST, NULL, 0, - (void*)infos, bufSize, &retSize, NULL, NULL) == 0) - { - unsigned int entries = retSize/sizeof(INTERFACE_INFO); - int i; - for (i = 0; i < entries; i++) - { - if (infos[i].iiFlags & IFF_UP) - { - struct in_addr addr = infos[i].iiAddress.AddressIn.sin_addr; - if (incLoopBack || (addr.s_addr != htonl(INADDR_LOOPBACK))) - addrslist.push_back(inet_ntoa(addr)); - } - } - } - - closesocket(s); -} -#endif - - -#endif // SERVER diff --git a/Sources/Plasma/NucleusLib/pnAddrInfo/pnAddrInfo.h b/Sources/Plasma/NucleusLib/pnAddrInfo/pnAddrInfo.h deleted file mode 100644 index 6fb1112e..00000000 --- a/Sources/Plasma/NucleusLib/pnAddrInfo/pnAddrInfo.h +++ /dev/null @@ -1,83 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -#ifndef PN_ADDR_INFO_H -#define PN_ADDR_INFO_H - -#ifndef SERVER - -// A wrapper library for getaddrinfo -// made to support Windows 98, Me, 2k -// Unix and XP use native code - -#if HS_BUILD_FOR_UNIX -# include -# include -# include -#elif !defined(HS_BUILD_FOR_WIN32) -# error "pnAddrInfo Not Implemented!" -#endif - -#include "HeadSpin.h" -#include "hsStlUtils.h" - - -class pnAddrInfo -{ -public: - typedef std::list List; - - pnAddrInfo(); - ~pnAddrInfo(); - - static const pnAddrInfo* GetInterface(); - - static struct addrinfo* GetAddrByNameSimple(const char* name, const int family = PF_INET); - static int Get(const char* node, const char* service, const struct addrinfo* hints, struct addrinfo** res); - static const char* GetErrorString(int errcode); - static void Free(struct addrinfo* res); - - static void GetLocalAddrs(List& addrslist, bool incLoopBack = false); -}; - -#endif // SERVER - -#endif // PN_ADDR_INFO_H diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/CMakeLists.txt b/Sources/Plasma/NucleusLib/pnNetCommon/CMakeLists.txt index 13974a33..29e1ac1d 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/CMakeLists.txt +++ b/Sources/Plasma/NucleusLib/pnNetCommon/CMakeLists.txt @@ -34,7 +34,10 @@ set(pnNetCommon_SOURCES ) add_library(pnNetCommon STATIC ${pnNetCommon_HEADERS} ${pnNetCommon_SOURCES}) -target_link_libraries(pnNetCommon pnAddrInfo plStatusLog) +target_link_libraries(pnNetCommon plStatusLog) +if(WIN32) + target_link_libraries(pnNetCommon Ws2_32) +endif(WIN32) source_group("Header Files" FILES ${pnNetCommon_HEADERS}) source_group("Source Files" FILES ${pnNetCommon_SOURCES}) diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/pnNetCommon.cpp b/Sources/Plasma/NucleusLib/pnNetCommon/pnNetCommon.cpp index 566c6f35..0302cd06 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/pnNetCommon.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCommon/pnNetCommon.cpp @@ -40,7 +40,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include "pnNetCommon.h" -#include "pnAddrInfo/pnAddrInfo.h" + #if HS_BUILD_FOR_UNIX # include # include @@ -68,19 +68,25 @@ plString GetTextAddr(uint32_t binAddr) uint32_t GetBinAddr(const char * textAddr) { uint32_t addr = 0; - if (!textAddr) return addr; - struct addrinfo* ai = NULL; - addr = inet_addr(textAddr); if(addr == INADDR_NONE) { - ai = pnAddrInfo::GetAddrByNameSimple(textAddr); - if(ai!= NULL) - memcpy(&addr,(void*)(&(((sockaddr_in*)(ai->ai_addr))->sin_addr)),sizeof(addr)); - pnAddrInfo::Free(ai); + struct addrinfo* ai = nil; + struct addrinfo hints; + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = PF_INET; + hints.ai_flags = AI_CANONNAME; + if (getaddrinfo(textAddr, nil, &hints, &ai) != 0) + { + hsAssert(false, "getaddrinfo failed"); + return addr; + } + + memcpy(&addr, (void*)(&(((sockaddr_in*)(ai->ai_addr))->sin_addr)), sizeof(addr)); + freeaddrinfo(ai); } return addr; diff --git a/Sources/Tools/MaxMain/CMakeLists.txt b/Sources/Tools/MaxMain/CMakeLists.txt index 8eb3773f..9c14a9d5 100644 --- a/Sources/Tools/MaxMain/CMakeLists.txt +++ b/Sources/Tools/MaxMain/CMakeLists.txt @@ -171,7 +171,6 @@ target_link_libraries(MaxMain plSurface) target_link_libraries(MaxMain plTransform) target_link_libraries(MaxMain plUnifiedTime) target_link_libraries(MaxMain plVault) -target_link_libraries(MaxMain pnAddrInfo) target_link_libraries(MaxMain pnAsyncCore) target_link_libraries(MaxMain pnAsyncCoreExe) target_link_libraries(MaxMain pnDispatch) diff --git a/Sources/Tools/MaxPlasmaLights/CMakeLists.txt b/Sources/Tools/MaxPlasmaLights/CMakeLists.txt index 0506efa1..02f0188c 100644 --- a/Sources/Tools/MaxPlasmaLights/CMakeLists.txt +++ b/Sources/Tools/MaxPlasmaLights/CMakeLists.txt @@ -104,7 +104,6 @@ target_link_libraries(MaxPlasmaLights plSurface) target_link_libraries(MaxPlasmaLights plTransform) target_link_libraries(MaxPlasmaLights plUnifiedTime) target_link_libraries(MaxPlasmaLights plVault) -target_link_libraries(MaxPlasmaLights pnAddrInfo) target_link_libraries(MaxPlasmaLights pnAsyncCore) target_link_libraries(MaxPlasmaLights pnAsyncCoreExe) target_link_libraries(MaxPlasmaLights pnDispatch) diff --git a/Sources/Tools/plResBrowser/CMakeLists.txt b/Sources/Tools/plResBrowser/CMakeLists.txt index 7291b2d0..f913d6cf 100644 --- a/Sources/Tools/plResBrowser/CMakeLists.txt +++ b/Sources/Tools/plResBrowser/CMakeLists.txt @@ -40,7 +40,6 @@ target_link_libraries(plResBrowser plResMgr) target_link_libraries(plResBrowser plScene) target_link_libraries(plResBrowser plStatusLog) target_link_libraries(plResBrowser plUnifiedTime) -target_link_libraries(plResBrowser pnAddrInfo) target_link_libraries(plResBrowser pnDispatch) target_link_libraries(plResBrowser pnFactory) target_link_libraries(plResBrowser pnKeyedObject)