diff --git a/source/shared_lib/CMakeLists.txt b/source/shared_lib/CMakeLists.txt index c3d9326d5..0d2b4da23 100644 --- a/source/shared_lib/CMakeLists.txt +++ b/source/shared_lib/CMakeLists.txt @@ -335,6 +335,12 @@ IF(BUILD_MEGAGLEST_MODEL_VIEWER OR BUILD_MEGAGLEST_MAP_EDITOR OR BUILD_MEGAGLEST MESSAGE(STATUS "EXTERNAL_LIBS = [${EXTERNAL_LIBS}]") + OPTION(BUILD_MEGAGLEST_UPNP_DEBUG "Build MegaGlest with UPNP DEBUG enabled" OFF) + IF(BUILD_MEGAGLEST_UPNP_DEBUG) + MESSAGE(STATUS "Will try to build MegaGlest shared library with DEBUG info for UPNP") + ADD_DEFINITIONS("-DDEBUG") + ENDIF() + IF(WIN32) TARGET_LINK_LIBRARIES(${TARGET_NAME} stdc++ gcc odbc32 wsock32 winspool winmm shell32 comctl32 ctl3d32 advapi32 wsock32 opengl32 glu32 ole32 oleaut32 uuid mingw32 ddraw dsound dxguid ws2_32 iphlpapi wsock32 libogg libvorbis libvorbisfile zlib jpeg libpng xerces-c2_8_0 OpenAL32 libcurl winmm gdi32 opengl32 glu32 SDL SDLmain lua5.1 streflop stdc++ moldname mingwex msvcrt user32 kernel32) @@ -345,4 +351,9 @@ IF(BUILD_MEGAGLEST_MODEL_VIEWER OR BUILD_MEGAGLEST_MAP_EDITOR OR BUILD_MEGAGLEST TARGET_LINK_LIBRARIES(${TARGET_NAME} ${EXTERNAL_LIBS}) ENDIF() + + #IF(BUILD_MEGAGLEST_UPNP_DEBUG) + # REMOVE_DEFINITIONS("-DDEBUG") + #ENDIF() + ENDIF() diff --git a/source/shared_lib/sources/platform/miniupnpc/miniupnpc.c b/source/shared_lib/sources/platform/miniupnpc/miniupnpc.c index 7ebed5fda..7f66b4f88 100644 --- a/source/shared_lib/sources/platform/miniupnpc/miniupnpc.c +++ b/source/shared_lib/sources/platform/miniupnpc/miniupnpc.c @@ -586,6 +586,12 @@ upnpDiscover(int delay, const char * multicastif, } for(p = servinfo; p; p = p->ai_next) { n = sendto(sudp, bufr, n, 0, p->ai_addr, p->ai_addrlen); + +#ifdef DEBUG + struct sockaddr_in *saddrin = (struct sockaddr_in *)p->ai_addr; + printf("sendto returned %d [%s] to host [%s]\n", n,bufr,inet_ntoa(saddrin->sin_addr)); +#endif + if (n < 0) { PRINT_SOCKET_ERROR("sendto"); continue; @@ -601,6 +607,11 @@ upnpDiscover(int delay, const char * multicastif, } /* Waiting for SSDP REPLY packet to M-SEARCH */ n = receivedata(sudp, bufr, sizeof(bufr), delay); + +#ifdef DEBUG + printf("receivedata returned %d [%s]\n", n,bufr); +#endif + if (n < 0) { /* error */ if(error) diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index c5b450edd..df99678f4 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -2147,15 +2147,34 @@ int UPNP_Tools::upnp_init(void *param) { if(UPNP_Tools::isUPNP) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Searching for UPnP devices for automatic port forwarding...\n"); - int ipv6 = 0; + int upnp_delay = 5000; + const char *upnp_multicastif = NULL; + const char *upnp_minissdpdsock = NULL; + int upnp_sameport = 0; + int upnp_ipv6 = 0; + int upnp_error = 0; + #ifndef MINIUPNPC_VERSION_PRE1_6 - devlist = upnpDiscover(2000, NULL, NULL, 0, ipv6, NULL); + devlist = upnpDiscover(upnp_delay, upnp_multicastif, upnp_minissdpdsock, upnp_sameport, upnp_ipv6, &upnp_error); + + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"UPnP discover returned upnp_error = %d.\n",upnp_error); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("UPnP discover returned upnp_error = %d.\n",upnp_error); + #else - devlist = upnpDiscover(2000, NULL, NULL, 0); + devlist = upnpDiscover(upnp_delay, upnp_multicastif, upnp_minissdpdsock, upnp_sameport); #endif - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"UPnP device search finished.\n"); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"UPnP device search finished devlist = %p.\n",devlist); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("UPnP device search finished devlist = %p.\n",devlist); if (devlist) { + dev = devlist; + while (dev) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"UPnP discover deviceList [%s].\n",(dev->st ? dev->st : "null")); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("UPnP discover deviceList [%s].\n",(dev->st ? dev->st : "null")); + + dev = dev->pNext; + } + dev = devlist; while (dev) { if (strstr(dev->st, "InternetGatewayDevice")) { @@ -2168,9 +2187,11 @@ int UPNP_Tools::upnp_init(void *param) { } if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"UPnP device found: %s %s\n", dev->descURL, dev->st); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("UPnP device found: %s %s\n", dev->descURL, dev->st); descXML = (char *)miniwget_getaddr(dev->descURL, &descXMLsize, lanaddr, sizeof(lanaddr)); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"LAN address: %s\n", lanaddr); + if (descXML) { parserootdesc (descXML, descXMLsize, &data); free (descXML); descXML = 0;