summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/network.c8
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 */