diff --git a/src/core/network.c b/src/core/network.c index ab19aab0..71a5dcb1 100644 --- a/src/core/network.c +++ b/src/core/network.c @@ -51,6 +51,11 @@ union sockaddr_union { /* Cygwin need this, don't know others.. */ /*#define BLOCKING_SOCKETS 1*/ +IPADDR ip4_any = { + AF_INET, + { INADDR_ANY } +}; + int net_ip_compare(IPADDR *ip1, IPADDR *ip2) { if (ip1->family != ip2->family) @@ -114,7 +119,7 @@ void sin_set_port(union sockaddr_union *so, int port) { #ifdef HAVE_IPV6 if (so->sin.sin_family == AF_INET6) - so->sin6.sin6_port = htons(port); + so->sin6.sin6_port = htons((unsigned short)port); else #endif so->sin.sin_port = htons((unsigned short)port); @@ -283,8 +288,8 @@ GIOChannel *net_listen(IPADDR *my_ip, int *port) g_return_val_if_fail(port != NULL, NULL); memset(&so, 0, sizeof(so)); - sin_set_port(&so, *port); sin_set_ip(&so, my_ip); + sin_set_port(&so, *port); /* create the socket */ handle = socket(so.sin.sin_family, SOCK_STREAM, 0); diff --git a/src/core/network.h b/src/core/network.h index c6b08f9f..68f869ea 100644 --- a/src/core/network.h +++ b/src/core/network.h @@ -39,6 +39,8 @@ struct _IPADDR { #define IPADDR_IS_V6(ip) ((ip)->family != AF_INET) +extern IPADDR ip4_any; + /* returns 1 if IPADDRs are the same */ int net_ip_compare(IPADDR *ip1, IPADDR *ip2); diff --git a/src/irc/dcc/dcc.c b/src/irc/dcc/dcc.c index e3e04107..8bbca251 100644 --- a/src/irc/dcc/dcc.c +++ b/src/irc/dcc/dcc.c @@ -208,7 +208,10 @@ GIOChannel *dcc_listen(GIOChannel *iface, IPADDR *ip, int *port) if (first == 0) { /* random port */ *port = 0; - return net_listen(NULL, port); + if (IPADDR_IS_V6(ip)) + return net_listen(NULL, port); + else + return net_listen(&ip4_any, port); } /* get last port */ @@ -226,7 +229,10 @@ GIOChannel *dcc_listen(GIOChannel *iface, IPADDR *ip, int *port) /* use the first available port */ for (*port = first; *port <= last; (*port)++) { - handle = net_listen(NULL, port); + if (IPADDR_IS_V6(ip)) + handle = net_listen(NULL, port); + else + handle = net_listen(&ip4_any, port); if (handle != NULL) return handle; }