From b25b2a0e6c5ba494b550640a1bc4862cfac6b886 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 2 May 2016 18:54:55 +0200 Subject: [PATCH] Some code de-duplication --- command.c | 5 ----- libretro-common/net/net_compat.c | 14 ++++++++++---- libretro-common/net/net_socket.c | 7 ------- netplay/netplay.c | 6 ------ 4 files changed, 10 insertions(+), 22 deletions(-) diff --git a/command.c b/command.c index 60251d732d..d7ea4eca24 100644 --- a/command.c +++ b/command.c @@ -505,11 +505,6 @@ static bool send_udp_packet(const char *host, int fd = -1; bool ret = true; -#if defined(_WIN32) || defined(HAVE_SOCKET_LEGACY) - hints.ai_family = AF_INET; -#else - hints.ai_family = AF_UNSPEC; -#endif hints.ai_socktype = SOCK_DGRAM; snprintf(port_buf, sizeof(port_buf), "%hu", (unsigned short)port); diff --git a/libretro-common/net/net_compat.c b/libretro-common/net/net_compat.c index 15f9385f5c..be0393c5d0 100644 --- a/libretro-common/net/net_compat.c +++ b/libretro-common/net/net_compat.c @@ -107,10 +107,16 @@ int getaddrinfo_retro(const char *node, const char *service, if (!info) goto error; - info->ai_family = AF_INET; - info->ai_socktype = hints->ai_socktype; +#if defined(_WIN32) || defined(HAVE_SOCKET_LEGACY) + hints->ai_family = AF_INET; +#else + hints->ai_family = AF_UNSPEC; +#endif - in_addr = (struct sockaddr_in*)calloc(1, sizeof(*in_addr)); + info->ai_family = AF_INET; + info->ai_socktype = hints->ai_socktype; + in_addr = (struct sockaddr_in*) + calloc(1, sizeof(*in_addr)); if (!in_addr) goto error; @@ -136,7 +142,7 @@ int getaddrinfo_retro(const char *node, const char *service, goto error; info->ai_addr = (struct sockaddr*)in_addr; - *res = info; + *res = info; return 0; diff --git a/libretro-common/net/net_socket.c b/libretro-common/net/net_socket.c index 9efd5f514f..a2abbcf49d 100644 --- a/libretro-common/net/net_socket.c +++ b/libretro-common/net/net_socket.c @@ -31,16 +31,9 @@ int socket_init(void **address, uint16_t port, const char *server, enum socket_t struct addrinfo **addrinfo = (struct addrinfo**)address; struct addrinfo *addr = NULL; - if (!network_init()) goto error; -#if defined(_WIN32) || defined(HAVE_SOCKET_LEGACY) - hints.ai_family = AF_INET; -#else - hints.ai_family = AF_UNSPEC; -#endif - switch (type) { case SOCKET_TYPE_DATAGRAM: diff --git a/netplay/netplay.c b/netplay/netplay.c index 9d40929184..72de3f3cca 100644 --- a/netplay/netplay.c +++ b/netplay/netplay.c @@ -707,12 +707,6 @@ static bool init_tcp_socket(netplay_t *netplay, const char *server, struct addrinfo *res = NULL; struct addrinfo hints = {0}; -#if defined(_WIN32) || defined(HAVE_SOCKET_LEGACY) - hints.ai_family = AF_INET; -#else - hints.ai_family = AF_UNSPEC; -#endif - hints.ai_socktype = SOCK_STREAM; if (!server) hints.ai_flags = AI_PASSIVE;