Bug Tracker – Bug 587

Allow binding to a certain IP Address.

Last modified: 2012-12-14 22:57:41 CST
Bug 587 - (ARRAY(0x472fe20)) Allow binding to a certain IP Address.
(ARRAY(0x472fe20))
Allow binding to a certain IP Address.
Status: REOPENED
Product: Odamex
Classification: Unclassified
Component: Server
(old) 0.5.0 - 0.5.5
All All
: P2 trivial
Depends on:
Blocks: ARRAY(0x2e9e3d0)
  Show dependency tree
 
Reported: 2010-05-17 23:06:35 CDT by GhostlyDeath
Modified: 2012-12-14 22:57 CST (History)
4 users (show)

See Also:


Attachments
Patch that allows you to bind to an address (3.73 KB, patch)
2010-07-03 16:11:13 CDT, GhostlyDeath
Details | Diff
Newer patch (3.50 KB, patch)
2010-07-03 18:08:31 CDT, GhostlyDeath
Details | Diff
WinSock fixes (2.14 KB, patch)
2010-07-04 17:41:41 CDT, GhostlyDeath
Details | Diff
Probable fix for localhost connect issue (2.65 KB, patch)
2011-01-15 03:00:12 CST, Kyle
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description GhostlyDeath 2010-05-17 23:06:35 CDT
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;

***********************************************************
Comment 1 GhostlyDeath 2010-07-03 16:11:13 CDT
Created ﷒0﷓
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.
Comment 2 GhostlyDeath 2010-07-03 18:08:31 CDT
Created ﷒0﷓
Newer patch

Changed CVAR name to sv_bindaddress.
Comment 3 Brandon Del Bel 2010-07-04 07:21:33 CDT
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
Comment 4 GhostlyDeath 2010-07-04 17:22:24 CDT
#ifdef _WIN32
    #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
#endif

Also, errno could be errno or h_errno, depends.
Comment 5 GhostlyDeath 2010-07-04 17:35:37 CDT
(In reply to comment #4)
> #ifdef _WIN32
>     #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
> #endif
> 
> Also, errno could be errno or h_errno, depends.

No screw that
Comment 6 GhostlyDeath 2010-07-04 17:41:41 CDT
Created ﷒0﷓
WinSock fixes

Misc Fixes for Win32 which uses WinSock which is practically 100% compatible but alot of stuff is renamed.
Comment 7 Ralph Vickers 2010-07-04 20:49:27 CDT
Resolved r1636
Comment 8 GhostlyDeath 2010-07-05 00:36:59 CDT
(In reply to comment #7)
> Resolved r1636

No
Comment 9 GhostlyDeath 2010-07-05 00:41:24 CDT
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.
Comment 10 Ralph Vickers 2010-07-17 23:43:27 CDT
Can no longer connect to localhost/127.0.0.1 with the implementation of this patch. Is it possible to correct this?
Comment 11 Mike Lightner 2010-07-21 23:50:06 CDT
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.
Comment 12 Kyle 2011-01-15 03:00:12 CST
Created ﷒0﷓
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)
Comment 13 Mike Lightner 2011-01-17 15:39:55 CST
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.
Comment 14 Kyle 2011-01-19 01:51:03 CST
(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.