more adns tidy ups
This commit is contained in:
parent
f209483a4e
commit
d8edceefce
10 changed files with 91 additions and 109 deletions
2
configure
vendored
2
configure
vendored
|
@ -22384,6 +22384,7 @@ rm -f conftest*
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for ac_func in socket \
|
||||
|
@ -22400,6 +22401,7 @@ for ac_func in socket \
|
|||
gettimeofday \
|
||||
inet_addr \
|
||||
inet_ntoa \
|
||||
inet_aton \
|
||||
inet_pton \
|
||||
inet_ntop \
|
||||
tcsetattr \
|
||||
|
|
|
@ -157,6 +157,7 @@ AC_CHECK_FUNCS( socket \
|
|||
gettimeofday \
|
||||
inet_addr \
|
||||
inet_ntoa \
|
||||
inet_aton \
|
||||
inet_pton \
|
||||
inet_ntop \
|
||||
tcsetattr \
|
||||
|
|
|
@ -33,16 +33,70 @@
|
|||
#ifndef ADNS_H_INCLUDED
|
||||
#define ADNS_H_INCLUDED
|
||||
|
||||
#define ADNS_API EXPORTFUNC
|
||||
|
||||
#ifdef WIN32
|
||||
#include "adns_win32.h"
|
||||
#if defined (_MSC_VER)
|
||||
#pragma warning(disable:4003)
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
/* ---------------- START OF C HEADER -------------- */
|
||||
|
||||
#include <Winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <limits.h>
|
||||
#include <malloc.h>
|
||||
#include <signal.h>
|
||||
|
||||
#define adns_socket_read(sck, data, len) recv(sck, (char *)data, len, 0)
|
||||
#define adns_socket_write(sck, data, len) send(sck, (char *)data, len, 0)
|
||||
|
||||
/* Win32 does not set errno on Winsock errors(!)
|
||||
* We have to map the winsock errors to errno manually
|
||||
* in order to support the original UNIX error hadnlig
|
||||
*/
|
||||
#define ADNS_CAPTURE_ERRNO {errno = WSAGetLastError(); WSASetLastError(errno);}
|
||||
#define ADNS_CLEAR_ERRNO {WSASetLastError(errno = 0);}
|
||||
|
||||
#define ENOBUFS WSAENOBUFS
|
||||
#define EWOULDBLOCK WSAEWOULDBLOCK
|
||||
#define EINPROGRESS WSAEINPROGRESS
|
||||
#define EMSGSIZE WSAEMSGSIZE
|
||||
#define ENOPROTOOPT WSAENOPROTOOPT
|
||||
|
||||
/*
|
||||
* UNIX system API for Win32
|
||||
* The following is a quick and dirty implementation of
|
||||
* some UNIX API calls in Win32.
|
||||
* They are used in the dll, but if your project have
|
||||
* it's own implementation of these system calls, simply
|
||||
* undefine ADNS_MAP_UNIXAPI.
|
||||
*/
|
||||
|
||||
struct iovec
|
||||
{
|
||||
char *iov_base;
|
||||
int iov_len;
|
||||
};
|
||||
|
||||
/*
|
||||
* Undef ADNS_MAP_UNIXAPI in the calling code to use natve calls
|
||||
*/
|
||||
ADNS_API int adns_writev (int FileDescriptor, const struct iovec * iov, int iovCount);
|
||||
ADNS_API int adns_getpid();
|
||||
|
||||
#define writev(FileDescriptor, iov, iovCount) adns_writev(FileDescriptor, iov, iovCount)
|
||||
#define getpid() adns_getpid()
|
||||
|
||||
/* ---------------- END OF C HEADER -------------- */
|
||||
#else
|
||||
# define ADNS_API
|
||||
# define adns_socket_read(sck, data, len) read(sck, data, len)
|
||||
# define adns_socket_write(sck, data, len) write(sck, data, len)
|
||||
# define ADNS_CAPTURE_ERRNO {}
|
||||
# define ADNS_CLEAR_ERRNO {}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" { /* I really dislike this - iwj. */
|
||||
#endif
|
||||
|
|
|
@ -56,75 +56,6 @@ extern "C"
|
|||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define ADNS_DLL
|
||||
|
||||
#if defined(ADNS_DLL)
|
||||
# ifdef ADNS_DLL_EXPORTS
|
||||
# define ADNS_API __declspec(dllexport)
|
||||
# else
|
||||
# define ADNS_API __declspec(dllimport)
|
||||
# endif /* ADNS_EXPORTS */
|
||||
#else
|
||||
# define ADNS_API
|
||||
#endif /* ADNS_DLL */
|
||||
|
||||
#if defined (_MSC_VER)
|
||||
#pragma warning(disable:4003)
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
/* ---------------- START OF C HEADER -------------- */
|
||||
|
||||
#include <Winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <limits.h>
|
||||
#include <malloc.h>
|
||||
#include <signal.h>
|
||||
|
||||
#define adns_socket_read(sck, data, len) recv(sck, (char *)data, len, 0)
|
||||
#define adns_socket_write(sck, data, len) send(sck, (char *)data, len, 0)
|
||||
|
||||
/* Win32 does not set errno on Winsock errors(!)
|
||||
* We have to map the winsock errors to errno manually
|
||||
* in order to support the original UNIX error hadnlig
|
||||
*/
|
||||
#define ADNS_CAPTURE_ERRNO {errno = WSAGetLastError(); WSASetLastError(errno);}
|
||||
#define ADNS_CLEAR_ERRNO {WSASetLastError(errno = 0);}
|
||||
|
||||
#define ENOBUFS WSAENOBUFS
|
||||
#define EWOULDBLOCK WSAEWOULDBLOCK
|
||||
#define EINPROGRESS WSAEINPROGRESS
|
||||
#define EMSGSIZE WSAEMSGSIZE
|
||||
#define ENOPROTOOPT WSAENOPROTOOPT
|
||||
|
||||
/*
|
||||
* UNIX system API for Win32
|
||||
* The following is a quick and dirty implementation of
|
||||
* some UNIX API calls in Win32.
|
||||
* They are used in the dll, but if your project have
|
||||
* it's own implementation of these system calls, simply
|
||||
* undefine ADNS_MAP_UNIXAPI.
|
||||
*/
|
||||
|
||||
struct iovec
|
||||
{
|
||||
char *iov_base;
|
||||
int iov_len;
|
||||
};
|
||||
|
||||
/*
|
||||
* Undef ADNS_MAP_UNIXAPI in the calling code to use natve calls
|
||||
*/
|
||||
ADNS_API int adns_gettimeofday(struct timeval *tv, struct timezone *tz);
|
||||
ADNS_API int adns_writev (int FileDescriptor, const struct iovec * iov, int iovCount);
|
||||
ADNS_API int adns_inet_aton(const char *cp, struct in_addr *inp);
|
||||
ADNS_API int adns_getpid();
|
||||
|
||||
#define gettimeofday(tv, tz) adns_gettimeofday(tv, tz)
|
||||
#define writev(FileDescriptor, iov, iovCount) adns_writev(FileDescriptor, iov, iovCount)
|
||||
#define inet_aton(ap, inp) adns_inet_aton(ap, inp)
|
||||
#define getpid() adns_getpid()
|
||||
|
||||
/* ---------------- END OF C HEADER -------------- */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
|
|
@ -137,6 +137,9 @@
|
|||
/* Define to 1 if you have the `inet_ntoa' function. */
|
||||
#undef HAVE_INET_NTOA
|
||||
|
||||
/* Define to 1 if you have the `inet_aton' function. */
|
||||
#undef HAVE_INET_ATON
|
||||
|
||||
/* Define to 1 if you have the `inet_ntop' function. */
|
||||
#undef HAVE_INET_NTOP
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@
|
|||
#define HAVE_GETPWUID 1
|
||||
|
||||
/* Define to 1 if you have the `gettimeofday' function. */
|
||||
#define HAVE_GETTIMEOFDAY 1
|
||||
/* #undef HAVE_GETTIMEOFDAY 1 */
|
||||
|
||||
/* HAVE_GNUC25_ATTRIB */
|
||||
/* #undef HAVE_GNUC25_ATTRIB */
|
||||
|
@ -103,6 +103,9 @@
|
|||
/* Define to 1 if you have the `inet_ntoa' function. */
|
||||
#define HAVE_INET_NTOA 1
|
||||
|
||||
/* Define to 1 if you have the `inet_aton' function. */
|
||||
/* #undef HAVE_INET_ATON */
|
||||
|
||||
/* Define to 1 if you have the `inet_pton' function. */
|
||||
/* #undef HAVE_INET_PTON */
|
||||
|
||||
|
|
|
@ -39,5 +39,17 @@ EXPORTFUNC char *strndup( const char *src, size_t count );
|
|||
#ifndef HAVE_INET_NTOP
|
||||
EXPORTFUNC char *inet_ntop( int af, const unsigned char *src, char *dst, size_t size );
|
||||
#endif /* HAVE_INET_NTOP */
|
||||
#ifndef HAVE_INET_ATON
|
||||
EXPORTFUNC int inet_aton( const char *name, struct in_addr *addr );
|
||||
#endif /* HAVE_INET_ATON */
|
||||
#ifndef HAVE_GETTIMEOFDAY
|
||||
struct timezone {
|
||||
int tz_minuteswest;
|
||||
int tz_dsttime;
|
||||
};
|
||||
|
||||
int gettimeofday(struct timeval *tv, struct timezone *tz);
|
||||
#endif /* HAVE_GETTIMEOFDAY */
|
||||
|
||||
|
||||
#endif /* _SUPPORT_H_ */
|
||||
|
|
|
@ -53,39 +53,7 @@ int adns_writev(int FileDescriptor, const struct iovec * iov, int iovCount)
|
|||
return r;
|
||||
}
|
||||
|
||||
int adns_inet_aton(const char *cp, struct in_addr *inp)
|
||||
{
|
||||
inp->s_addr = inet_addr(cp);
|
||||
return inp->s_addr != INADDR_ANY;
|
||||
}
|
||||
|
||||
int adns_getpid()
|
||||
{
|
||||
return GetCurrentProcessId();
|
||||
}
|
||||
|
||||
int gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||
{
|
||||
static __int64 Adjustment;
|
||||
__int64 now = 0;
|
||||
|
||||
if (!Adjustment)
|
||||
{
|
||||
SYSTEMTIME st = {1970,1,0,1,0,0,0};
|
||||
SystemTimeToFileTime(&st, (LPFILETIME)&Adjustment);
|
||||
}
|
||||
|
||||
if (tz)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
GetSystemTimeAsFileTime((LPFILETIME)&now);
|
||||
now -= Adjustment;
|
||||
|
||||
tv->tv_sec = (long)(now / 10000000);
|
||||
tv->tv_usec = (long)((now % 10000000) / 10);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\include;..\lib\curl;..\lib\pcre;win32;..\lib\event"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;ADNS_MAP_UNIXAPI;NEOSTATSCORE;ADNS_DLL_EXPORTS;PCRE_SPY;HAVE_CONFIG_H"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;NEOSTATSCORE;PCRE_SPY;HAVE_CONFIG_H"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="5"
|
||||
|
@ -71,7 +71,7 @@
|
|||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="..\include;..\lib\curl;..\lib\pcre;win32;..\lib\event"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;ADNS_MAP_UNIXAPI;NEOSTATSCORE;ADNS_DLL_EXPORTS;DLL_EXPORT;HAVE_CONFIG_H"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;NEOSTATSCORE;DLL_EXPORT;HAVE_CONFIG_H"
|
||||
RuntimeLibrary="4"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
|
@ -301,9 +301,6 @@
|
|||
<File
|
||||
RelativePath="..\include\adns.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\include\adns_win32.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\include\adnsdlist.h">
|
||||
</File>
|
||||
|
|
|
@ -193,3 +193,14 @@ char *inet_ntop(int af, const unsigned char *src, char *dst, size_t size)
|
|||
return dst;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_INET_ATON
|
||||
/* Convert from "a.b.c.d" IP address string into an in_addr structure.
|
||||
* Return 0 on failure, 1 on success.
|
||||
*/
|
||||
int inet_aton( const char *name, struct in_addr *addr )
|
||||
{
|
||||
addr->s_addr = inet_addr(name);
|
||||
return ( addr->s_addr == INADDR_NONE ) ? 0 : 1;
|
||||
}
|
||||
#endif
|
||||
|
|
Reference in a new issue