From 9abd8576183f2140e8dd18c0ae66a45a26aee5bb Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Wed, 7 Nov 2001 14:35:00 +0000 Subject: [PATCH] net_connect(): if bind() fails, set the address back to INADDR_ANY to make sure it doesn't leave the socket in buggy state. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1978 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/core/network.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/network.c b/src/core/network.c index 4fc06c05..774815fd 100644 --- a/src/core/network.c +++ b/src/core/network.c @@ -196,10 +196,14 @@ GIOChannel *net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip) setsockopt(handle, SOL_SOCKET, SO_KEEPALIVE, (char *) &opt, sizeof(opt)); - /* set our own address, ignore if bind() fails */ + /* set our own address */ if (my_ip != NULL) { sin_set_ip(&so, my_ip); - bind(handle, &so.sa, SIZEOF_SOCKADDR(so)); + if (bind(handle, &so.sa, SIZEOF_SOCKADDR(so)) == -1) { + /* failed, set it back to INADDR_ANY */ + sin_set_ip(&so, NULL); + bind(handle, &so.sa, SIZEOF_SOCKADDR(so)); + } } /* connect */