From 8a032256bf29f2c86ebcfaf5a9da3cdb49e890c2 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Fri, 1 May 2020 17:25:39 +0100 Subject: [PATCH 1/6] don't define __USE_MINGW_ANSI_STDIO in makefiles (according to modern MinGW versions, defining this macro directly is deprecated) --- src/win32/Makefile.cfg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/win32/Makefile.cfg b/src/win32/Makefile.cfg index 27926b208..90ebbd794 100644 --- a/src/win32/Makefile.cfg +++ b/src/win32/Makefile.cfg @@ -59,7 +59,8 @@ endif ifndef SDL OPTS+=-D_WINDOWS endif - OPTS+=-D__USE_MINGW_ANSI_STDIO=0 + # Do we need this? + #OPTS+=-D__USE_MINGW_ANSI_STDIO=0 ifndef SDL LIBS+=-lmingw32 -mwindows -ldinput -ldxguid -lgdi32 -lwinmm From 43e53368b5ca27d55e05f9ece3013f6f8209aaa9 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 12 Jul 2020 21:31:25 +0100 Subject: [PATCH 2/6] added tabbing to some of the preprocessor code in i_tcp.c and mserv.c to make it easier to read them (and to allow me to understand what I need to do for the next commit) --- src/i_tcp.c | 196 ++++++++++++++++++++++++++-------------------------- src/mserv.c | 76 ++++++++++---------- 2 files changed, 135 insertions(+), 137 deletions(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index 5180869a5..3c5923d2c 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -20,127 +20,127 @@ #endif #ifndef NO_IPV6 -#define HAVE_IPV6 + #define HAVE_IPV6 #endif #ifdef _WIN32 -#define USE_WINSOCK -#if defined (_WIN64) || defined (HAVE_IPV6) -#define USE_WINSOCK2 -#else //_WIN64/HAVE_IPV6 -#define USE_WINSOCK1 -#endif + #define USE_WINSOCK + #if defined (_WIN64) || defined (HAVE_IPV6) + #define USE_WINSOCK2 + #else //_WIN64/HAVE_IPV6 + #define USE_WINSOCK1 + #endif #endif //WIN32 OS #ifdef USE_WINSOCK2 -#include + #include #endif #include "doomdef.h" #if defined (NOMD5) && !defined (NONET) -//#define NONET + //#define NONET #endif #ifdef NONET -#undef HAVE_MINIUPNPC + #undef HAVE_MINIUPNPC #else -#ifdef USE_WINSOCK1 -#include -#elif !defined (SCOUW2) && !defined (SCOUW7) -#ifndef USE_WINSOCK -#include -#endif //normal BSD API + #ifdef USE_WINSOCK1 + #include + #elif !defined (SCOUW2) && !defined (SCOUW7) + #ifndef USE_WINSOCK + #include + #endif //normal BSD API -#ifndef USE_WINSOCK -#ifdef __APPLE_CC__ -#ifndef _BSD_SOCKLEN_T_ -#define _BSD_SOCKLEN_T_ -#endif //_BSD_SOCKLEN_T_ -#endif //__APPLE_CC__ -#include -#include -#endif //normal BSD API + #ifndef USE_WINSOCK + #ifdef __APPLE_CC__ + #ifndef _BSD_SOCKLEN_T_ + #define _BSD_SOCKLEN_T_ + #endif //_BSD_SOCKLEN_T_ + #endif //__APPLE_CC__ + #include + #include + #endif //normal BSD API -#ifndef USE_WINSOCK -#include -#include -#endif //normal BSD API + #ifndef USE_WINSOCK + #include + #include + #endif //normal BSD API -#include -#include + #include + #include -#if (defined (__unix__) && !defined (MSDOS)) || defined(__APPLE__) || defined (UNIXCOMMON) - #include -#endif // UNIXCOMMON -#endif // !NONET + #if (defined (__unix__) && !defined (MSDOS)) || defined(__APPLE__) || defined (UNIXCOMMON) + #include + #endif // UNIXCOMMON + #endif // !defined (SCOUW2) && !defined (SCOUW7)) -#ifdef USE_WINSOCK - // some undefined under win32 - #undef errno - //#define errno WSAGetLastError() //Alam_GBC: this is the correct way, right? - #define errno h_errno // some very strange things happen when not using h_error?!? - #ifdef EWOULDBLOCK - #undef EWOULDBLOCK - #endif - #define EWOULDBLOCK WSAEWOULDBLOCK - #ifdef EMSGSIZE - #undef EMSGSIZE - #endif - #define EMSGSIZE WSAEMSGSIZE - #ifdef ECONNREFUSED - #undef ECONNREFUSED - #endif - #define ECONNREFUSED WSAECONNREFUSED - #ifdef ETIMEDOUT - #undef ETIMEDOUT - #endif - #define ETIMEDOUT WSAETIMEDOUT - #ifndef IOC_VENDOR - #define IOC_VENDOR 0x18000000 - #endif - #ifndef _WSAIOW - #define _WSAIOW(x,y) (IOC_IN|(x)|(y)) - #endif - #ifndef SIO_UDP_CONNRESET - #define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR,12) - #endif - #ifndef AI_ADDRCONFIG - #define AI_ADDRCONFIG 0x00000400 - #endif - #ifndef STATUS_INVALID_PARAMETER - #define STATUS_INVALID_PARAMETER 0xC000000D - #endif -#endif + #ifdef USE_WINSOCK + // some undefined under win32 + #undef errno + //#define errno WSAGetLastError() //Alam_GBC: this is the correct way, right? + #define errno h_errno // some very strange things happen when not using h_error?!? + #ifdef EWOULDBLOCK + #undef EWOULDBLOCK + #endif + #define EWOULDBLOCK WSAEWOULDBLOCK + #ifdef EMSGSIZE + #undef EMSGSIZE + #endif + #define EMSGSIZE WSAEMSGSIZE + #ifdef ECONNREFUSED + #undef ECONNREFUSED + #endif + #define ECONNREFUSED WSAECONNREFUSED + #ifdef ETIMEDOUT + #undef ETIMEDOUT + #endif + #define ETIMEDOUT WSAETIMEDOUT + #ifndef IOC_VENDOR + #define IOC_VENDOR 0x18000000 + #endif + #ifndef _WSAIOW + #define _WSAIOW(x,y) (IOC_IN|(x)|(y)) + #endif + #ifndef SIO_UDP_CONNRESET + #define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR,12) + #endif + #ifndef AI_ADDRCONFIG + #define AI_ADDRCONFIG 0x00000400 + #endif + #ifndef STATUS_INVALID_PARAMETER + #define STATUS_INVALID_PARAMETER 0xC000000D + #endif + #endif // USE_WINSOCK -#ifdef __DJGPP__ -#ifdef WATTCP // Alam_GBC: Wattcp may need this -#include -#define strerror strerror_s -#else // wattcp -#include -#endif // libsocket -#endif // djgpp + #ifdef __DJGPP__ + #ifdef WATTCP // Alam_GBC: Wattcp may need this + #include + #define strerror strerror_s + #else // wattcp + #include + #endif // libsocket + #endif // djgpp -typedef union -{ - struct sockaddr any; - struct sockaddr_in ip4; -#ifdef HAVE_IPV6 - struct sockaddr_in6 ip6; -#endif -} mysockaddr_t; + typedef union + { + struct sockaddr any; + struct sockaddr_in ip4; + #ifdef HAVE_IPV6 + struct sockaddr_in6 ip6; + #endif + } mysockaddr_t; -#ifdef HAVE_MINIUPNPC -#ifdef STATIC_MINIUPNPC -#define STATICLIB -#endif -#include "miniupnpc/miniwget.h" -#include "miniupnpc/miniupnpc.h" -#include "miniupnpc/upnpcommands.h" -#undef STATICLIB -static UINT8 UPNP_support = TRUE; -#endif + #ifdef HAVE_MINIUPNPC + #ifdef STATIC_MINIUPNPC + #define STATICLIB + #endif + #include "miniupnpc/miniwget.h" + #include "miniupnpc/miniupnpc.h" + #include "miniupnpc/upnpcommands.h" + #undef STATICLIB + static UINT8 UPNP_support = TRUE; + #endif // HAVE_MINIUPNC #endif // !NONET diff --git a/src/mserv.c b/src/mserv.c index 05a5344ba..58fb36bcb 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -19,37 +19,35 @@ #include #if (defined (NOMSERV)) && !defined (NONET) -#define NONET + #define NONET #endif #ifndef NONET + #ifndef NO_IPV6 + #define HAVE_IPV6 + #endif + #ifdef _WIN32 + #define RPC_NO_WINDOWS_H + #ifdef HAVE_IPV6 + #include + #else + #include // socket(),... + #endif //!HAVE_IPV6 + #else + #include + #ifdef __APPLE_CC__ + #ifndef _BSD_SOCKLEN_T_ + #define _BSD_SOCKLEN_T_ + #endif + #endif + #include // socket(),... + #include // sockaddr_in + #include // getaddrinfo(),... + #include -#ifndef NO_IPV6 -#define HAVE_IPV6 -#endif - -#ifdef _WIN32 -#define RPC_NO_WINDOWS_H -#ifdef HAVE_IPV6 -#include -#else -#include // socket(),... -#endif //!HAVE_IPV6 -#else -#include -#ifdef __APPLE_CC__ -#ifndef _BSD_SOCKLEN_T_ -#define _BSD_SOCKLEN_T_ -#endif -#endif -#include // socket(),... -#include // sockaddr_in -#include // getaddrinfo(),... -#include - -#include // timeval,... (TIMEOUT) -#include -#endif // _WIN32 + #include // timeval,... (TIMEOUT) + #include + #endif // _WIN32 #endif // !NONET #include "doomstat.h" @@ -155,18 +153,18 @@ typedef struct // win32 or djgpp #if defined (_WIN32) || defined (__DJGPP__) -#define ioctl ioctlsocket -#define close closesocket -#ifdef WATTCP -#define strerror strerror_s -#endif -#ifdef _WIN32 -#undef errno -#define errno h_errno // some very strange things happen when not using h_error -#endif -#ifndef AI_ADDRCONFIG -#define AI_ADDRCONFIG 0x00000400 -#endif + #define ioctl ioctlsocket + #define close closesocket + #ifdef WATTCP + #define strerror strerror_s + #endif + #ifdef _WIN32 + #undef errno + #define errno h_errno // some very strange things happen when not using h_error + #endif + #ifndef AI_ADDRCONFIG + #define AI_ADDRCONFIG 0x00000400 + #endif #endif #ifndef NONET From e133d8ec373b35e9b4e4a11bd0f8d09adb46d51e Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 12 Jul 2020 22:08:35 +0100 Subject: [PATCH 3/6] i_tcp.c: SCOUW2 and SCOUW7 haven't been defined since we got rid of Doom Legacy's makefiles for UnixWare 2/7 (which are ANCIENT), so get rid of them! --- src/i_tcp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index 3c5923d2c..e20e43ea4 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -47,7 +47,7 @@ #else #ifdef USE_WINSOCK1 #include - #elif !defined (SCOUW2) && !defined (SCOUW7) + #else #ifndef USE_WINSOCK #include #endif //normal BSD API @@ -73,7 +73,7 @@ #if (defined (__unix__) && !defined (MSDOS)) || defined(__APPLE__) || defined (UNIXCOMMON) #include #endif // UNIXCOMMON - #endif // !defined (SCOUW2) && !defined (SCOUW7)) + #endif #ifdef USE_WINSOCK // some undefined under win32 From 0f4487eb68475d772b24469815c82f429c98abbb Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 12 Jul 2020 22:24:10 +0100 Subject: [PATCH 4/6] * i_tcp.c: merge these three ifndef USE_WINSOCK blocks together * mserv.c: added i_tcp.c's USE_WINSOCK macros so socklen_t isn't redundantly defined if Winsock 2 is used --- src/i_tcp.c | 6 ------ src/mserv.c | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index e20e43ea4..4738b9df8 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -50,9 +50,6 @@ #else #ifndef USE_WINSOCK #include - #endif //normal BSD API - - #ifndef USE_WINSOCK #ifdef __APPLE_CC__ #ifndef _BSD_SOCKLEN_T_ #define _BSD_SOCKLEN_T_ @@ -60,9 +57,6 @@ #endif //__APPLE_CC__ #include #include - #endif //normal BSD API - - #ifndef USE_WINSOCK #include #include #endif //normal BSD API diff --git a/src/mserv.c b/src/mserv.c index 58fb36bcb..84fdca80e 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -22,6 +22,19 @@ #define NONET #endif +#ifndef NO_IPV6 + #define HAVE_IPV6 +#endif + +#ifdef _WIN32 + #define USE_WINSOCK + #if /*defined (_WIN64) ||*/ defined (HAVE_IPV6) + #define USE_WINSOCK2 + #else //_WIN64/HAVE_IPV6 + #define USE_WINSOCK1 + #endif +#endif //WIN32 OS + #ifndef NONET #ifndef NO_IPV6 #define HAVE_IPV6 @@ -196,7 +209,7 @@ typedef unsigned long SOCKET_TYPE; #define ERRSOCKET (-1) #endif -#if (defined (WATTCP) && !defined (__libsocket_socklen_t)) || defined (_WIN32) +#if (defined (WATTCP) && !defined (__libsocket_socklen_t)) || defined (USE_WINSOCK1) typedef int socklen_t; #endif From b8a794e37fb5e0c8be987585c940637aa066b7eb Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 12 Jul 2020 22:29:15 +0100 Subject: [PATCH 5/6] socklen_t isn't actually needed in either i_tcp.c or mserv.c if NONET is on! (also added some more tabbing) --- src/i_tcp.c | 43 +++++++++++++++++++++---------------------- src/mserv.c | 31 +++++++++++++++---------------- 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index 4738b9df8..efd381765 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -171,32 +171,31 @@ #define DEFAULTPORT "5029" #if defined (USE_WINSOCK) && !defined (NONET) -typedef SOCKET SOCKET_TYPE; -#define ERRSOCKET (SOCKET_ERROR) + typedef SOCKET SOCKET_TYPE; + #define ERRSOCKET (SOCKET_ERROR) #else -#if (defined (__unix__) && !defined (MSDOS)) || defined (__APPLE__) || defined (__HAIKU__) -typedef int SOCKET_TYPE; -#else -typedef unsigned long SOCKET_TYPE; -#endif -#define ERRSOCKET (-1) -#endif - -#if (defined (WATTCP) && !defined (__libsocket_socklen_t)) || defined (USE_WINSOCK1) -typedef int socklen_t; + #if (defined (__unix__) && !defined (MSDOS)) || defined (__APPLE__) || defined (__HAIKU__) + typedef int SOCKET_TYPE; + #else + typedef unsigned long SOCKET_TYPE; + #endif + #define ERRSOCKET (-1) #endif #ifndef NONET -static SOCKET_TYPE mysockets[MAXNETNODES+1] = {ERRSOCKET}; -static size_t mysocketses = 0; -static int myfamily[MAXNETNODES+1] = {0}; -static SOCKET_TYPE nodesocket[MAXNETNODES+1] = {ERRSOCKET}; -static mysockaddr_t clientaddress[MAXNETNODES+1]; -static mysockaddr_t broadcastaddress[MAXNETNODES+1]; -static size_t broadcastaddresses = 0; -static boolean nodeconnected[MAXNETNODES+1]; -static mysockaddr_t banned[MAXBANS]; -static UINT8 bannedmask[MAXBANS]; + #if (defined (WATTCP) && !defined (__libsocket_socklen_t)) || defined (USE_WINSOCK1) + typedef int socklen_t; + #endif + static SOCKET_TYPE mysockets[MAXNETNODES+1] = {ERRSOCKET}; + static size_t mysocketses = 0; + static int myfamily[MAXNETNODES+1] = {0}; + static SOCKET_TYPE nodesocket[MAXNETNODES+1] = {ERRSOCKET}; + static mysockaddr_t clientaddress[MAXNETNODES+1]; + static mysockaddr_t broadcastaddress[MAXNETNODES+1]; + static size_t broadcastaddresses = 0; + static boolean nodeconnected[MAXNETNODES+1]; + static mysockaddr_t banned[MAXBANS]; + static UINT8 bannedmask[MAXBANS]; #endif static size_t numbans = 0; diff --git a/src/mserv.c b/src/mserv.c index 84fdca80e..da163d7f6 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -198,26 +198,25 @@ static INT32 msnode = -1; UINT16 current_port = 0; #if defined (_WIN32) && !defined (NONET) -typedef SOCKET SOCKET_TYPE; -#define ERRSOCKET (SOCKET_ERROR) + typedef SOCKET SOCKET_TYPE; + #define ERRSOCKET (SOCKET_ERROR) #else -#if (defined (__unix__) && !defined (MSDOS)) || defined (__APPLE__) || defined (__HAIKU__) -typedef int SOCKET_TYPE; -#else -typedef unsigned long SOCKET_TYPE; -#endif -#define ERRSOCKET (-1) -#endif - -#if (defined (WATTCP) && !defined (__libsocket_socklen_t)) || defined (USE_WINSOCK1) -typedef int socklen_t; + #if (defined (__unix__) && !defined (MSDOS)) || defined (__APPLE__) || defined (__HAIKU__) + typedef int SOCKET_TYPE; + #else + typedef unsigned long SOCKET_TYPE; + #endif + #define ERRSOCKET (-1) #endif #ifndef NONET -static SOCKET_TYPE socket_fd = ERRSOCKET; // WINSOCK socket -static struct timeval select_timeout; -static fd_set wset; -static size_t recvfull(SOCKET_TYPE s, char *buf, size_t len, int flags); + #if (defined (WATTCP) && !defined (__libsocket_socklen_t)) || defined (USE_WINSOCK1) + typedef int socklen_t; + #endif + static SOCKET_TYPE socket_fd = ERRSOCKET; // WINSOCK socket + static struct timeval select_timeout; + static fd_set wset; + static size_t recvfull(SOCKET_TYPE s, char *buf, size_t len, int flags); #endif // Room list is an external variable now. From ed70675df35eee1c185f07f8a774fa9c44117d5b Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 12 Jul 2020 22:37:36 +0100 Subject: [PATCH 6/6] added some helpful comments, remove duplicate code --- src/i_tcp.c | 1 + src/mserv.c | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index efd381765..ab8a69a9f 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -183,6 +183,7 @@ #endif #ifndef NONET + // define socklen_t in DOS/Windows if it is not already defined #if (defined (WATTCP) && !defined (__libsocket_socklen_t)) || defined (USE_WINSOCK1) typedef int socklen_t; #endif diff --git a/src/mserv.c b/src/mserv.c index da163d7f6..72243e950 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -26,9 +26,11 @@ #define HAVE_IPV6 #endif +// -- Monster Iestyn 12/07/20 +// define Winsock related macros like in i_tcp.c (this is really all for socklen_t tbh) #ifdef _WIN32 #define USE_WINSOCK - #if /*defined (_WIN64) ||*/ defined (HAVE_IPV6) + #if /*defined (_WIN64) ||*/ defined (HAVE_IPV6) // (to be consistent with below code) #define USE_WINSOCK2 #else //_WIN64/HAVE_IPV6 #define USE_WINSOCK1 @@ -36,9 +38,6 @@ #endif //WIN32 OS #ifndef NONET - #ifndef NO_IPV6 - #define HAVE_IPV6 - #endif #ifdef _WIN32 #define RPC_NO_WINDOWS_H #ifdef HAVE_IPV6 @@ -210,6 +209,7 @@ UINT16 current_port = 0; #endif #ifndef NONET + // define socklen_t in DOS/Windows if it is not already defined #if (defined (WATTCP) && !defined (__libsocket_socklen_t)) || defined (USE_WINSOCK1) typedef int socklen_t; #endif