From 3d5da0105db09ca1876912c27cfa7b36f396c544 Mon Sep 17 00:00:00 2001 From: Vladimir Dubrovin <3proxy@3proxy.ru> Date: Mon, 12 Oct 2026 22:04:01 +0300 Subject: [PATCH] Fix the build with MSVC: nssocket() a function everywhere Outside Linux nssocket() was a macro, and two of its callers have #ifdef WITH_UN among its arguments. Preprocessor directives in macro arguments are undefined behaviour: gcc and clang take them, MSVC does not. It is a function on every system now. Co-Authored-By: Claude Opus 5.5 --- src/common.c | 5 +++++ src/proxy.h | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/common.c b/src/common.c index 847e9f0..7a6db9c 100644 --- a/src/common.c +++ b/src/common.c @@ -77,6 +77,11 @@ SOCKET nssocket(struct srvparam *srv, struct sockfuncs *sf, void *state, int sid errno = err; return s; } +#else +/* no network namespaces: a socket is made where it always is */ +SOCKET nssocket(struct srvparam *srv, struct sockfuncs *sf, void *state, int side, int domain, int type, int protocol){ + return sf->_socket(state, domain, type, protocol); +} #endif diff --git a/src/proxy.h b/src/proxy.h index 7a53bc3..588151e 100644 --- a/src/proxy.h +++ b/src/proxy.h @@ -245,10 +245,10 @@ int socks5_setaddr(int family, int atyp, const unsigned char *addr, PROXYSOCKADD #ifdef __linux__ extern int mainnsfd; int nsopen(void); -SOCKET nssocket(struct srvparam *srv, struct sockfuncs *sf, void *state, int side, int domain, int type, int protocol); -#else -#define nssocket(srv, sf, state, side, domain, type, protocol) ((sf)->_socket((state), (domain), (type), (protocol))) #endif +/* a function everywhere, never a macro: its callers have preprocessor + lines among its arguments */ +SOCKET nssocket(struct srvparam *srv, struct sockfuncs *sf, void *state, int side, int domain, int type, int protocol); int socksend(struct clientparam *param, SOCKET sock, unsigned char * buf, int bufsize, int to); int socksendto(struct clientparam *param, SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufsize, int to); int sockrecvfrom(struct clientparam *param, SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufsize, int to);