-
Notifications
You must be signed in to change notification settings - Fork 25
Binding a socket to a local interface when it is not specifically specified. #36
Comments
Regarding UDP I got feedback from an expert colleague based on investigations on his Linux machine:
My conclusion is that for our API this means for UDP:
|
The description is that of Berkeley socket behavior. This is pretty much what everyone's used to. However, I don't think it's acceptable for a mobile device with several interfaces (3g, wifi, bluetooth) to have a local address depending on the address of the datagram sent. Besides, it would make the localAddress attribute irrelevant. So I really we should, as for TCP, use a well specified default interface for any UDP socket (i.e. a call to bind() is always done). However, it's probably a good idea to have same behavior when a remote address is specified (connect() called) : Can only send to the specified remote address and datagrams are filtered : only datagrams from the specified remoteAddress are received, all others are dropped (ignored). |
I think that we have to find a combination of using the routing table as Patrick states and sometimes using a default interface as Ke-Fong suggests. Just to remind everyone, we are here just talking about the case when the application does not explictly bind the socket to a specific local address, i.e. the application does not speciffy a localAddress field in the options argument in the call to the UDP or TCP socket constructor. To me it sounds logical to use the routing table as a starting point. For example, if the remote address is local host another local interface must be used compared to the case when the remote address is an internet address. However, the problem occurs if the are more than one way to reach the internet, for example if the device is a desktop computer with more than one network card or a mobile device running 3G and wifi simultaneously. In this case one of these must be considered as "the default interface". So I propose a wording in the specification that says that:
I can make an update to the specification according to above. WDYT? |
Any objections to the update I propose above? |
Please review PR 51. I am not sure on the approach for server sockets. node.js states "If the host is omitted, the server will accept connections directed to any IPv4 address (INADDR_ANY). ". |
[Paatric]:
[Claes] So this means that for TCP a better description on the process for allocating a local address is needed in the case when a specific local address is not defined by the web application but I don't think that the API itself has to change?
For the case when a local interface needs to be stated by the web application I refer to the latest comments in #24, i.e. that the phase 2 SysApps API, Network Interface API, should be used to list the available networks so that a specific interface can be selected by the application.
However, your description above on how the routing table is used to set the local address based on the remote address to connect to works for TCP. What applies then to UDP? With the constructor's options argument we can set an optional "default remote address" for subsequent send() calls. So if this option is used I assume that the routing table can be used in the same manner as for TCP. However, which is the procedure if we don't set this option? Does that mean that the local address can't be determined until we issue a send() call?
Regarding setting the localAddress attribute I assume that Patrick means that for TCP the localAddress attribute immediately could be set to the actual value during the execution of the constructor, not to null, even if it is not explicitly specified in the constructor. Correct?
The text was updated successfully, but these errors were encountered: