diff options
author | Timo Sirainen <cras@irssi.org> | 2001-11-07 14:35:00 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2001-11-07 14:35:00 +0000 |
commit | 9abd8576183f2140e8dd18c0ae66a45a26aee5bb (patch) | |
tree | 806f35396078db0cc73c66b1d028ead81119a9e6 /src | |
parent | 1ca2218e469bb62ac311b77d73acbe1a4c919e96 (diff) | |
download | irssi-9abd8576183f2140e8dd18c0ae66a45a26aee5bb.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/core/network.c | 8 |
1 files 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 */ |