Allow binding to a certain IP Address.
On some servers, you have multiple IP Addresses, and in that case the socket library may decide what it really wants to use. Would basically be this in i_net.cpp in the function BindToLocalPort *********************************************************** netadr_t na; if -bind command line parameter exists { NET_StringToAdr("<-bind address>", &na); NetadrToSockadr(&na, &address); } else // Any address address.sin_addr.s_addr = INADDR_ANY; ***********************************************************
Created attachment 186 [details] Patch that allows you to bind to an address This patch does the following: * Allows you to bind to a certain IP address (for example if you have multiple IP addresses, INADDR_ANY just doesn't cut it). * Fixes NET_StringToAdr so that it works for any host (that is, I replaced badly written code). * You need to use "+set bindaddress <host/ip>", otherwise it will use the default (the cvar doesn't appear to get saved). Note that when binding to an address: * You need to own the address (that is, if it doesn't appear in ifconfig then you can't use it). If errno states that you can't use the address (must be root or not an address you own) then it will revert to any address. * You can only join the game when connecting to that address, which is the point of this patch. * If you do choose a 127.*.*.* address then you can only play with yourself.
Created attachment 187 [details] Newer patch Changed CVAR name to sv_bindaddress.
r1635: make -f Makefile.win client server ... i586-mingw32msvc-g++ -I/usr/i586-mingw32msvc/include/SDL -I/usr/i586-mingw32msvc/include/SDL -Os -D_WIN32 -DNOASM -Icommon -Itextscreen -I../client/sdl -Iclient/sdl -I../client/src -Iclient/src -c common/i_net.cpp -o obj/common/client_i_net.o common/i_net.cpp: In function ‘void BindToLocalPort(SOCKET, u_short)’: common/i_net.cpp:155: error: ‘EADDRNOTAVAIL’ was not declared in this scope make: *** [obj/common/client_i_net.o] Error 1
#ifdef _WIN32 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL #endif Also, errno could be errno or h_errno, depends.
(In reply to comment #4) > #ifdef _WIN32 > #define EADDRNOTAVAIL WSAEADDRNOTAVAIL > #endif > > Also, errno could be errno or h_errno, depends. No screw that
Created attachment 188 [details] WinSock fixes Misc Fixes for Win32 which uses WinSock which is practically 100% compatible but alot of stuff is renamed.
Resolved r1636
(In reply to comment #7) > Resolved r1636 No
The code in 1636 is not correct: errno is used in UNIX for BSD sockets but with WinSock it's not the case. Winsock requires WSAGetLastError() to obtain errno values. Also every errno for WinSocks is changed to WSAxxxx. The latest patch uses WSAGetLastError() for windows but still uses errno for UNIX. It also fixes places where strerror(errno) is used where errno is never set, which is the other portion of the code.
Can no longer connect to localhost/127.0.0.1 with the implementation of this patch. Is it possible to correct this?
r1664 reverts this patch. This was not thoroughly tested on Windows and has introduced undesirable behavior. I think it is something that is implementable and worth keeping open.
Created attachment 237 [details] Probable fix for localhost connect issue This patch puts the problem-causing code inside an "#ifndef _WIN32", while this removes the ability to bind to a specific IP with the windows server, it keeps this (useful) functionality in for server hosts running *nix. As I do not run windows, this patch will need to be tested (Patched against trunk r2046)
Your "fix" is to hide it from one platform. I do not think this constitutes a fix. You remove the ability for one platform to do it, and in turn the platform(s) that still would be able to may then have problems binding to localhost.
(In reply to comment #13) > Your "fix" is to hide it from one platform. I do not think this constitutes a > fix. You remove the ability for one platform to do it, and in turn the > platform(s) that still would be able to may then have problems binding to > localhost. Wrong, the platforms that the binding is left available for actually have some working implementation of the socket library, and therefore allow connecting to localhost *as long as* the sv_bindaddress cvar is left unset. I'm asking for a compromise between compatibility and practicality, getting this feature working under windows is better off left until it's actually needed. Meanwhile there are servers running on Linux/BSD that need this feature.