mirror of
https://github.com/libretro/RetroArch
synced 2025-03-20 19:21:27 +00:00
(Network) Fix getaddrinfo_retro (#14261)
This commit is contained in:
parent
afd463be16
commit
9b10579a54
@ -209,7 +209,7 @@ command_t* command_network_new(uint16_t port)
|
|||||||
command_network_t *netcmd = (command_network_t*)calloc(
|
command_network_t *netcmd = (command_network_t*)calloc(
|
||||||
1, sizeof(command_network_t));
|
1, sizeof(command_network_t));
|
||||||
int fd = socket_init(
|
int fd = socket_init(
|
||||||
(void**)&res, port, NULL, SOCKET_TYPE_DATAGRAM);
|
(void**)&res, port, NULL, SOCKET_TYPE_DATAGRAM, AF_INET);
|
||||||
|
|
||||||
RARCH_LOG("[NetCMD]: %s %hu.\n",
|
RARCH_LOG("[NetCMD]: %s %hu.\n",
|
||||||
msg_hash_to_str(MSG_BRINGING_UP_COMMAND_INTERFACE_ON_PORT),
|
msg_hash_to_str(MSG_BRINGING_UP_COMMAND_INTERFACE_ON_PORT),
|
||||||
|
@ -117,7 +117,7 @@ static void *network_gfx_init(const video_info_t *video,
|
|||||||
|
|
||||||
RARCH_LOG("[Network]: Connecting to host %s:%d\n", network->address, network->port);
|
RARCH_LOG("[Network]: Connecting to host %s:%d\n", network->address, network->port);
|
||||||
try_connect:
|
try_connect:
|
||||||
fd = socket_init((void**)&addr, network->port, network->address, SOCKET_TYPE_STREAM);
|
fd = socket_init((void**)&addr, network->port, network->address, SOCKET_TYPE_STREAM, 0);
|
||||||
|
|
||||||
next_addr = addr;
|
next_addr = addr;
|
||||||
|
|
||||||
|
@ -1033,7 +1033,7 @@ static bool input_remote_init_network(input_remote_t *handle,
|
|||||||
RARCH_LOG("Bringing up remote interface on port %hu.\n",
|
RARCH_LOG("Bringing up remote interface on port %hu.\n",
|
||||||
(unsigned short)port);
|
(unsigned short)port);
|
||||||
|
|
||||||
if ((fd = socket_init((void**)&res, port, NULL, SOCKET_TYPE_DATAGRAM)) < 0)
|
if ((fd = socket_init((void**)&res, port, NULL, SOCKET_TYPE_DATAGRAM, AF_INET)) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
handle->net_fd[user] = fd;
|
handle->net_fd[user] = fd;
|
||||||
|
@ -70,6 +70,7 @@ struct hostent
|
|||||||
int h_length;
|
int h_length;
|
||||||
char **h_addr_list;
|
char **h_addr_list;
|
||||||
char *h_addr;
|
char *h_addr;
|
||||||
|
char *h_end;
|
||||||
};
|
};
|
||||||
|
|
||||||
#elif defined(GEKKO)
|
#elif defined(GEKKO)
|
||||||
@ -172,6 +173,7 @@ struct hostent
|
|||||||
int h_length;
|
int h_length;
|
||||||
char **h_addr_list;
|
char **h_addr_list;
|
||||||
char *h_addr;
|
char *h_addr;
|
||||||
|
char *h_end;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SceNetInAddr inet_aton(const char *ip_addr);
|
struct SceNetInAddr inet_aton(const char *ip_addr);
|
||||||
|
@ -60,7 +60,8 @@ typedef struct socket_target
|
|||||||
enum socket_protocol prot;
|
enum socket_protocol prot;
|
||||||
} socket_target_t;
|
} socket_target_t;
|
||||||
|
|
||||||
int socket_init(void **address, uint16_t port, const char *server, enum socket_type type);
|
int socket_init(void **address, uint16_t port, const char *server,
|
||||||
|
enum socket_type type, int family);
|
||||||
|
|
||||||
int socket_next(void **address);
|
int socket_next(void **address);
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@
|
|||||||
#if defined(_XBOX)
|
#if defined(_XBOX)
|
||||||
struct hostent *gethostbyname(const char *name)
|
struct hostent *gethostbyname(const char *name)
|
||||||
{
|
{
|
||||||
static struct in_addr addr;
|
static struct in_addr addr = {0};
|
||||||
static struct hostent he = {0};
|
static struct hostent he = {0};
|
||||||
WSAEVENT event;
|
WSAEVENT event;
|
||||||
XNDNS *dns = NULL;
|
XNDNS *dns = NULL;
|
||||||
struct hostent *ret = NULL;
|
struct hostent *ret = NULL;
|
||||||
@ -114,30 +114,34 @@ unsigned int inet_addr(const char *cp)
|
|||||||
|
|
||||||
struct hostent *gethostbyname(const char *name)
|
struct hostent *gethostbyname(const char *name)
|
||||||
{
|
{
|
||||||
int err;
|
static struct SceNetInAddr addr = {0};
|
||||||
static struct hostent ent;
|
static struct hostent he = {0};
|
||||||
static char sname[MAX_NAME] = {0};
|
int rid;
|
||||||
static struct SceNetInAddr saddr = {0};
|
struct hostent *ret = NULL;
|
||||||
static char *addrlist[2] = {(char *) &saddr, NULL };
|
|
||||||
int rid = sceNetResolverCreate("resolver", NULL, 0);
|
|
||||||
|
|
||||||
|
if (!name)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
rid = sceNetResolverCreate("resolver", NULL, 0);
|
||||||
if(rid < 0)
|
if(rid < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
err = sceNetResolverStartNtoa(rid, name, &saddr, 0,0,0);
|
if (sceNetResolverStartNtoa(rid, name, &addr, 0, 0, 0) < 0)
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
he.h_name = NULL;
|
||||||
|
he.h_aliases = NULL;
|
||||||
|
he.h_addrtype = AF_INET;
|
||||||
|
he.h_length = sizeof(addr);
|
||||||
|
he.h_addr_list = &he.h_addr;
|
||||||
|
he.h_addr = (char*)&addr;
|
||||||
|
|
||||||
|
ret = &he;
|
||||||
|
|
||||||
|
done:
|
||||||
sceNetResolverDestroy(rid);
|
sceNetResolverDestroy(rid);
|
||||||
if(err < 0)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
addrlist[0] = inet_ntoa(saddr);
|
return ret;
|
||||||
ent.h_name = sname;
|
|
||||||
ent.h_aliases = 0;
|
|
||||||
ent.h_addrtype = AF_INET;
|
|
||||||
ent.h_length = sizeof(struct in_addr);
|
|
||||||
ent.h_addr_list = addrlist;
|
|
||||||
ent.h_addr = addrlist[0];
|
|
||||||
|
|
||||||
return &ent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(_3DS)
|
#elif defined(_3DS)
|
||||||
@ -207,11 +211,7 @@ int getaddrinfo_retro(const char *node, const char *service,
|
|||||||
addr->sin_family = AF_INET;
|
addr->sin_family = AF_INET;
|
||||||
if (service)
|
if (service)
|
||||||
addr->sin_port = inet_htons((uint16_t)strtoul(service, NULL, 10));
|
addr->sin_port = inet_htons((uint16_t)strtoul(service, NULL, 10));
|
||||||
#ifdef VITA
|
|
||||||
addr->sin_addr.s_addr = inet_addr(host->h_addr);
|
|
||||||
#else
|
|
||||||
memcpy(&addr->sin_addr, host->h_addr, sizeof(addr->sin_addr));
|
memcpy(&addr->sin_addr, host->h_addr, sizeof(addr->sin_addr));
|
||||||
#endif
|
|
||||||
|
|
||||||
*res = info;
|
*res = info;
|
||||||
|
|
||||||
|
@ -417,7 +417,7 @@ static int net_http_new_socket(struct http_connection_t *conn)
|
|||||||
{
|
{
|
||||||
struct addrinfo *addr = NULL, *next_addr = NULL;
|
struct addrinfo *addr = NULL, *next_addr = NULL;
|
||||||
int fd = socket_init(
|
int fd = socket_init(
|
||||||
(void**)&addr, conn->port, conn->domain, SOCKET_TYPE_STREAM);
|
(void**)&addr, conn->port, conn->domain, SOCKET_TYPE_STREAM, 0);
|
||||||
#ifdef HAVE_SSL
|
#ifdef HAVE_SSL
|
||||||
if (conn->sock_state.ssl)
|
if (conn->sock_state.ssl)
|
||||||
{
|
{
|
||||||
|
@ -32,15 +32,22 @@
|
|||||||
|
|
||||||
#include <net/net_socket.h>
|
#include <net/net_socket.h>
|
||||||
|
|
||||||
int socket_init(void **address, uint16_t port, const char *server, enum socket_type type)
|
int socket_init(void **address, uint16_t port, const char *server,
|
||||||
|
enum socket_type type, int family)
|
||||||
{
|
{
|
||||||
char port_buf[6];
|
char port_buf[6];
|
||||||
struct addrinfo hints = {0};
|
struct addrinfo hints = {0};
|
||||||
struct addrinfo **addrinfo = (struct addrinfo**)address;
|
struct addrinfo **addrinfo = (struct addrinfo**)address;
|
||||||
struct addrinfo *addr = NULL;
|
struct addrinfo *addr = NULL;
|
||||||
|
|
||||||
if (!network_init())
|
if (!family)
|
||||||
return -1;
|
#if defined(HAVE_SOCKET_LEGACY) || defined(WIIU)
|
||||||
|
family = AF_INET;
|
||||||
|
#else
|
||||||
|
family = AF_UNSPEC;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
hints.ai_family = family;
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
@ -50,14 +57,16 @@ int socket_init(void **address, uint16_t port, const char *server, enum socket_t
|
|||||||
case SOCKET_TYPE_STREAM:
|
case SOCKET_TYPE_STREAM:
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
break;
|
break;
|
||||||
case SOCKET_TYPE_SEQPACKET:
|
default:
|
||||||
/* TODO/FIXME - implement? */
|
return -1;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!server)
|
if (!server)
|
||||||
hints.ai_flags = AI_PASSIVE;
|
hints.ai_flags = AI_PASSIVE;
|
||||||
|
|
||||||
|
if (!network_init())
|
||||||
|
return -1;
|
||||||
|
|
||||||
snprintf(port_buf, sizeof(port_buf), "%hu", (unsigned short)port);
|
snprintf(port_buf, sizeof(port_buf), "%hu", (unsigned short)port);
|
||||||
|
|
||||||
if (getaddrinfo_retro(server, port_buf, &hints, addrinfo))
|
if (getaddrinfo_retro(server, port_buf, &hints, addrinfo))
|
||||||
|
@ -90,7 +90,8 @@ bool natt_init(struct natt_discovery *discovery)
|
|||||||
if (!msearch_addr)
|
if (!msearch_addr)
|
||||||
goto failure;
|
goto failure;
|
||||||
|
|
||||||
fd = socket_init((void **) &bind_addr, 0, NULL, SOCKET_TYPE_DATAGRAM);
|
fd = socket_init((void**)&bind_addr, 0, NULL,
|
||||||
|
SOCKET_TYPE_DATAGRAM, AF_INET);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
goto failure;
|
goto failure;
|
||||||
if (!bind_addr)
|
if (!bind_addr)
|
||||||
|
@ -214,7 +214,7 @@ bool init_netplay_discovery(void)
|
|||||||
struct addrinfo *addr = NULL;
|
struct addrinfo *addr = NULL;
|
||||||
net_driver_state_t *net_st = &networking_driver_st;
|
net_driver_state_t *net_st = &networking_driver_st;
|
||||||
int fd = socket_init((void**)&addr, 0, NULL,
|
int fd = socket_init((void**)&addr, 0, NULL,
|
||||||
SOCKET_TYPE_DATAGRAM);
|
SOCKET_TYPE_DATAGRAM, AF_INET);
|
||||||
bool ret = fd >= 0 && addr;
|
bool ret = fd >= 0 && addr;
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
@ -457,7 +457,7 @@ static bool init_lan_ad_server_socket(void)
|
|||||||
struct addrinfo *addr = NULL;
|
struct addrinfo *addr = NULL;
|
||||||
net_driver_state_t *net_st = &networking_driver_st;
|
net_driver_state_t *net_st = &networking_driver_st;
|
||||||
int fd = socket_init((void**)&addr, RARCH_DISCOVERY_PORT,
|
int fd = socket_init((void**)&addr, RARCH_DISCOVERY_PORT,
|
||||||
NULL, SOCKET_TYPE_DATAGRAM);
|
NULL, SOCKET_TYPE_DATAGRAM, AF_INET);
|
||||||
bool ret = fd >= 0 && addr &&
|
bool ret = fd >= 0 && addr &&
|
||||||
socket_bind(fd, addr) && socket_nonblock(fd);
|
socket_bind(fd, addr) && socket_nonblock(fd);
|
||||||
|
|
||||||
|
@ -271,7 +271,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Connect to the netplay server */
|
/* Connect to the netplay server */
|
||||||
if ((sock = socket_init((void **) &addr, port, host, SOCKET_PROTOCOL_TCP)) < 0)
|
if ((sock = socket_init((void**)&addr, port, host, SOCKET_PROTOCOL_TCP, 0)) < 0)
|
||||||
{
|
{
|
||||||
perror("socket");
|
perror("socket");
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user