1
0
mirror of https://github.com/irssi/irssi.git synced 2025-01-03 14:56:47 -05:00

Network fixes. DCC fixes for IPv6 + BSDs.

git-svn-id: http://svn.irssi.org/repos/irssi/trunk@3124 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2003-07-09 23:34:41 +00:00 committed by cras
parent ae5b5f38bd
commit a619fe9a2c
3 changed files with 17 additions and 4 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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;
}