iOS: - tested with iOS SDK 4.2 - running on iOS 4.3.x
FreeBSD:- tested with 8.2
OpenSolaris
-Windows:- tested on Windows 7 using Visual Studio 10
+Windows:- tested on Windows 7 64 and Windows XP 32 using Visual Studio 10 (see README.win32.txt for build instructions)
Cygwin
1. checkout git://github.com/Memphiz/oncrpc-win32.git project (branch hyper!)
-2. build oncrpc-win32 project (see README.win32 in the projects dir)
-3. checkout libnfs (branch win32)
-4. adapt oncrpc-win32 path in win32/win32build.bat
-4. build libnfs with cd win32;win32build.bat
-5. copy lib/libnfs.dll and <oncrpc-win32-path>/win32/bin/liboncrpc.dll to the dir where the executable is...
+2. build oncrpc-win32 project (see README.libnfs in the projects dir)
+3. checkout libnfs ("parallel" to oncrpc-win32)
+4. load vs2010 project from win32/libnfs/libnfs.sln
+5. build libnfs and nfsclient-sync
#include <sys/sockio.h>
#endif
-#include <fcntl.h>
-#include <errno.h>
#include "libnfs.h"
#include "libnfs-raw.h"
#include "libnfs-raw-mount.h"
nfs_set_error(nfs, "statvfs call failed with \"%s\"", (char *)data);
return;
}
-#ifndef WIN32
+
memcpy(cb_data->return_data, data, sizeof(struct statvfs));
-#else
- cb_data->return_data=NULL;
-#endif/**/
}
int nfs_statvfs(struct nfs_context *nfs, const char *path, struct statvfs *svfs)
-#if !defined(WIN32)
void free_nfs_srvr_list(struct nfs_server_list *srv)
{
while (srv != NULL) {
srv_data->srvrs = srvr;
}
-#ifndef WIN32
+#ifdef WIN32
+
+static int send_nfsd_probes(struct rpc_context *rpc, INTERFACE_INFO *InterfaceList, int numIfs, struct nfs_list_data *data)
+{
+ int i=0;
+
+ for(i = 0; i < numIfs; i++)
+ {
+ SOCKADDR *pAddress;
+ char bcdd[16];
+ unsigned long nFlags = 0;
+
+ pAddress = (SOCKADDR *) & (InterfaceList[i].iiBroadcastAddress);
+
+ if(pAddress->sa_family != AF_INET)
+ continue;
+
+ nFlags = InterfaceList[i].iiFlags;
+
+ if (!(nFlags & IFF_UP))
+ {
+ continue;
+ }
+
+ if (nFlags & IFF_LOOPBACK)
+ {
+ continue;
+ }
+
+ if (!(nFlags & IFF_BROADCAST))
+ {
+ continue;
+ }
+
+ if (getnameinfo(pAddress, sizeof(struct sockaddr_in), &bcdd[0], sizeof(bcdd), NULL, 0, NI_NUMERICHOST) < 0)
+ {
+ continue;
+ }
+
+ if (rpc_set_udp_destination(rpc, bcdd, 111, 1) < 0)
+ {
+ return -1;
+ }
+
+ if (rpc_pmap_callit_async(rpc, MOUNT_PROGRAM, 2, 0, NULL, 0, callit_cb, data) < 0)
+ {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+struct nfs_server_list *nfs_find_local_servers(void)
+{
+ struct rpc_context *rpc;
+ struct nfs_list_data data = {0, NULL};
+ struct timeval tv_start, tv_current;
+ int loop;
+ struct pollfd pfd;
+ INTERFACE_INFO InterfaceList[20];
+ unsigned long nBytesReturned;
+ int nNumInterfaces = 0;
+
+ rpc = rpc_init_udp_context();
+ if (rpc == NULL)
+ {
+ return NULL;
+ }
+
+ if (rpc_bind_udp(rpc, "0.0.0.0", 0) < 0)
+ {
+ rpc_destroy_context(rpc);
+ return NULL;
+ }
+
+ if (WSAIoctl(rpc_get_fd(rpc), SIO_GET_INTERFACE_LIST, 0, 0, &InterfaceList, sizeof(InterfaceList), &nBytesReturned, 0, 0) == SOCKET_ERROR)
+ {
+ return NULL;
+ }
+
+ nNumInterfaces = nBytesReturned / sizeof(INTERFACE_INFO);
+
+ for (loop=0; loop<3; loop++)
+ {
+ if (send_nfsd_probes(rpc, InterfaceList, nNumInterfaces, &data) != 0)
+ {
+ rpc_destroy_context(rpc);
+ return NULL;
+ }
+
+ win32_gettimeofday(&tv_start, NULL);
+ for(;;)
+ {
+ int mpt;
+
+ pfd.fd = rpc_get_fd(rpc);
+ pfd.events = rpc_which_events(rpc);
+
+ win32_gettimeofday(&tv_current, NULL);
+ mpt = 1000
+ - (tv_current.tv_sec *1000 + tv_current.tv_usec / 1000)
+ + (tv_start.tv_sec *1000 + tv_start.tv_usec / 1000);
+
+ if (poll(&pfd, 1, mpt) < 0)
+ {
+ free_nfs_srvr_list(data.srvrs);
+ rpc_destroy_context(rpc);
+ return NULL;
+ }
+ if (pfd.revents == 0)
+ {
+ break;
+ }
+
+ if (rpc_service(rpc, pfd.revents) < 0)
+ {
+ break;
+ }
+ }
+ }
+
+ rpc_destroy_context(rpc);
+
+ if (data.status != 0)
+ {
+ free_nfs_srvr_list(data.srvrs);
+ return NULL;
+ }
+ return data.srvrs;
+}
+#else
+
static int send_nfsd_probes(struct rpc_context *rpc, struct ifconf *ifc, struct nfs_list_data *data)
{
char *ptr;
return 0;
}
-#endif/*WIN32 TODO implement this with win32api FIXME*/
struct nfs_server_list *nfs_find_local_servers(void)
{
struct rpc_context *rpc;
struct nfs_list_data data = {0, NULL};
-#ifndef WIN32
struct timeval tv_start, tv_current;
struct ifconf ifc;
int size, loop;
free_nfs_srvr_list(data.srvrs);
return NULL;
}
-#endif/*WIN32 - FIXME redef it when send_nfsd_probes is implemented for win32*/
return data.srvrs;
}
-#endif
+#endif//WIN32
mount_free_export_list
mount_getexports
mount_getexports_async
+nfs_find_local_servers
+free_nfs_srvr_list
nfs_access
nfs_access_async
nfs_chmod
FSSTAT3res *res;
struct nfs_cb_data *data = private_data;
struct nfs_context *nfs = data->nfs;
-#ifndef WIN32
struct statvfs svfs;
-#endif/*WIN32*/
if (status == RPC_STATUS_ERROR) {
data->cb(-EFAULT, nfs, command_data, data->private_data);
return;
}
-#ifndef WIN32
svfs.f_bsize = 4096;
svfs.f_frsize = 4096;
svfs.f_blocks = res->FSSTAT3res_u.resok.tbytes/4096;
svfs.f_namemax = 256;
data->cb(0, nfs, &svfs, data->private_data);
-#else
- data->cb(0, nfs,NULL, data->private_data);
-#endif/*WIN32*/
free_nfs_cb_data(data);
}
return nfs->export;
}
-
-#if defined(WIN32)
-int poll(struct pollfd *fds, int nfsd, int timeout)
-{
- fd_set rfds, wfds, efds;
- int ret;
-
- FD_ZERO(&rfds);
- FD_ZERO(&wfds);
- FD_ZERO(&efds);
- if (fds->events & POLLIN) {
- FD_SET(fds->fd, &rfds);
- }
- if (fds->events & POLLOUT) {
- FD_SET(fds->fd, &wfds);
- }
- FD_SET(fds->fd, &efds);
- select(fds->fd + 1, &rfds, &wfds, &efds, NULL);
- fds->revents = 0;
- if (FD_ISSET(fds->fd, &rfds)) {
- fds->revents |= POLLIN;
- }
- if (FD_ISSET(fds->fd, &wfds)) {
- fds->revents |= POLLOUT;
- }
- if (FD_ISSET(fds->fd, &efds)) {
- fds->revents |= POLLHUP;
- }
- return 1;
-}
-#endif
-
#include <netdb.h>
#endif/*WIN32*/
-#if defined(WIN32)
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#include <basetsd.h>
-#define ssize_t SSIZE_T
-#define MSG_DONTWAIT 0
-#else
-#include <unistd.h>
-#include <poll.h>
-#include <arpa/inet.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <netdb.h>
-#endif
-
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "libnfs-private.h"
#include "slist.h"
+#ifdef WIN32
+//has to be included after stdlib!!
+#include "win32_errnowrapper.h"
+#endif
+
+
static int rpc_disconnect_requeue(struct rpc_context *rpc);
static void set_nonblocking(int fd)
int rpc_service(struct rpc_context *rpc, int revents)
{
if (revents & POLLERR) {
+#ifdef WIN32
char err = 0;
+#else
+ int err = 0;
+#endif
socklen_t err_size = sizeof(err);
if (getsockopt(rpc->fd, SOL_SOCKET, SO_ERROR,
set_nonblocking(rpc->fd);
#if defined(WIN32)
- if (connect(rpc->fd, (struct sockaddr *)&s, socksize) == 0 && GetLastError() != WSAEINPROGRESS )
+ if (connect(rpc->fd, (struct sockaddr *)&s, socksize) == 0 && errno != EINPROGRESS )
#else
if (connect(rpc->fd, (struct sockaddr *)&s, socksize) != 0 && errno != EINPROGRESS)
#endif
#include "libnfs-private.h"
#include "libnfs-raw-nfs.h"
-#ifdef WIN32
-#define bzero(a,b) memset((a),(0),(b))
-#endif/*WIN32*/
-
char *nfsstat3_to_str(int error)
{
switch (error) {
#include <sys/stat.h>
#endif/*WIN32*/
-#if defined(WIN32)
-#include <winsock2.h>
-#endif
-
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "win32_compat.h"
#endif/*WIN32*/
-#if defined(WIN32)
-#include <winsock2.h>
-#endif
-
#include <stdio.h>
#include <rpc/rpc.h>
#include <rpc/xdr.h>
#include "win32_compat.h"
#endif/*WIN32*/
-#if defined(WIN32)
-#include <winsock2.h>
-#endif
-
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
- <CharacterSet>Unicode</CharacterSet>
+ <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
- <CharacterSet>Unicode</CharacterSet>
+ <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
- <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;_WIN32_WINNT=0x0501;_U_=;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;_WIN32_WINNT=0x0501;_U_=;_USE_32BIT_TIME_T;__STDC_CONSTANT_MACROS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\..\oncrpc-win32\win32\include;..\..\include;..\..\.;..\..\win32;..\..\mount;..\..\nfs;..\..\lib</AdditionalIncludeDirectories>
<CompileAs>Default</CompileAs>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>..\..\lib\libnfs-win32.def</ModuleDefinitionFile>
<AdditionalDependencies>oncrpc.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <IgnoreSpecificDefaultLibraries>MSVCRT</IgnoreSpecificDefaultLibraries>
</Link>
<PreBuildEvent>
<Command>copy $(ProjectDir)..\..\nfs\nfs.x $(ProjectDir)..\..\nfs\libnfs-raw-nfs.x
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
- <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;_WIN32_WINNT=0x0501;_U_=;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;_WIN32_WINNT=0x0501;_U_=;_USE_32BIT_TIME_T;__STDC_CONSTANT_MACROS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\..\oncrpc-win32\win32\include;..\..\include;..\..\.;..\..\win32;..\..\mount;..\..\nfs;..\..\lib</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
</ClCompile>
#include "win32_compat.h"
#include <errno.h>
#include <stdio.h>
+#include < time.h >
+
#undef poll
#undef socket
#undef connect
#undef inet_aton
#undef gettimeofday
#undef stat
-#define bzero(a,b) memset((a),(0),(b))
#define assert(a)
/* Windows needs this header file for the implementation of inet_aton() */
int win32_inet_pton(int af, const char * src, void * dst)
{
- int temp = sizeof(struct sockaddr_in);
- int ret = -1;
- int len = strlen(src) + 1;
- wchar_t *srcNonConst = (wchar_t *)malloc(len);
- memset(srcNonConst, 0, len);
- MultiByteToWideChar(CP_ACP, NULL, src, -1, srcNonConst, len);
-
- if( WSAStringToAddress(srcNonConst,af,NULL,(LPSOCKADDR)dst,&temp) == 0 )
- {
- ret = 1;
- }
- else
- {
- if( WSAGetLastError() == WSAEINVAL )
- {
- ret = -1;
- }
- }
- //free(srcNonConst);
- return ret;
-}
-
-/*
- * Check whether "cp" is a valid ascii representation of an Internet address
- * and convert to a binary address. Returns 1 if the address is valid, 0 if
- * not. This replaces inet_addr, the return value from which cannot
- * distinguish between failure and a local broadcast address.
- *
- * This implementation of the standard inet_aton() function was copied
- * (with trivial modifications) from the OpenBSD project.
- */
-int
-win32_inet_aton(const char *cp, struct in_addr *addr)
-{
- register unsigned int val;
- register int base, n;
- register char c;
- unsigned int parts[4];
- register unsigned int *pp = parts;
-
- assert(sizeof(val) == 4);
-
- c = *cp;
- while(1) {
- /*
- * Collect number up to ``.''.
- * Values are specified as for C:
- * 0x=hex, 0=octal, isdigit=decimal.
- */
- if(!isdigit(c))
- return (0);
- val = 0; base = 10;
- if(c == '0') {
- c = *++cp;
- if(c == 'x' || c == 'X')
- base = 16, c = *++cp;
- else
- base = 8;
- }
- while(1) {
- if(isascii(c) && isdigit(c)) {
- val = (val * base) + (c - '0');
- c = *++cp;
- } else if(base == 16 && isascii(c) && isxdigit(c)) {
- val = (val << 4) |
- (c + 10 - (islower(c) ? 'a' : 'A'));
- c = *++cp;
- } else
- break;
- }
- if(c == '.') {
- /*
- * Internet format:
- * a.b.c.d
- * a.b.c (with c treated as 16 bits)
- * a.b (with b treated as 24 bits)
- */
- if(pp >= parts + 3)
- return (0);
- *pp++ = val;
- c = *++cp;
- } else
- break;
- }
- /*
- * Check for trailing characters.
- */
- if(c != '\0' && (!isascii(c) || !isspace(c)))
- return (0);
- /*
- * Concoct the address according to
- * the number of parts specified.
- */
- n = pp - parts + 1;
- switch(n) {
-
- case 0:
- return (0); /* initial nondigit */
-
- case 1: /* a -- 32 bits */
- break;
-
- case 2: /* a.b -- 8.24 bits */
- if((val > 0xffffff) || (parts[0] > 0xff))
- return (0);
- val |= parts[0] << 24;
- break;
-
- case 3: /* a.b.c -- 8.8.16 bits */
- if((val > 0xffff) || (parts[0] > 0xff) || (parts[1] > 0xff))
- return (0);
- val |= (parts[0] << 24) | (parts[1] << 16);
- break;
-
- case 4: /* a.b.c.d -- 8.8.8.8 bits */
- if((val > 0xff) || (parts[0] > 0xff) ||
- (parts[1] > 0xff) || (parts[2] > 0xff))
- return (0);
- val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
- break;
- }
- if(addr)
- addr->s_addr = htonl(val);
- return (1);
-}
-
-unsigned int
-win32_sleep(unsigned int seconds)
-{
- Sleep(seconds * 1000);
- return 0;
-}
-
-int win32_poll(struct pollfd *fds, int nfsd, int timeout)
-{
- fd_set rfds, wfds, efds;
- int ret;
+ struct sockaddr_in sa;
+ int len = sizeof(SOCKADDR);
+ int ret = -1;
+ int strLen = strlen(src) + 1;
+#ifdef UNICODE
+ wchar_t *srcNonConst = (wchar_t *)malloc(strLen*sizeof(wchar_t));
+ memset(srcNonConst, 0, strLen);
+ MultiByteToWideChar(CP_ACP, 0, src, -1, srcNonConst, strLen);
+#else
+ char *srcNonConst = (char *)malloc(strLen);
+ memset(srcNonConst, 0, strLen);
+ strncpy(srcNonConst, src, strLen);
+#endif
- FD_ZERO(&rfds);
- FD_ZERO(&wfds);
- FD_ZERO(&efds);
- if (fds->events & POLLIN)
- {
- FD_SET(fds->fd, &rfds);
- }
- if (fds->events & POLLOUT)
- {
- FD_SET(fds->fd, &wfds);
- }
- FD_SET(fds->fd, &efds);
- ret = select(fds->fd + 1, &rfds, &wfds, &efds, NULL);
- fds->revents = 0;
-
- if (FD_ISSET(fds->fd, &rfds))
- {
- fds->revents |= POLLIN;
- }
-
- if (FD_ISSET(fds->fd, &wfds))
+ if( WSAStringToAddress(srcNonConst,af,NULL,(LPSOCKADDR)&sa,&len) == 0 )
{
- fds->revents |= POLLOUT;
+ ret = 1;
}
-
- if (FD_ISSET(fds->fd, &efds))
+ else
{
- fds->revents |= POLLHUP;
+ if( WSAGetLastError() == WSAEINVAL )
+ {
+ ret = -1;
+ }
}
+ free(srcNonConst);
+ memcpy(dst, &sa.sin_addr, sizeof(struct in_addr));
return ret;
}
-/*int win32_poll(struct pollfd *fds, unsigned int nfds, int timo)
+int win32_poll(struct pollfd *fds, unsigned int nfds, int timo)
{
- struct timeval timeout, *toptr;
- fd_set ifds, ofds, efds, *ip, *op;
- int i, rc;
-
- // Set up the file-descriptor sets in ifds, ofds and efds.
- FD_ZERO(&ifds);
- FD_ZERO(&ofds);
- FD_ZERO(&efds);
- for (i = 0, op = ip = 0; i < nfds; ++i) {
- fds[i].revents = 0;
- if(fds[i].events & (POLLIN|POLLPRI)) {
- ip = &ifds;
- FD_SET(fds[i].fd, ip);
- }
- if(fds[i].events & POLLOUT) {
- op = &ofds;
- FD_SET(fds[i].fd, op);
- }
- FD_SET(fds[i].fd, &efds);
- }
-
- // Set up the timeval structure for the timeout parameter
- if(timo < 0) {
- toptr = 0;
- } else {
- toptr = &timeout;
- timeout.tv_sec = timo / 1000;
- timeout.tv_usec = (timo - timeout.tv_sec * 1000) * 1000;
+ struct timeval timeout, *toptr;
+ fd_set ifds, ofds, efds, *ip, *op;
+ unsigned int i;
+ int rc;
+
+ // Set up the file-descriptor sets in ifds, ofds and efds.
+ FD_ZERO(&ifds);
+ FD_ZERO(&ofds);
+ FD_ZERO(&efds);
+ for (i = 0, op = ip = 0; i < nfds; ++i)
+ {
+ fds[i].revents = 0;
+ if(fds[i].events & (POLLIN|POLLPRI))
+ {
+ ip = &ifds;
+ FD_SET(fds[i].fd, ip);
+ }
+ if(fds[i].events & POLLOUT)
+ {
+ op = &ofds;
+ FD_SET(fds[i].fd, op);
}
+ FD_SET(fds[i].fd, &efds);
+ }
+
+ // Set up the timeval structure for the timeout parameter
+ if(timo < 0)
+ {
+ toptr = 0;
+ }
+ else
+ {
+ toptr = &timeout;
+ timeout.tv_sec = timo / 1000;
+ timeout.tv_usec = (timo - timeout.tv_sec * 1000) * 1000;
+ }
#ifdef DEBUG_POLL
- printf("Entering select() sec=%ld usec=%ld ip=%lx op=%lx\n",
- (long)timeout.tv_sec, (long)timeout.tv_usec, (long)ip, (long)op);
+ printf("Entering select() sec=%ld usec=%ld ip=%lx op=%lx\n",
+ (long)timeout.tv_sec, (long)timeout.tv_usec, (long)ip, (long)op);
#endif
- rc = select(0, ip, op, &efds, toptr);
+ rc = select(0, ip, op, &efds, toptr);
#ifdef DEBUG_POLL
- printf("Exiting select rc=%d\n", rc);
+ printf("Exiting select rc=%d\n", rc);
#endif
- if(rc <= 0)
- return rc;
+ if(rc <= 0)
+ return rc;
- if(rc > 0) {
- for (i = 0; i < nfds; ++i) {
- int fd = fds[i].fd;
- if(fds[i].events & (POLLIN|POLLPRI) && FD_ISSET(fd, &ifds))
- fds[i].revents |= POLLIN;
- if(fds[i].events & POLLOUT && FD_ISSET(fd, &ofds))
- fds[i].revents |= POLLOUT;
- if(FD_ISSET(fd, &efds))
- // Some error was detected ... should be some way to know.
- fds[i].revents |= POLLHUP;
+ if(rc > 0)
+ {
+ for (i = 0; i < nfds; ++i)
+ {
+ int fd = fds[i].fd;
+ if(fds[i].events & (POLLIN|POLLPRI) && FD_ISSET(fd, &ifds))
+ fds[i].revents |= POLLIN;
+ if(fds[i].events & POLLOUT && FD_ISSET(fd, &ofds))
+ fds[i].revents |= POLLOUT;
+ if(FD_ISSET(fd, &efds)) // Some error was detected ... should be some way to know.
+ fds[i].revents |= POLLHUP;
#ifdef DEBUG_POLL
- printf("%d %d %d revent = %x\n",
- FD_ISSET(fd, &ifds), FD_ISSET(fd, &ofds), FD_ISSET(fd, &efds),
- fds[i].revents
- );
+ printf("%d %d %d revent = %x\n",
+ FD_ISSET(fd, &ifds), FD_ISSET(fd, &ofds), FD_ISSET(fd, &efds),
+ fds[i].revents
+ );
#endif
- }
}
- return rc;
+ }
+ return rc;
}
-*/
+
+#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
+ #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
+#else
+ #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
+#endif
+
+struct timezone
+{
+ int tz_minuteswest; /* minutes W of Greenwich */
+ int tz_dsttime; /* type of dst correction */
+};
+
+int win32_gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+ FILETIME ft;
+ unsigned __int64 tmpres = 0;
+ static int tzflag;
+
+ if (NULL != tv)
+ {
+ GetSystemTimeAsFileTime(&ft);
+
+ tmpres |= ft.dwHighDateTime;
+ tmpres <<= 32;
+ tmpres |= ft.dwLowDateTime;
+
+ /*converting file time to unix epoch*/
+ tmpres -= DELTA_EPOCH_IN_MICROSECS;
+ tmpres /= 10; /*convert into microseconds*/
+ tv->tv_sec = (long)(tmpres / 1000000UL);
+ tv->tv_usec = (long)(tmpres % 1000000UL);
+ }
+
+ if (NULL != tz)
+ {
+ if (!tzflag)
+ {
+ _tzset();
+ tzflag++;
+ }
+ tz->tz_minuteswest = _timezone / 60;
+ tz->tz_dsttime = _daylight;
+ }
+
+ return 0;
+}
+
#endif
#include <winsock2.h>
#include <ws2tcpip.h>
+#include <Ws2ipdef.h>
#include <basetsd.h>
#include <io.h>
#include <sys/stat.h>
typedef int gid_t;
typedef int socklen_t;
-
#define S_IRUSR 0000400
#define S_IWUSR 0000200
#define S_IXUSR 0000100
/* Wrapper macros to call misc. functions win32 is missing */
#define poll(x, y, z) win32_poll(x, y, z)
-#define inet_aton(x, y) win32_inet_aton(x, y)
#define inet_pton(x,y,z) win32_inet_pton(x,y,z)
-int win32_inet_aton(const char *, struct in_addr *);
int win32_inet_pton(int af, const char * src, void * dst);
-int win32_poll(struct pollfd *fds, int nfsd, int timeout);
+int win32_poll(struct pollfd *fds, unsigned int nfsd, int timeout);
+int win32_gettimeofday(struct timeval *tv, struct timezone *tz);
#endif//win32_COMPAT_H_
#endif//WIN32
--- /dev/null
+#ifndef WIN32_ERRNOWRAPPER_H_
+#define WIN32_ERRNOWRAPPER_H_
+
+#undef errno
+#define errno WSAGetLastError()
+#undef EAGAIN
+#undef EWOULDBLOCK
+#undef EINTR
+#undef EINPROGRESS
+
+#define EWOULDBLOCK WSAEWOULDBLOCK
+#define EAGAIN WSAEWOULDBLOCK //same on windows
+#define EINTR WSAEINTR
+#define EINPROGRESS WSAEINPROGRESS
+#endif //WIN32_ERRNOWRAPPER_H_