Commit 379ff53dc964ee1dc9442dac230c87a595e06a12
1 parent
ce93da6f
win32 compile
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1016 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
13 changed files
with
142 additions
and
26 deletions
slirp/libslirp.h
slirp/main.h
slirp/misc.c
... | ... | @@ -326,7 +326,7 @@ fork_exec(so, ex, do_pty) |
326 | 326 | bind(s, (struct sockaddr *)&addr, addrlen) < 0 || |
327 | 327 | listen(s, 1) < 0) { |
328 | 328 | lprint("Error: inet socket: %s\n", strerror(errno)); |
329 | - close(s); | |
329 | + closesocket(s); | |
330 | 330 | |
331 | 331 | return 0; |
332 | 332 | } |
... | ... | @@ -421,7 +421,7 @@ fork_exec(so, ex, do_pty) |
421 | 421 | * of connect() fail in the child process |
422 | 422 | */ |
423 | 423 | so->s = accept(s, (struct sockaddr *)&addr, &addrlen); |
424 | - close(s); | |
424 | + closesocket(s); | |
425 | 425 | opt = 1; |
426 | 426 | setsockopt(so->s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int)); |
427 | 427 | opt = 1; |
... | ... | @@ -804,7 +804,7 @@ fd_nonblock(fd) |
804 | 804 | #ifdef FIONBIO |
805 | 805 | int opt = 1; |
806 | 806 | |
807 | - ioctl(fd, FIONBIO, &opt); | |
807 | + ioctlsocket(fd, FIONBIO, &opt); | |
808 | 808 | #else |
809 | 809 | int opt; |
810 | 810 | |
... | ... | @@ -821,7 +821,7 @@ fd_block(fd) |
821 | 821 | #ifdef FIONBIO |
822 | 822 | int opt = 0; |
823 | 823 | |
824 | - ioctl(fd, FIONBIO, &opt); | |
824 | + ioctlsocket(fd, FIONBIO, &opt); | |
825 | 825 | #else |
826 | 826 | int opt; |
827 | 827 | ... | ... |
slirp/sbuf.c
slirp/slirp.c
... | ... | @@ -28,8 +28,50 @@ fd_set *global_readfds, *global_writefds, *global_xfds; |
28 | 28 | |
29 | 29 | static int get_dns_addr(struct in_addr *pdns_addr) |
30 | 30 | { |
31 | - /* XXX: add it */ | |
32 | - return -1; | |
31 | + FIXED_INFO *FixedInfo=NULL; | |
32 | + ULONG BufLen; | |
33 | + DWORD ret; | |
34 | + IP_ADDR_STRING *pIPAddr; | |
35 | + struct in_addr tmp_addr; | |
36 | + | |
37 | + FixedInfo = (FIXED_INFO *)GlobalAlloc(GPTR, sizeof(FIXED_INFO)); | |
38 | + BufLen = sizeof(FIXED_INFO); | |
39 | + | |
40 | + if (ERROR_BUFFER_OVERFLOW == GetNetworkParams(FixedInfo, &BufLen)) { | |
41 | + if (FixedInfo) { | |
42 | + GlobalFree(FixedInfo); | |
43 | + FixedInfo = NULL; | |
44 | + } | |
45 | + FixedInfo = GlobalAlloc(GPTR, BufLen); | |
46 | + } | |
47 | + | |
48 | + if ((ret = GetNetworkParams(FixedInfo, &BufLen)) != ERROR_SUCCESS) { | |
49 | + printf("GetNetworkParams failed. ret = %08x\n", (u_int)ret ); | |
50 | + if (FixedInfo) { | |
51 | + GlobalFree(FixedInfo); | |
52 | + FixedInfo = NULL; | |
53 | + } | |
54 | + return -1; | |
55 | + } | |
56 | + | |
57 | + pIPAddr = &(FixedInfo->DnsServerList); | |
58 | + inet_aton(pIPAddr->IpAddress.String, &tmp_addr); | |
59 | + *pdns_addr = tmp_addr; | |
60 | +#if 0 | |
61 | + printf( "DNS Servers:\n" ); | |
62 | + printf( "DNS Addr:%s\n", pIPAddr->IpAddress.String ); | |
63 | + | |
64 | + pIPAddr = FixedInfo -> DnsServerList.Next; | |
65 | + while ( pIPAddr ) { | |
66 | + printf( "DNS Addr:%s\n", pIPAddr ->IpAddress.String ); | |
67 | + pIPAddr = pIPAddr ->Next; | |
68 | + } | |
69 | +#endif | |
70 | + if (FixedInfo) { | |
71 | + GlobalFree(FixedInfo); | |
72 | + FixedInfo = NULL; | |
73 | + } | |
74 | + return 0; | |
33 | 75 | } |
34 | 76 | |
35 | 77 | #else |
... | ... | @@ -73,10 +115,25 @@ static int get_dns_addr(struct in_addr *pdns_addr) |
73 | 115 | |
74 | 116 | #endif |
75 | 117 | |
118 | +#ifdef _WIN32 | |
119 | +void slirp_cleanup(void) | |
120 | +{ | |
121 | + WSACleanup(); | |
122 | +} | |
123 | +#endif | |
124 | + | |
76 | 125 | void slirp_init(void) |
77 | 126 | { |
78 | 127 | // debug_init("/tmp/slirp.log", DEBUG_DEFAULT); |
79 | 128 | |
129 | +#ifdef _WIN32 | |
130 | + { | |
131 | + WSADATA Data; | |
132 | + WSAStartup(MAKEWORD(2,0), &Data); | |
133 | + atexit(slirp_cleanup); | |
134 | + } | |
135 | +#endif | |
136 | + | |
80 | 137 | link_up = 1; |
81 | 138 | |
82 | 139 | if_init(); |
... | ... | @@ -104,6 +161,16 @@ void slirp_init(void) |
104 | 161 | /* |
105 | 162 | * curtime kept to an accuracy of 1ms |
106 | 163 | */ |
164 | +#ifdef _WIN32 | |
165 | +static void updtime(void) | |
166 | +{ | |
167 | + struct _timeb tb; | |
168 | + | |
169 | + _ftime(&tb); | |
170 | + curtime = (u_int)tb.time * (u_int)1000; | |
171 | + curtime += (u_int)tb.millitm; | |
172 | +} | |
173 | +#else | |
107 | 174 | static void updtime(void) |
108 | 175 | { |
109 | 176 | gettimeofday(&tt, 0); |
... | ... | @@ -114,6 +181,7 @@ static void updtime(void) |
114 | 181 | if ((tt.tv_usec % 1000) >= 500) |
115 | 182 | curtime++; |
116 | 183 | } |
184 | +#endif | |
117 | 185 | |
118 | 186 | void slirp_select_fill(int *pnfds, |
119 | 187 | fd_set *readfds, fd_set *writefds, fd_set *xfds) | ... | ... |
slirp/slirp.h
... | ... | @@ -11,6 +11,30 @@ |
11 | 11 | #include "config.h" |
12 | 12 | #include "slirp_config.h" |
13 | 13 | |
14 | +#ifdef _WIN32 | |
15 | +# include <inttypes.h> | |
16 | + | |
17 | +typedef uint8_t u_int8_t; | |
18 | +typedef uint16_t u_int16_t; | |
19 | +typedef uint32_t u_int32_t; | |
20 | +typedef uint64_t u_int64_t; | |
21 | +typedef char *caddr_t; | |
22 | + | |
23 | +# include <winsock2.h> | |
24 | +# include <sys/timeb.h> | |
25 | +# include <iphlpapi.h> | |
26 | + | |
27 | +# define EWOULDBLOCK WSAEWOULDBLOCK | |
28 | +# define EINPROGRESS WSAEINPROGRESS | |
29 | +# define ENOTCONN WSAENOTCONN | |
30 | +# define EHOSTUNREACH WSAEHOSTUNREACH | |
31 | +# define ENETUNREACH WSAENETUNREACH | |
32 | +# define ECONNREFUSED WSAECONNREFUSED | |
33 | +#else | |
34 | +# define ioctlsocket ioctl | |
35 | +# define closesocket(s) close(s) | |
36 | +#endif | |
37 | + | |
14 | 38 | #include <sys/types.h> |
15 | 39 | #ifdef HAVE_SYS_BITYPES_H |
16 | 40 | # include <sys/bitypes.h> |
... | ... | @@ -79,7 +103,9 @@ typedef unsigned char u_int8_t; |
79 | 103 | # include <strings.h> |
80 | 104 | #endif |
81 | 105 | |
106 | +#ifndef _WIN32 | |
82 | 107 | #include <sys/uio.h> |
108 | +#endif | |
83 | 109 | |
84 | 110 | #ifndef _P |
85 | 111 | #ifndef NO_PROTOTYPES |
... | ... | @@ -89,8 +115,10 @@ typedef unsigned char u_int8_t; |
89 | 115 | #endif |
90 | 116 | #endif |
91 | 117 | |
118 | +#ifndef _WIN32 | |
92 | 119 | #include <netinet/in.h> |
93 | 120 | #include <arpa/inet.h> |
121 | +#endif | |
94 | 122 | |
95 | 123 | #ifdef GETTIMEOFDAY_ONE_ARG |
96 | 124 | #define gettimeofday(x, y) gettimeofday(x) |
... | ... | @@ -119,7 +147,9 @@ int inet_aton _P((const char *cp, struct in_addr *ia)); |
119 | 147 | #ifdef HAVE_SYS_SIGNAL_H |
120 | 148 | # include <sys/signal.h> |
121 | 149 | #endif |
150 | +#ifndef _WIN32 | |
122 | 151 | #include <sys/socket.h> |
152 | +#endif | |
123 | 153 | |
124 | 154 | #if defined(HAVE_SYS_IOCTL_H) |
125 | 155 | # include <sys/ioctl.h> |
... | ... | @@ -232,8 +262,9 @@ extern int do_echo; |
232 | 262 | inline void remque_32 _P((void *)); |
233 | 263 | #endif |
234 | 264 | |
235 | -#include <pwd.h> | |
265 | +#ifndef _WIN32 | |
236 | 266 | #include <netdb.h> |
267 | +#endif | |
237 | 268 | |
238 | 269 | #define DEFAULT_BAUD 115200 |
239 | 270 | |
... | ... | @@ -292,4 +323,9 @@ struct tcpcb *tcp_drop(struct tcpcb *tp, int err); |
292 | 323 | #define MAX_MRU 16384 |
293 | 324 | #endif |
294 | 325 | |
326 | +#ifndef _WIN32 | |
327 | +#define min(x,y) ((x) < (y) ? (x) : (y)) | |
328 | +#define max(x,y) ((x) > (y) ? (x) : (y)) | |
329 | +#endif | |
330 | + | |
295 | 331 | #endif | ... | ... |
slirp/slirp_config.h
... | ... | @@ -61,7 +61,10 @@ |
61 | 61 | #define HAVE_STDLIB_H |
62 | 62 | |
63 | 63 | /* Define if you have sys/ioctl.h */ |
64 | +#undef HAVE_SYS_IOCTL_H | |
65 | +#ifndef _WIN32 | |
64 | 66 | #define HAVE_SYS_IOCTL_H |
67 | +#endif | |
65 | 68 | |
66 | 69 | /* Define if you have sys/filio.h */ |
67 | 70 | #undef HAVE_SYS_FILIO_H |
... | ... | @@ -93,6 +96,9 @@ |
93 | 96 | |
94 | 97 | /* Define if iovec needs to be declared */ |
95 | 98 | #undef DECLARE_IOVEC |
99 | +#ifdef _WIN32 | |
100 | +#define DECLARE_IOVEC | |
101 | +#endif | |
96 | 102 | |
97 | 103 | /* Define if a declaration of sprintf/fprintf is needed */ |
98 | 104 | #undef DECLARE_SPRINTF |
... | ... | @@ -101,13 +107,19 @@ |
101 | 107 | #undef HAVE_SYS_WAIT_H |
102 | 108 | |
103 | 109 | /* Define if you have sys/select.h */ |
110 | +#undef HAVE_SYS_SELECT_H | |
111 | +#ifndef _WIN32 | |
104 | 112 | #define HAVE_SYS_SELECT_H |
113 | +#endif | |
105 | 114 | |
106 | 115 | /* Define if you have strings.h */ |
107 | 116 | #define HAVE_STRING_H |
108 | 117 | |
109 | 118 | /* Define if you have arpa/inet.h */ |
119 | +#undef HAVE_ARPA_INET_H | |
120 | +#ifndef _WIN32 | |
110 | 121 | #define HAVE_ARPA_INET_H |
122 | +#endif | |
111 | 123 | |
112 | 124 | /* Define if you have sys/signal.h */ |
113 | 125 | #undef HAVE_SYS_SIGNAL_H |
... | ... | @@ -147,7 +159,10 @@ |
147 | 159 | #undef HAVE_SRANDOM |
148 | 160 | |
149 | 161 | /* Define if you have inet_aton */ |
162 | +#undef HAVE_INET_ATON | |
163 | +#ifndef _WIN32 | |
150 | 164 | #define HAVE_INET_ATON |
165 | +#endif | |
151 | 166 | |
152 | 167 | /* Define if you have setenv */ |
153 | 168 | #undef HAVE_SETENV |
... | ... | @@ -169,6 +184,9 @@ |
169 | 184 | |
170 | 185 | /* Define if you DON'T have unix-domain sockets */ |
171 | 186 | #undef NO_UNIX_SOCKETS |
187 | +#ifdef _WIN32 | |
188 | +#define NO_UNIX_SOCKETS | |
189 | +#endif | |
172 | 190 | |
173 | 191 | /* Define if gettimeofday only takes one argument */ |
174 | 192 | #undef GETTIMEOFDAY_ONE_ARG | ... | ... |
slirp/socket.c
slirp/tcp_input.c
slirp/tcp_output.c
slirp/tcp_subr.c
... | ... | @@ -301,7 +301,7 @@ tcp_close(tp) |
301 | 301 | /* clobber input socket cache if we're closing the cached connection */ |
302 | 302 | if (so == tcp_last_so) |
303 | 303 | tcp_last_so = &tcb; |
304 | - close(so->s); | |
304 | + closesocket(so->s); | |
305 | 305 | sbfree(&so->so_rcv); |
306 | 306 | sbfree(&so->so_snd); |
307 | 307 | sofree(so); |
... | ... | @@ -477,7 +477,7 @@ tcp_connect(inso) |
477 | 477 | } else { |
478 | 478 | if ((so = socreate()) == NULL) { |
479 | 479 | /* If it failed, get rid of the pending connection */ |
480 | - close(accept(inso->s,(struct sockaddr *)&addr,&addrlen)); | |
480 | + closesocket(accept(inso->s,(struct sockaddr *)&addr,&addrlen)); | |
481 | 481 | return; |
482 | 482 | } |
483 | 483 | if (tcp_attach(so) < 0) { |
... | ... | @@ -508,7 +508,7 @@ tcp_connect(inso) |
508 | 508 | |
509 | 509 | /* Close the accept() socket, set right state */ |
510 | 510 | if (inso->so_state & SS_FACCEPTONCE) { |
511 | - close(so->s); /* If we only accept once, close the accept() socket */ | |
511 | + closesocket(so->s); /* If we only accept once, close the accept() socket */ | |
512 | 512 | so->so_state = SS_NOFDREF; /* Don't select it yet, even though we have an FD */ |
513 | 513 | /* if it's not FACCEPTONCE, it's already NOFDREF */ |
514 | 514 | } | ... | ... |
slirp/tcp_timer.c
slirp/udp.c
... | ... | @@ -329,7 +329,7 @@ udp_attach(so) |
329 | 329 | addr.sin_addr.s_addr = INADDR_ANY; |
330 | 330 | if(bind(so->s, (struct sockaddr *)&addr, sizeof(addr))<0) { |
331 | 331 | int lasterrno=errno; |
332 | - close(so->s); | |
332 | + closesocket(so->s); | |
333 | 333 | so->s=-1; |
334 | 334 | errno=lasterrno; |
335 | 335 | } else { |
... | ... | @@ -345,7 +345,7 @@ void |
345 | 345 | udp_detach(so) |
346 | 346 | struct socket *so; |
347 | 347 | { |
348 | - close(so->s); | |
348 | + closesocket(so->s); | |
349 | 349 | /* if (so->so_m) m_free(so->so_m); done by sofree */ |
350 | 350 | |
351 | 351 | sofree(so); |
... | ... | @@ -527,7 +527,7 @@ struct cu_header { |
527 | 527 | addr.sin_port = htons(518); |
528 | 528 | sendto(s, (char *)nmsg, sizeof(*nmsg), 0, |
529 | 529 | (struct sockaddr *) &addr, sizeof(addr)); |
530 | - close(s) ; | |
530 | + closesocket(s) ; | |
531 | 531 | |
532 | 532 | omsg->type = nmsg->type = ANNOUNCE; |
533 | 533 | OTOSIN(omsg, ctl_addr)->sin_port = temp_port; |
... | ... | @@ -558,7 +558,7 @@ struct cu_header { |
558 | 558 | addr.sin_port = htons(518); |
559 | 559 | sendto(s, (char *)nmsg, sizeof(*nmsg), 0, |
560 | 560 | (struct sockaddr *)&addr, sizeof(addr)); |
561 | - close(s); | |
561 | + closesocket(s); | |
562 | 562 | |
563 | 563 | OTOSIN(omsg, ctl_addr)->sin_port = temp_port; |
564 | 564 | OTOSIN(nmsg, ctl_addr)->sin_port = temp_port; | ... | ... |