[freetds] connect(2) for UDP

Frediano Ziglio freddy77 at gmail.com
Thu Dec 18 06:03:19 EST 2008


2008/12/18 Peter Deacon <peterd at iea-software.com>:
> On Wed, 17 Dec 2008, Peter Deacon wrote:
>
>> Recommend using bind() rather than connect() with UDP.  With bind you
>> still get ICMP indiciations for fast failure when send()ing.
>
> More specifically..
>
> bind()
> sendto()
> select() for response
>
> The select will wake on either the expiration of the timer, data to be
> read or a failure hint if it turns out nothing was listening on the port
> from the previous sendto()
>

Oppss... I was wrong...
I did some tests with Python (only 5 lines to send and receive a
datagram, what a nice language :) ):
- server reply from a fix interface (netstat say sql browser bind at any:1434)
- using bind have a security problem (SELinux or a firewall can refuse
the bind) but when you send a packet kernel set the output port and do
a sort of bind (you can understand it calling getsockname)
- using connect filter packets from server so in the case of more
interfaces in server you lose the reply
- in case server is not listening to port 1434 it reply ICMP and
recvfrom return suddently with ECONNREFUSED
So you have timeout if
1- server is not alive (obviously!)
2- you use connect
3- you ask for a specific instance
so using current code detects port close suddently but
tds7_get_instance_port require a lot of time if there isn't the given
interface. The method is compatible with MS one (asking for a proper
instance) but I think it would be better to require all instances so
server always reply and in case of missing instance
tds7_get_instance_port return suddently.

Regards
  Frediano Ziglio


More information about the FreeTDS mailing list