Add inet_ntop function for mingw compiler
This commit is contained in:
parent
388937a487
commit
226eeb2718
@ -25,16 +25,11 @@
|
||||
#include "utils/time.hpp"
|
||||
|
||||
#include <string.h>
|
||||
#if defined(WIN32) && !defined(__MINGW32__)
|
||||
#if defined(WIN32)
|
||||
# include "Ws2tcpip.h"
|
||||
# define inet_ntop InetNtop
|
||||
|
||||
// TODO: It's very ugly hack which allows to compile STK on windows using gcc.
|
||||
// Solution would be nice seen.
|
||||
#elif defined(__MINGW32__)
|
||||
# include "Ws2tcpip.h"
|
||||
# define inet_ntop
|
||||
|
||||
# if defined(InetNtop)
|
||||
# define inet_ntop InetNtop
|
||||
# endif
|
||||
#else
|
||||
# include <arpa/inet.h>
|
||||
# include <errno.h>
|
||||
@ -42,6 +37,27 @@
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
|
||||
#if !defined(inet_ntop)
|
||||
const char* inet_ntop(int af, const void* src, char* dst, int cnt)
|
||||
{
|
||||
struct sockaddr_in srcaddr;
|
||||
|
||||
memset(&srcaddr, 0, sizeof(struct sockaddr_in));
|
||||
memcpy(&(srcaddr.sin_addr), src, sizeof(srcaddr.sin_addr));
|
||||
|
||||
srcaddr.sin_family = af;
|
||||
if (WSAAddressToString((struct sockaddr*) &srcaddr,
|
||||
sizeof(struct sockaddr_in), 0, dst, (LPDWORD) &cnt) != 0)
|
||||
{
|
||||
DWORD rv = WSAGetLastError();
|
||||
printf("WSAAddressToString() : %d\n",rv);
|
||||
return NULL;
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
FILE* STKHost::m_log_file = NULL;
|
||||
pthread_mutex_t STKHost::m_log_mutex;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user