Skip to content
Snippets Groups Projects
Commit b1dbfa84 authored by deuce's avatar deuce
Browse files

Move getaddrinfo() stuff into sockwrap.h

Fix inet_addrtop() for Win32.
parent e9f87f95
No related branches found
No related tags found
No related merge requests found
......@@ -7,17 +7,6 @@
#include <sockwrap.h>
#include <multisock.h>
#ifdef _WIN32
#undef socklen_t
#include <ws2tcpip.h>
# ifndef AI_ADDRCONFIG
# define AI_ADDRCONFIG 0x400 // Vista or later
# endif
# ifndef AI_NUMERICSERV
# define AI_NUMERICSERV 0 // Not supported by Win32
# endif
#endif
struct xpms_set *xpms_create(unsigned int retries, unsigned int wait_secs,
int (*lprintf)(int level, const char *fmt, ...))
{
......@@ -70,10 +59,8 @@ BOOL xpms_add(struct xpms_set *xpms_set, int domain, int type,
hints.ai_family=domain;
hints.ai_socktype=type;
hints.ai_protocol=protocol;
hints.ai_flags=AI_NUMERICSERV;
#ifdef AI_ADDRCONFIG
hints.ai_flags|=AI_NUMERICSERV;
hints.ai_flags|=AI_ADDRCONFIG;
#endif
sprintf(port_str, "%hu", port);
if((ret=getaddrinfo(addr, port_str, &hints, &res))!=0) {
if(xpms_set->lprintf)
......
......@@ -42,8 +42,6 @@
#include <stdio.h> /* SEEK_SET */
#include <string.h>
#if defined(_WIN32)
#undef socklen_t
#include <ws2tcpip.h>
#include <malloc.h> /* alloca() on Win32 */
#endif
......@@ -391,6 +389,13 @@ int nonblocking_connect(SOCKET sock, struct sockaddr* addr, size_t size, unsigne
const char *inet_addrtop(SOCKADDR *in, char *dest, size_t size)
{
#ifdef _WIN32
DWORD dsize=size;
if(WSAAddressToString(in, SOCK_MAXADDRLEN, NULL, dest, &dsize)==SOCKET_ERROR)
return NULL;
return dest;
#else
switch(in->sa_family) {
case AF_INET:
return inet_ntop(in->sa_family, &((struct sockaddr_in *)in)->sin_addr, dest, size);
......@@ -400,6 +405,7 @@ const char *inet_addrtop(SOCKADDR *in, char *dest, size_t size)
safe_snprintf(dest, size, "<unknown address>");
return NULL;
}
#endif
}
uint16_t inet_addrport(SOCKADDR *in)
......
......@@ -48,8 +48,10 @@
#ifndef _WINSOCKAPI_
#include <winsock2.h> /* socket/bind/etc. */
#include <mswsock.h> /* Microsoft WinSock2 extensions */
#include <ws2tcpip.h> /* More stuff */
#define SOCK_MAXADDRLEN sizeof(SOCKADDR_STORAGE)
/* Let's agree on a standard WinSock symbol here, people */
#define _WINSOCKAPI_
#define _WINSOCKAPI_
#endif
#elif defined __unix__ /* Unix-variant */
......@@ -150,12 +152,18 @@ typedef struct {
#define s_addr S_un.S_addr
#define socklen_t int
static int wsa_error;
#define ERROR_VALUE ((wsa_error=WSAGetLastError())>0 ? wsa_error-WSABASEERR : wsa_error)
#define sendsocket(s,b,l) send(s,b,l,0)
/* For getaddrinfo() */
#ifndef AI_ADDRCONFIG
# define AI_ADDRCONFIG 0x400 // Vista or later
#endif
#ifndef AI_NUMERICSERV
# define AI_NUMERICSERV 0 // Not supported by Win32
#endif
#else /* BSD sockets */
/* WinSock-isms */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment