mirror of
https://github.com/libretro/RetroArch
synced 2025-01-30 12:32:52 +00:00
(Network) Move the addr_6to4 function to a proper place (#14100)
This commit is contained in:
parent
865993ffa7
commit
a7dc57f68f
@ -299,6 +299,8 @@ int getaddrinfo_retro(const char *node, const char *service,
|
|||||||
|
|
||||||
void freeaddrinfo_retro(struct addrinfo *res);
|
void freeaddrinfo_retro(struct addrinfo *res);
|
||||||
|
|
||||||
|
bool addr_6to4(struct sockaddr_storage *addr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* network_init:
|
* network_init:
|
||||||
*
|
*
|
||||||
|
@ -461,6 +461,43 @@ int inet_ptrton(int af, const char *src, void *dst)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool addr_6to4(struct sockaddr_storage *addr)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_INET6
|
||||||
|
/* ::ffff:a.b.c.d */
|
||||||
|
static const uint16_t preffix[] = {0,0,0,0,0,0xffff};
|
||||||
|
uint32_t address;
|
||||||
|
uint16_t port;
|
||||||
|
struct sockaddr_in6 *addr6 = (struct sockaddr_in6*)addr;
|
||||||
|
struct sockaddr_in *addr4 = (struct sockaddr_in*)addr;
|
||||||
|
|
||||||
|
switch (addr->ss_family)
|
||||||
|
{
|
||||||
|
case AF_INET:
|
||||||
|
/* No need to convert. */
|
||||||
|
return true;
|
||||||
|
case AF_INET6:
|
||||||
|
/* Is the address provided an IPv4? */
|
||||||
|
if (!memcmp(&addr6->sin6_addr, preffix, sizeof(preffix)))
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
/* We don't know how to handle this. */
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(&address, ((uint8_t*)&addr6->sin6_addr) + sizeof(preffix),
|
||||||
|
sizeof(address));
|
||||||
|
port = addr6->sin6_port;
|
||||||
|
|
||||||
|
memset(addr, 0, sizeof(*addr));
|
||||||
|
addr4->sin_family = AF_INET;
|
||||||
|
addr4->sin_port = port;
|
||||||
|
memcpy(&addr4->sin_addr, &address, sizeof(addr4->sin_addr));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
struct in_addr6_compat
|
struct in_addr6_compat
|
||||||
{
|
{
|
||||||
unsigned char ip_addr[16];
|
unsigned char ip_addr[16];
|
||||||
|
@ -65,43 +65,6 @@ static bool translate_addr(struct sockaddr_in *addr,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool addr_6to4(struct sockaddr_storage *addr)
|
|
||||||
{
|
|
||||||
#if defined(HAVE_INET6)
|
|
||||||
/* ::ffff:a.b.c.d */
|
|
||||||
static const uint16_t preffix[] = {0,0,0,0,0,0xffff};
|
|
||||||
uint32_t address;
|
|
||||||
uint16_t port;
|
|
||||||
struct sockaddr_in6 *addr6 = (struct sockaddr_in6*)addr;
|
|
||||||
struct sockaddr_in *addr4 = (struct sockaddr_in*)addr;
|
|
||||||
|
|
||||||
switch (addr->ss_family)
|
|
||||||
{
|
|
||||||
case AF_INET:
|
|
||||||
/* No need to convert. */
|
|
||||||
return true;
|
|
||||||
case AF_INET6:
|
|
||||||
/* Is the address provided an IPv4? */
|
|
||||||
if (!memcmp(&addr6->sin6_addr, preffix, sizeof(preffix)))
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
/* We don't know how to handle this. */
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(&address, ((uint8_t*)&addr6->sin6_addr) + sizeof(preffix),
|
|
||||||
sizeof(address));
|
|
||||||
port = addr6->sin6_port;
|
|
||||||
|
|
||||||
memset(addr, 0, sizeof(*addr));
|
|
||||||
addr4->sin_family = AF_INET;
|
|
||||||
addr4->sin_port = port;
|
|
||||||
memcpy(&addr4->sin_addr, &address, sizeof(addr4->sin_addr));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool natt_init(struct natt_discovery *discovery)
|
bool natt_init(struct natt_discovery *discovery)
|
||||||
{
|
{
|
||||||
static const char msearch[] =
|
static const char msearch[] =
|
||||||
|
@ -259,7 +259,6 @@ net_driver_state_t *networking_state_get_ptr(void);
|
|||||||
bool netplay_decode_hostname(const char *hostname,
|
bool netplay_decode_hostname(const char *hostname,
|
||||||
char *address, unsigned *port, char *session, size_t len);
|
char *address, unsigned *port, char *session, size_t len);
|
||||||
bool netplay_is_lan_address(struct sockaddr_in *addr);
|
bool netplay_is_lan_address(struct sockaddr_in *addr);
|
||||||
bool netplay_6to4(struct sockaddr_storage *addr);
|
|
||||||
|
|
||||||
int netplay_rooms_parse(const char *buf);
|
int netplay_rooms_parse(const char *buf);
|
||||||
int netplay_rooms_get_count(void);
|
int netplay_rooms_get_count(void);
|
||||||
|
@ -330,16 +330,8 @@ static bool netplay_lan_ad_client_response(void)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* And that we know how to handle it */
|
/* And that we know how to handle it */
|
||||||
#ifdef HAVE_INET6
|
if (!addr_6to4(&their_addr))
|
||||||
if (their_addr.ss_family == AF_INET6)
|
|
||||||
{
|
|
||||||
/* Check for IPv4 tunneling */
|
|
||||||
if (!netplay_6to4(&their_addr))
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else if (their_addr.ss_family != AF_INET)
|
|
||||||
continue;
|
continue;
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!netplay_is_lan_address((struct sockaddr_in*)&their_addr))
|
if (!netplay_is_lan_address((struct sockaddr_in*)&their_addr))
|
||||||
continue;
|
continue;
|
||||||
@ -545,16 +537,8 @@ static bool netplay_lan_ad_server(netplay_t *netplay)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_INET6
|
if (!addr_6to4(&their_addr))
|
||||||
if (their_addr.ss_family == AF_INET6)
|
|
||||||
{
|
|
||||||
/* Check for IPv4 tunneling */
|
|
||||||
if (!netplay_6to4(&their_addr))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (their_addr.ss_family != AF_INET)
|
|
||||||
return true;
|
return true;
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!netplay_is_lan_address((struct sockaddr_in*)&their_addr))
|
if (!netplay_is_lan_address((struct sockaddr_in*)&their_addr))
|
||||||
return true;
|
return true;
|
||||||
@ -8866,33 +8850,6 @@ bool netplay_is_lan_address(struct sockaddr_in *addr)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool netplay_6to4(struct sockaddr_storage *addr)
|
|
||||||
{
|
|
||||||
#ifdef HAVE_INET6
|
|
||||||
/* ::ffff:a.b.c.d */
|
|
||||||
static const uint16_t preffix[] = {0,0,0,0,0,0xffff};
|
|
||||||
uint32_t address;
|
|
||||||
uint16_t port;
|
|
||||||
struct sockaddr_in6 *addr6 = (struct sockaddr_in6*)addr;
|
|
||||||
struct sockaddr_in *addr4 = (struct sockaddr_in*)addr;
|
|
||||||
|
|
||||||
/* Is the address provided an IPv4? */
|
|
||||||
if (memcmp(&addr6->sin6_addr, preffix, sizeof(preffix)))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
memcpy(&address, ((uint8_t*)&addr6->sin6_addr) + sizeof(preffix),
|
|
||||||
sizeof(address));
|
|
||||||
port = addr6->sin6_port;
|
|
||||||
|
|
||||||
memset(addr, 0, sizeof(*addr));
|
|
||||||
addr4->sin_family = AF_INET;
|
|
||||||
addr4->sin_port = port;
|
|
||||||
memcpy(&addr4->sin_addr, &address, sizeof(addr4->sin_addr));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Netplay Widgets */
|
/* Netplay Widgets */
|
||||||
|
|
||||||
#ifdef HAVE_GFX_WIDGETS
|
#ifdef HAVE_GFX_WIDGETS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user