diff options
Diffstat (limited to 'src/qcommon/net_ip.c')
-rw-r--r-- | src/qcommon/net_ip.c | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/src/qcommon/net_ip.c b/src/qcommon/net_ip.c index baf70a17..e7a52996 100644 --- a/src/qcommon/net_ip.c +++ b/src/qcommon/net_ip.c @@ -227,6 +227,7 @@ static void NetadrToSockadr( netadr_t *a, struct sockaddr *s ) { ((struct sockaddr_in6 *)s)->sin6_family = AF_INET6; ((struct sockaddr_in6 *)s)->sin6_addr = * ((struct in6_addr *) &a->ip6); ((struct sockaddr_in6 *)s)->sin6_port = a->port; + ((struct sockaddr_in6 *)s)->sin6_scope_id = a->scope_id; } else if(a->type == NA_MULTICAST6) { @@ -248,6 +249,7 @@ static void SockadrToNetadr( struct sockaddr *s, netadr_t *a ) { a->type = NA_IP6; memcpy(a->ip6, &((struct sockaddr_in6 *)s)->sin6_addr, sizeof(a->ip6)); a->port = ((struct sockaddr_in6 *)s)->sin6_port; + a->scope_id = ((struct sockaddr_in6 *)s)->sin6_scope_id; } } @@ -279,14 +281,11 @@ static qboolean Sys_StringToSockaddr(const char *s, struct sockaddr *sadr, int s memset(sadr, '\0', sizeof(*sadr)); memset(&hints, '\0', sizeof(hints)); - // workaround for buggy MacOSX getaddrinfo implementation that doesn't handle AF_UNSPEC in hints correctly. - if(family == AF_UNSPEC) - hintsp = NULL; - else - { - hintsp = &hints; - hintsp->ai_family = family; - } + hintsp = &hints; + hintsp->ai_family = family; + hintsp->ai_socktype = SOCK_DGRAM; + // FIXME: we should set "->ai_flags" to AI_PASSIVE if we intend + // to use this structure for a bind() - instead of a sendto() retval = getaddrinfo(s, NULL, hintsp, &res); @@ -340,8 +339,15 @@ static qboolean Sys_StringToSockaddr(const char *s, struct sockaddr *sadr, int s Sys_SockaddrToString ============= */ -static void Sys_SockaddrToString(char *dest, int destlen, struct sockaddr *input, int inputlen) +static void Sys_SockaddrToString(char *dest, int destlen, struct sockaddr *input) { + socklen_t inputlen; + + if (input->sa_family == AF_INET6) + inputlen = sizeof(struct sockaddr_in6); + else + inputlen = sizeof(struct sockaddr_in); + getnameinfo(input, inputlen, dest, destlen, NULL, 0, NI_NUMERICHOST); } @@ -399,7 +405,7 @@ qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b) if (a.type == NA_IP6) { - if(!memcmp(a.ip6, b.ip6, sizeof(a.ip6))) + if(!memcmp(a.ip6, b.ip6, sizeof(a.ip6)) && a.scope_id == b.scope_id) return qtrue; return qfalse; @@ -423,7 +429,7 @@ const char *NET_AdrToString (netadr_t a) memset(&sadr, 0, sizeof(sadr)); NetadrToSockadr(&a, (struct sockaddr *) &sadr); - Sys_SockaddrToString(s, sizeof(s), (struct sockaddr *) &sadr, sizeof(sadr)); + Sys_SockaddrToString(s, sizeof(s), (struct sockaddr *) &sadr); } return s; @@ -718,6 +724,8 @@ qboolean Sys_IsLANAddress( netadr_t adr ) { } else { + // TODO? should we check the scope_id here? + compareip = (byte *) &((struct sockaddr_in6 *) &localIP[index].addr)->sin6_addr; comparemask = (byte *) &((struct sockaddr_in6 *) &localIP[index].netmask)->sin6_addr; compareadr = adr.ip6; @@ -755,7 +763,7 @@ void Sys_ShowIP(void) { for(i = 0; i < numIP; i++) { - Sys_SockaddrToString(addrbuf, sizeof(addrbuf), (struct sockaddr *) &localIP[i].addr, sizeof((*localIP).addr)); + Sys_SockaddrToString(addrbuf, sizeof(addrbuf), (struct sockaddr *) &localIP[i].addr); if(localIP[i].type == NA_IP) Com_Printf( "IP: %s\n", addrbuf); @@ -776,7 +784,7 @@ NET_IPSocket int NET_IPSocket( char *net_interface, int port, int *err ) { SOCKET newsocket; struct sockaddr_in address; - qboolean _true = qtrue; + u_long _true = 1; int i = 1; *err = 0; @@ -794,7 +802,7 @@ int NET_IPSocket( char *net_interface, int port, int *err ) { return newsocket; } // make it non-blocking - if( ioctlsocket( newsocket, FIONBIO, (u_long *)&_true ) == SOCKET_ERROR ) { + if( ioctlsocket( newsocket, FIONBIO, &_true ) == SOCKET_ERROR ) { Com_Printf( "WARNING: NET_IPSocket: ioctl FIONBIO: %s\n", NET_ErrorString() ); *err = socketError; closesocket(newsocket); @@ -847,7 +855,7 @@ NET_IP6Socket int NET_IP6Socket( char *net_interface, int port, struct sockaddr_in6 *bindto, int *err ) { SOCKET newsocket; struct sockaddr_in6 address; - qboolean _true = qtrue; + u_long _true = 1; *err = 0; @@ -869,7 +877,7 @@ int NET_IP6Socket( char *net_interface, int port, struct sockaddr_in6 *bindto, i } // make it non-blocking - if( ioctlsocket( newsocket, FIONBIO, (u_long *)&_true ) == SOCKET_ERROR ) { + if( ioctlsocket( newsocket, FIONBIO, &_true ) == SOCKET_ERROR ) { Com_Printf( "WARNING: NET_IP6Socket: ioctl FIONBIO: %s\n", NET_ErrorString() ); *err = socketError; closesocket(newsocket); |