ipv6: builds and works now, still can't interact with ipv4 clients/servers

This commit is contained in:
Jeff Teunissen 2010-12-29 07:47:15 -05:00
parent fdb4d885ae
commit 878a9cfb6a

View file

@ -244,35 +244,16 @@ const char *
NET_BaseAdrToString (netadr_t a) NET_BaseAdrToString (netadr_t a)
{ {
static char s[64]; static char s[64];
struct sockaddr_storage ss; AF_address_t ss;
// NetadrToSockadr(&a,&sa); NetadrToSockadr(&a,&ss);
memset (&ss, 0, sizeof (ss));
if (IN6_IS_ADDR_V4MAPPED ((struct in6_addr *) a.ip)) {
#ifdef HAVE_SS_LEN #ifdef HAVE_SS_LEN
ss.ss_len = sizeof (struct sockaddr_in); if (getnameinfo (&ss.sa, ss.ss.ss_len, s, sizeof (s),
#endif
ss.ss_family = AF_INET;
memcpy (&((struct sockaddr_in *) &ss)->sin_addr,
&((struct in6_addr *) a.ip)->s6_addr[12],
sizeof (struct in_addr));
} else {
#ifdef HAVE_SS_LEN
ss.ss_len = sizeof (struct sockaddr_in6);
#endif
ss.ss_family = AF_INET6;
memcpy (&((struct sockaddr_in6 *) &ss)->sin6_addr,
a.ip, sizeof (struct in6_addr));
}
#ifdef HAVE_SS_LEN
if (getnameinfo ((struct sockaddr *) &ss, ss.ss_len, s, sizeof (s),
NULL, 0, NI_NUMERICHOST)) strcpy (s, "<invalid>"); NULL, 0, NI_NUMERICHOST)) strcpy (s, "<invalid>");
#else #else
// maybe needs switch for AF_INET6 or AF_INET? // maybe needs switch for AF_INET6 or AF_INET?
if (getnameinfo ((struct sockaddr *) &ss, sizeof (ss), s, sizeof (s), if (getnameinfo (&ss.sa, sizeof (ss.ss), s, sizeof (s),
NULL, 0, NI_NUMERICHOST)) NULL, 0, NI_NUMERICHOST))
strcpy (s, "<invalid>"); strcpy (s, "<invalid>");
#endif #endif
@ -296,9 +277,8 @@ NET_StringToAdr (const char *s, netadr_t *a)
int err; int err;
struct addrinfo hints; struct addrinfo hints;
struct addrinfo *resultp; struct addrinfo *resultp;
struct sockaddr_storage ss; AF_address_t addr;
struct sockaddr_in6 *ss6; AF_address_t resadr;
struct sockaddr_in *ss4;
if (!copy) if (!copy)
copy = dstring_new (); copy = dstring_new ();
@ -336,20 +316,18 @@ NET_StringToAdr (const char *s, netadr_t *a)
switch (resultp->ai_family) { switch (resultp->ai_family) {
case AF_INET: case AF_INET:
// convert to ipv6 addr // convert to ipv6 addr
memset (&ss, 0, sizeof (ss)); memset (&addr, 0, sizeof (addr));
ss6 = (struct sockaddr_in6 *) &ss; memset (&resadr, 0, sizeof (resadr));
ss4 = (struct sockaddr_in *) resultp->ai_addr; memcpy (&resadr.s4, resultp->ai_addr, sizeof (resadr.s4));
ss6->sin6_family = AF_INET6;
memset (&ss6->sin6_addr, 0, sizeof (ss6->sin6_addr)); addr.ss.ss_family = AF_INET6;
ss6->sin6_addr.s6_addr[10] = ss6->sin6_addr.s6_addr[11] = 0xff; addr.s6.sin6_addr.s6_addr[10] = addr.s6.sin6_addr.s6_addr[11] = 0xff;
memcpy (&ss6->sin6_addr.s6_addr[12], &ss4->sin_addr, memcpy (&(addr.s6.sin6_addr.s6_addr[12]), &resadr.s4.sin_addr,
sizeof (ss4->sin_addr)); sizeof (resadr.s4.sin_addr));
addr.s6.sin6_port = resadr.s4.sin_port;
ss6->sin6_port = ss4->sin_port;
break; break;
case AF_INET6: case AF_INET6:
memcpy (&ss, resultp->ai_addr, sizeof (struct sockaddr_in6)); memcpy (&addr, resultp->ai_addr, sizeof (addr.s6));
break; break;
default: default:
@ -358,7 +336,7 @@ NET_StringToAdr (const char *s, netadr_t *a)
return 0; return 0;
} }
SockadrToNetadr ((struct sockaddr_in6 *) &ss, a); SockadrToNetadr (&addr, a);
return true; return true;
} }
@ -399,12 +377,12 @@ NET_GetPacket (void)
{ {
int ret; int ret;
unsigned int fromlen; unsigned int fromlen;
struct sockaddr_in6 from; AF_address_t from;
fromlen = sizeof (from); fromlen = sizeof (from);
ret = ret =
recvfrom (net_socket, (void *) net_message_buffer, recvfrom (net_socket, (void *) net_message_buffer,
sizeof (net_message_buffer), 0, (struct sockaddr *) &from, sizeof (net_message_buffer), 0, &from.sa,
&fromlen); &fromlen);
SockadrToNetadr (&from, &net_from); SockadrToNetadr (&from, &net_from);
@ -442,12 +420,12 @@ void
NET_SendPacket (int length, const void *data, netadr_t to) NET_SendPacket (int length, const void *data, netadr_t to)
{ {
int ret; int ret;
struct sockaddr_in6 addr; AF_address_t addr;
NetadrToSockadr (&to, &addr); NetadrToSockadr (&to, &addr);
ret = ret =
sendto (net_socket, data, length, 0, (struct sockaddr *) &addr, sendto (net_socket, data, length, 0, &addr.sa,
sizeof (addr)); sizeof (addr));
if (ret == -1) { if (ret == -1) {
#ifdef _WIN32 #ifdef _WIN32