aboutsummaryrefslogtreecommitdiff
path: root/slirp.c
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 /slirp.c
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
Diffstat (limited to 'slirp.c')
-rw-r--r--slirp.c72
1 files changed, 70 insertions, 2 deletions
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)