From bae71dff48507fadb62ffa0807fcf6440e8d2004 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Fri, 29 Nov 2002 13:38:21 +0000 Subject: [PATCH] If bind() fails when connecting, don't fallback to default address. Should make it easier to notice invalid settings or figure out why it's not working.. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@3032 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/core/network.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/network.c b/src/core/network.c index b2b7fc3e..f5a6608b 100644 --- a/src/core/network.c +++ b/src/core/network.c @@ -201,10 +201,13 @@ GIOChannel *net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip) /* set our own address */ if (my_ip != NULL) { sin_set_ip(&so, my_ip); - if (bind(handle, &so.sa, SIZEOF_SOCKADDR(so)) == -1) { + if (bind(handle, &so.sa, SIZEOF_SOCKADDR(so)) < 0) { /* failed, set it back to INADDR_ANY */ - sin_set_ip(&so, NULL); - bind(handle, &so.sa, SIZEOF_SOCKADDR(so)); + int old_errno = errno; + + close(handle); + errno = old_errno; + return NULL; } }