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
commit379ff53dc964ee1dc9442dac230c87a595e06a12 (patch)
treee95b6fe5abe71414f507d85ebcfea63b3d2468b3
parentce93da6ffee7f27044c5b49b096ebdec27075110 (diff)
win32 compile
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1016 c046a42c-6fe2-441c-8c8c-71466251a162
-rw-r--r--slirp/libslirp.h4
-rw-r--r--slirp/main.h1
-rw-r--r--slirp/misc.c8
-rw-r--r--slirp/sbuf.c2
-rw-r--r--slirp/slirp.c72
-rw-r--r--slirp/slirp.h38
-rw-r--r--slirp/slirp_config.h18
-rw-r--r--slirp/socket.c2
-rw-r--r--slirp/tcp_input.c3
-rw-r--r--slirp/tcp_output.c3
-rw-r--r--slirp/tcp_subr.c6
-rw-r--r--slirp/tcp_timer.c3
-rw-r--r--slirp/udp.c8
13 files changed, 142 insertions, 26 deletions
diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index 31ddaea4d5..47824b2413 100644
--- a/slirp/libslirp.h
+++ b/slirp/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/slirp/main.h b/slirp/main.h
index dc06d6fe7e..2d6f43bcc0 100644
--- a/slirp/main.h
+++ b/slirp/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/slirp/misc.c b/slirp/misc.c
index 7f6448dffd..64bd9ee2f5 100644
--- a/slirp/misc.c
+++ b/slirp/misc.c
@@ -326,7 +326,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;
}
@@ -421,7 +421,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;
@@ -804,7 +804,7 @@ fd_nonblock(fd)
#ifdef FIONBIO
int opt = 1;
- ioctl(fd, FIONBIO, &opt);
+ ioctlsocket(fd, FIONBIO, &opt);
#else
int opt;
@@ -821,7 +821,7 @@ fd_block(fd)
#ifdef FIONBIO
int opt = 0;
- ioctl(fd, FIONBIO, &opt);
+ ioctlsocket(fd, FIONBIO, &opt);
#else
int opt;
diff --git a/slirp/sbuf.c b/slirp/sbuf.c
index 04fb97ddc8..d6726c94de 100644
--- a/slirp/sbuf.c
+++ b/slirp/sbuf.c
@@ -106,7 +106,7 @@ sbappend(so, 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/slirp.c b/slirp/slirp.c
index ad10516a06..405647b48c 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -28,8 +28,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
@@ -73,10 +115,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();
@@ -104,6 +161,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);
@@ -114,6 +181,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/slirp.h b/slirp/slirp.h
index eecef59165..f5c93c5ee5 100644
--- a/slirp/slirp.h
+++ b/slirp/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 char u_int8_t;
# include <strings.h>
#endif
+#ifndef _WIN32
#include <sys/uio.h>
+#endif
#ifndef _P
#ifndef NO_PROTOTYPES
@@ -89,8 +115,10 @@ typedef unsigned char u_int8_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 @@ extern int do_echo;
inline void remque_32 _P((void *));
#endif
-#include <pwd.h>
+#ifndef _WIN32
#include <netdb.h>
+#endif
#define DEFAULT_BAUD 115200
@@ -292,4 +323,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/slirp_config.h b/slirp/slirp_config.h
index 5b014f2750..856c315675 100644
--- a/slirp/slirp_config.h
+++ b/slirp/slirp_config.h
@@ -61,7 +61,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
@@ -93,6 +96,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
@@ -101,13 +107,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
@@ -147,7 +159,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
@@ -169,6 +184,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/slirp/socket.c b/slirp/socket.c
index 396fb4ac78..7286b5e19f 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -418,7 +418,7 @@ sorecvfrom(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/slirp/tcp_input.c b/slirp/tcp_input.c
index eeee985972..4f74d0cdbc 100644
--- a/slirp/tcp_input.c
+++ b/slirp/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/slirp/tcp_output.c b/slirp/tcp_output.c
index 0f05dfadcc..b79bcf1279 100644
--- a/slirp/tcp_output.c
+++ b/slirp/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/slirp/tcp_subr.c b/slirp/tcp_subr.c
index 07cfc0e4fe..c29dc604ff 100644
--- a/slirp/tcp_subr.c
+++ b/slirp/tcp_subr.c
@@ -301,7 +301,7 @@ tcp_close(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);
@@ -477,7 +477,7 @@ tcp_connect(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) {
@@ -508,7 +508,7 @@ tcp_connect(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/slirp/tcp_timer.c b/slirp/tcp_timer.c
index 166979a3e2..d3146db587 100644
--- a/slirp/tcp_timer.c
+++ b/slirp/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/slirp/udp.c b/slirp/udp.c
index 76a4fcc97a..67a05090fc 100644
--- a/slirp/udp.c
+++ b/slirp/udp.c
@@ -329,7 +329,7 @@ udp_attach(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 {
@@ -345,7 +345,7 @@ 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);
@@ -527,7 +527,7 @@ struct cu_header {
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;
@@ -558,7 +558,7 @@ struct cu_header {
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;