aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162>2004-07-12 22:33:07 +0000
committerbellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162>2004-07-12 22:33:07 +0000
commit57c3d6480861f11f1558708967fc58e3a80da2b4 (patch)
tree0814d528e6c2f2dae157a17ec825d52db6a4f992
parent25267a3cd019af1e37e200977d28f357c4a4ea14 (diff)
downloadslirp-57c3d6480861f11f1558708967fc58e3a80da2b4.zip
slirp-57c3d6480861f11f1558708967fc58e3a80da2b4.tar.gz
slirp-57c3d6480861f11f1558708967fc58e3a80da2b4.tar.bz2
win32 compile
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1016 c046a42c-6fe2-441c-8c8c-71466251a162
-rw-r--r--libslirp.h4
-rw-r--r--main.h1
-rw-r--r--misc.c8
-rw-r--r--sbuf.c2
-rw-r--r--slirp.c72
-rw-r--r--slirp.h38
-rw-r--r--slirp_config.h18
-rw-r--r--socket.c2
-rw-r--r--tcp_input.c3
-rw-r--r--tcp_output.c3
-rw-r--r--tcp_subr.c7
-rw-r--r--tcp_timer.c3
-rw-r--r--udp.c8
13 files changed, 143 insertions, 26 deletions
diff --git a/libslirp.h b/libslirp.h
index 5eb617e..36a1cc7 100644
--- a/libslirp.h
+++ b/libslirp.h
@@ -1,7 +1,11 @@
#ifndef _LIBSLIRP_H
#define _LIBSLIRP_H
+#ifdef _WIN32
+#include <winsock2.h>
+#else
#include <sys/select.h>
+#endif
void slirp_init(void);
diff --git a/main.h b/main.h
index 66e53e7..354ec24 100644
--- a/main.h
+++ b/main.h
@@ -10,7 +10,6 @@
#endif
#define TOWRITEMAX 512
-#define min(x, y) ((x) < (y) ? (x) : (y))
extern struct timeval tt;
extern int link_up;
diff --git a/misc.c b/misc.c
index 382059f..047120d 100644
--- a/misc.c
+++ b/misc.c
@@ -310,7 +310,7 @@ fork_exec(so, ex, do_pty)
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;
}
@@ -405,7 +405,7 @@ fork_exec(so, ex, do_pty)
* 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;
@@ -779,7 +779,7 @@ void fd_nonblock(fd) int fd;
#ifdef FIONBIO
int opt = 1;
- ioctl(fd, FIONBIO, &opt);
+ ioctlsocket(fd, FIONBIO, &opt);
#else
int opt;
@@ -794,7 +794,7 @@ void fd_block(fd) int fd;
#ifdef FIONBIO
int opt = 0;
- ioctl(fd, FIONBIO, &opt);
+ ioctlsocket(fd, FIONBIO, &opt);
#else
int opt;
diff --git a/sbuf.c b/sbuf.c
index 22c865f..21ac4bc 100644
--- a/sbuf.c
+++ b/sbuf.c
@@ -98,7 +98,7 @@ struct mbuf *m;
* 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) {
/*
diff --git a/slirp.c b/slirp.c
index ccec2e9..8bc82c0 100644
--- a/slirp.c
+++ b/slirp.c
@@ -26,8 +26,50 @@ fd_set *global_readfds, *global_writefds, *global_xfds;
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
@@ -71,10 +113,25 @@ static int get_dns_addr(struct in_addr *pdns_addr)
#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();
@@ -106,6 +163,16 @@ void slirp_init(void)
/*
* 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);
@@ -116,6 +183,7 @@ static void updtime(void)
if ((tt.tv_usec % 1000) >= 500)
curtime++;
}
+#endif
void slirp_select_fill(int *pnfds, fd_set *readfds, fd_set *writefds,
fd_set *xfds)
diff --git a/slirp.h b/slirp.h
index 9592178..f3ff59a 100644
--- a/slirp.h
+++ b/slirp.h
@@ -11,6 +11,30 @@
#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>
@@ -79,7 +103,9 @@ typedef unsigned int u_int32_t;
#include <strings.h>
#endif
+#ifndef _WIN32
#include <sys/uio.h>
+#endif
#ifndef _P
#ifndef NO_PROTOTYPES
@@ -89,8 +115,10 @@ typedef unsigned int u_int32_t;
#endif
#endif
+#ifndef _WIN32
#include <netinet/in.h>
#include <arpa/inet.h>
+#endif
#ifdef GETTIMEOFDAY_ONE_ARG
#define gettimeofday(x, y) gettimeofday(x)
@@ -119,7 +147,9 @@ int inet_aton _P((const char *cp, struct in_addr *ia));
#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>
@@ -232,8 +262,9 @@ inline void insque_32 _P((void *, void *));
inline void remque_32 _P((void *));
#endif
-#include <pwd.h>
+#ifndef _WIN32
#include <netdb.h>
+#endif
#define DEFAULT_BAUD 115200
@@ -294,4 +325,9 @@ struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
#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
diff --git a/slirp_config.h b/slirp_config.h
index 9e267a2..6ee9b6d 100644
--- a/slirp_config.h
+++ b/slirp_config.h
@@ -62,7 +62,10 @@
#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
@@ -94,6 +97,9 @@
/* 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
@@ -102,13 +108,19 @@
#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
@@ -148,7 +160,10 @@
#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
@@ -170,6 +185,9 @@
/* 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
diff --git a/socket.c b/socket.c
index ec6e047..32a4873 100644
--- a/socket.c
+++ b/socket.c
@@ -415,7 +415,7 @@ void sorecvfrom(so) struct socket *so;
*/
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;
diff --git a/tcp_input.c b/tcp_input.c
index c21f97b..c95ca61 100644
--- a/tcp_input.c
+++ b/tcp_input.c
@@ -47,9 +47,6 @@
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;
diff --git a/tcp_output.c b/tcp_output.c
index e4627a7..de048e6 100644
--- a/tcp_output.c
+++ b/tcp_output.c
@@ -44,9 +44,6 @@
#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
diff --git a/tcp_subr.c b/tcp_subr.c
index 06940a4..c12c6bd 100644
--- a/tcp_subr.c
+++ b/tcp_subr.c
@@ -298,7 +298,7 @@ struct tcpcb *tcp_close(tp) register struct tcpcb *tp;
/* 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);
@@ -466,7 +466,7 @@ void tcp_connect(inso) struct socket *inso;
} 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) {
@@ -497,7 +497,8 @@ void tcp_connect(inso) struct socket *inso;
/* 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 */
diff --git a/tcp_timer.c b/tcp_timer.c
index e23a1d0..9b984f6 100644
--- a/tcp_timer.c
+++ b/tcp_timer.c
@@ -36,9 +36,6 @@
#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;
diff --git a/udp.c b/udp.c
index 4d9061f..f4b1fa5 100644
--- a/udp.c
+++ b/udp.c
@@ -326,7 +326,7 @@ int udp_attach(so) struct socket *so;
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 {
@@ -340,7 +340,7 @@ int udp_attach(so) struct socket *so;
void 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);
@@ -516,7 +516,7 @@ struct mbuf *m;
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;
@@ -547,7 +547,7 @@ struct mbuf *m;
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;