diff options
author | bellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162> | 2004-07-12 22:33:07 +0000 |
---|---|---|
committer | bellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162> | 2004-07-12 22:33:07 +0000 |
commit | 379ff53dc964ee1dc9442dac230c87a595e06a12 (patch) | |
tree | e95b6fe5abe71414f507d85ebcfea63b3d2468b3 /slirp/slirp.c | |
parent | ce93da6ffee7f27044c5b49b096ebdec27075110 (diff) |
win32 compile
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1016 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'slirp/slirp.c')
-rw-r--r-- | slirp/slirp.c | 72 |
1 files changed, 70 insertions, 2 deletions
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) |