Some code de-duplication

This commit is contained in:
twinaphex 2016-05-02 18:54:55 +02:00
parent 00a49d068e
commit b25b2a0e6c
4 changed files with 10 additions and 22 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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:

View File

@ -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;