win32 compile
authorbellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162>
Mon, 12 Jul 2004 22:33:07 +0000 (22:33 +0000)
committerbellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162>
Mon, 12 Jul 2004 22:33:07 +0000 (22:33 +0000)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1016 c046a42c-6fe2-441c-8c8c-71466251a162

13 files changed:
slirp/libslirp.h
slirp/main.h
slirp/misc.c
slirp/sbuf.c
slirp/slirp.c
slirp/slirp.h
slirp/slirp_config.h
slirp/socket.c
slirp/tcp_input.c
slirp/tcp_output.c
slirp/tcp_subr.c
slirp/tcp_timer.c
slirp/udp.c

index 31ddaea..47824b2 100644 (file)
@@ -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);
 
index dc06d6f..2d6f43b 100644 (file)
@@ -10,7 +10,6 @@
 #endif
 
 #define TOWRITEMAX 512
-#define min(x,y) ((x) < (y) ? (x) : (y))
 
 extern struct timeval tt;
 extern int link_up;
index 7f6448d..64bd9ee 100644 (file)
@@ -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;
        
index 04fb97d..d6726c9 100644 (file)
@@ -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) {
                /* 
index ad10516..405647b 100644 (file)
@@ -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)
index eecef59..f5c93c5 100644 (file)
 #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
index 5b014f2..856c315 100644 (file)
 #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
 #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
index 396fb4a..7286b5e 100644 (file)
@@ -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;
index eeee985..4f74d0c 100644 (file)
@@ -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;
 
index 0f05dfa..b79bcf1 100644 (file)
@@ -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
index 07cfc0e..c29dc60 100644 (file)
@@ -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 */
        }
index 166979a..d3146db 100644 (file)
@@ -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;
index 76a4fcc..67a0509 100644 (file)
@@ -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;