#ifndef _LIBSLIRP_H
#define _LIBSLIRP_H
+#ifdef _WIN32
+#include <winsock2.h>
+#else
#include <sys/select.h>
+#endif
void slirp_init(void);
#endif
#define TOWRITEMAX 512
-#define min(x,y) ((x) < (y) ? (x) : (y))
extern struct timeval tt;
extern int link_up;
bind(s, (struct sockaddr *)&addr, addrlen) < 0 ||
listen(s, 1) < 0) {
lprint("Error: inet socket: %s\n", strerror(errno));
- close(s);
+ closesocket(s);
return 0;
}
* of connect() fail in the child process
*/
so->s = accept(s, (struct sockaddr *)&addr, &addrlen);
- close(s);
+ closesocket(s);
opt = 1;
setsockopt(so->s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int));
opt = 1;
#ifdef FIONBIO
int opt = 1;
- ioctl(fd, FIONBIO, &opt);
+ ioctlsocket(fd, FIONBIO, &opt);
#else
int opt;
#ifdef FIONBIO
int opt = 0;
- ioctl(fd, FIONBIO, &opt);
+ ioctlsocket(fd, FIONBIO, &opt);
#else
int opt;
* ottherwise it'll arrive out of order, and hence corrupt
*/
if (!so->so_rcv.sb_cc)
- ret = write(so->s, m->m_data, m->m_len);
+ ret = send(so->s, m->m_data, m->m_len, 0);
if (ret <= 0) {
/*
static int get_dns_addr(struct in_addr *pdns_addr)
{
- /* XXX: add it */
- return -1;
+ FIXED_INFO *FixedInfo=NULL;
+ ULONG BufLen;
+ DWORD ret;
+ IP_ADDR_STRING *pIPAddr;
+ struct in_addr tmp_addr;
+
+ FixedInfo = (FIXED_INFO *)GlobalAlloc(GPTR, sizeof(FIXED_INFO));
+ BufLen = sizeof(FIXED_INFO);
+
+ if (ERROR_BUFFER_OVERFLOW == GetNetworkParams(FixedInfo, &BufLen)) {
+ if (FixedInfo) {
+ GlobalFree(FixedInfo);
+ FixedInfo = NULL;
+ }
+ FixedInfo = GlobalAlloc(GPTR, BufLen);
+ }
+
+ if ((ret = GetNetworkParams(FixedInfo, &BufLen)) != ERROR_SUCCESS) {
+ printf("GetNetworkParams failed. ret = %08x\n", (u_int)ret );
+ if (FixedInfo) {
+ GlobalFree(FixedInfo);
+ FixedInfo = NULL;
+ }
+ return -1;
+ }
+
+ pIPAddr = &(FixedInfo->DnsServerList);
+ inet_aton(pIPAddr->IpAddress.String, &tmp_addr);
+ *pdns_addr = tmp_addr;
+#if 0
+ printf( "DNS Servers:\n" );
+ printf( "DNS Addr:%s\n", pIPAddr->IpAddress.String );
+
+ pIPAddr = FixedInfo -> DnsServerList.Next;
+ while ( pIPAddr ) {
+ printf( "DNS Addr:%s\n", pIPAddr ->IpAddress.String );
+ pIPAddr = pIPAddr ->Next;
+ }
+#endif
+ if (FixedInfo) {
+ GlobalFree(FixedInfo);
+ FixedInfo = NULL;
+ }
+ return 0;
}
#else
#endif
+#ifdef _WIN32
+void slirp_cleanup(void)
+{
+ WSACleanup();
+}
+#endif
+
void slirp_init(void)
{
// debug_init("/tmp/slirp.log", DEBUG_DEFAULT);
+#ifdef _WIN32
+ {
+ WSADATA Data;
+ WSAStartup(MAKEWORD(2,0), &Data);
+ atexit(slirp_cleanup);
+ }
+#endif
+
link_up = 1;
if_init();
/*
* curtime kept to an accuracy of 1ms
*/
+#ifdef _WIN32
+static void updtime(void)
+{
+ struct _timeb tb;
+
+ _ftime(&tb);
+ curtime = (u_int)tb.time * (u_int)1000;
+ curtime += (u_int)tb.millitm;
+}
+#else
static void updtime(void)
{
gettimeofday(&tt, 0);
if ((tt.tv_usec % 1000) >= 500)
curtime++;
}
+#endif
void slirp_select_fill(int *pnfds,
fd_set *readfds, fd_set *writefds, fd_set *xfds)
#include "config.h"
#include "slirp_config.h"
+#ifdef _WIN32
+# include <inttypes.h>
+
+typedef uint8_t u_int8_t;
+typedef uint16_t u_int16_t;
+typedef uint32_t u_int32_t;
+typedef uint64_t u_int64_t;
+typedef char *caddr_t;
+
+# include <winsock2.h>
+# include <sys/timeb.h>
+# include <iphlpapi.h>
+
+# define EWOULDBLOCK WSAEWOULDBLOCK
+# define EINPROGRESS WSAEINPROGRESS
+# define ENOTCONN WSAENOTCONN
+# define EHOSTUNREACH WSAEHOSTUNREACH
+# define ENETUNREACH WSAENETUNREACH
+# define ECONNREFUSED WSAECONNREFUSED
+#else
+# define ioctlsocket ioctl
+# define closesocket(s) close(s)
+#endif
+
#include <sys/types.h>
#ifdef HAVE_SYS_BITYPES_H
# include <sys/bitypes.h>
# include <strings.h>
#endif
+#ifndef _WIN32
#include <sys/uio.h>
+#endif
#ifndef _P
#ifndef NO_PROTOTYPES
#endif
#endif
+#ifndef _WIN32
#include <netinet/in.h>
#include <arpa/inet.h>
+#endif
#ifdef GETTIMEOFDAY_ONE_ARG
#define gettimeofday(x, y) gettimeofday(x)
#ifdef HAVE_SYS_SIGNAL_H
# include <sys/signal.h>
#endif
+#ifndef _WIN32
#include <sys/socket.h>
+#endif
#if defined(HAVE_SYS_IOCTL_H)
# include <sys/ioctl.h>
inline void remque_32 _P((void *));
#endif
-#include <pwd.h>
+#ifndef _WIN32
#include <netdb.h>
+#endif
#define DEFAULT_BAUD 115200
#define MAX_MRU 16384
#endif
+#ifndef _WIN32
+#define min(x,y) ((x) < (y) ? (x) : (y))
+#define max(x,y) ((x) > (y) ? (x) : (y))
+#endif
+
#endif
#define HAVE_STDLIB_H
/* Define if you have sys/ioctl.h */
+#undef HAVE_SYS_IOCTL_H
+#ifndef _WIN32
#define HAVE_SYS_IOCTL_H
+#endif
/* Define if you have sys/filio.h */
#undef HAVE_SYS_FILIO_H
/* Define if iovec needs to be declared */
#undef DECLARE_IOVEC
+#ifdef _WIN32
+#define DECLARE_IOVEC
+#endif
/* Define if a declaration of sprintf/fprintf is needed */
#undef DECLARE_SPRINTF
#undef HAVE_SYS_WAIT_H
/* Define if you have sys/select.h */
+#undef HAVE_SYS_SELECT_H
+#ifndef _WIN32
#define HAVE_SYS_SELECT_H
+#endif
/* Define if you have strings.h */
#define HAVE_STRING_H
/* Define if you have arpa/inet.h */
+#undef HAVE_ARPA_INET_H
+#ifndef _WIN32
#define HAVE_ARPA_INET_H
+#endif
/* Define if you have sys/signal.h */
#undef HAVE_SYS_SIGNAL_H
#undef HAVE_SRANDOM
/* Define if you have inet_aton */
+#undef HAVE_INET_ATON
+#ifndef _WIN32
#define HAVE_INET_ATON
+#endif
/* Define if you have setenv */
#undef HAVE_SETENV
/* Define if you DON'T have unix-domain sockets */
#undef NO_UNIX_SOCKETS
+#ifdef _WIN32
+#define NO_UNIX_SOCKETS
+#endif
/* Define if gettimeofday only takes one argument */
#undef GETTIMEOFDAY_ONE_ARG
*/
len = M_FREEROOM(m);
/* if (so->so_fport != htons(53)) { */
- ioctl(so->s, FIONREAD, &n);
+ ioctlsocket(so->s, FIONREAD, &n);
if (n > len) {
n = (m->m_data - m->m_dat) + m->m_len + n + 1;
struct socket tcb;
-#define min(x,y) ((x) < (y) ? (x) : (y))
-#define max(x,y) ((x) > (y) ? (x) : (y))
-
int tcprexmtthresh = 3;
struct socket *tcp_last_so = &tcb;
#include <slirp.h>
-#define max(x,y) ((x) > (y) ? (x) : (y))
-#define min(x,y) ((x) < (y) ? (x) : (y))
-
/*
* Since this is only used in "stats socket", we give meaning
* names instead of the REAL names
/* clobber input socket cache if we're closing the cached connection */
if (so == tcp_last_so)
tcp_last_so = &tcb;
- close(so->s);
+ closesocket(so->s);
sbfree(&so->so_rcv);
sbfree(&so->so_snd);
sofree(so);
} else {
if ((so = socreate()) == NULL) {
/* If it failed, get rid of the pending connection */
- close(accept(inso->s,(struct sockaddr *)&addr,&addrlen));
+ closesocket(accept(inso->s,(struct sockaddr *)&addr,&addrlen));
return;
}
if (tcp_attach(so) < 0) {
/* Close the accept() socket, set right state */
if (inso->so_state & SS_FACCEPTONCE) {
- close(so->s); /* If we only accept once, close the accept() socket */
+ closesocket(so->s); /* If we only accept once, close the accept() socket */
so->so_state = SS_NOFDREF; /* Don't select it yet, even though we have an FD */
/* if it's not FACCEPTONCE, it's already NOFDREF */
}
#include <slirp.h>
-#define max(x,y) ((x) > (y) ? (x) : (y))
-#define min(x,y) ((x) < (y) ? (x) : (y))
-
int tcp_keepidle = TCPTV_KEEP_IDLE;
int tcp_keepintvl = TCPTV_KEEPINTVL;
int tcp_maxidle;
addr.sin_addr.s_addr = INADDR_ANY;
if(bind(so->s, (struct sockaddr *)&addr, sizeof(addr))<0) {
int lasterrno=errno;
- close(so->s);
+ closesocket(so->s);
so->s=-1;
errno=lasterrno;
} else {
udp_detach(so)
struct socket *so;
{
- close(so->s);
+ closesocket(so->s);
/* if (so->so_m) m_free(so->so_m); done by sofree */
sofree(so);
addr.sin_port = htons(518);
sendto(s, (char *)nmsg, sizeof(*nmsg), 0,
(struct sockaddr *) &addr, sizeof(addr));
- close(s) ;
+ closesocket(s) ;
omsg->type = nmsg->type = ANNOUNCE;
OTOSIN(omsg, ctl_addr)->sin_port = temp_port;
addr.sin_port = htons(518);
sendto(s, (char *)nmsg, sizeof(*nmsg), 0,
(struct sockaddr *)&addr, sizeof(addr));
- close(s);
+ closesocket(s);
OTOSIN(omsg, ctl_addr)->sin_port = temp_port;
OTOSIN(nmsg, ctl_addr)->sin_port = temp_port;