From 4db8137c1a2c53cb8b2a3f4976f33bc085b77189 Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Sun, 25 Jan 2009 20:39:44 +0000 Subject: [PATCH] #43: Basic windows support operational --- README-win32.txt | 22 ++++++++++++++++++---- src/common.c | 6 +++++- src/tun.c | 20 ++++++++++++-------- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/README-win32.txt b/README-win32.txt index c9afe47..9716180 100644 --- a/README-win32.txt +++ b/README-win32.txt @@ -7,6 +7,20 @@ iodine - http://code.kryo.se/iodine Extra README file for Win32 related stuff +== Running iodine on Windows: +1. Install the TAP32 driver + http://openvpn.net/index.php/downloads.html + choose OpenVPN 2.0.9 Windows Installer, when installing you can + select to install only the TAP driver. + +2. Have one TAP32 interface installed + +3. Name the interface "dns" + +4. Run iodine/iodined as normal. + +5. Enjoy! + == Building on Windows: You need: @@ -22,16 +36,15 @@ You need: Then run "make cross-mingw" Note that the binaries will not get a .exe suffix + +== Zlib download You can get zlib for MinGW here (both for native and crosscompile): http://code.kryo.se/iodine/deps/zlib.zip Unzip it in your MinGW directory on Windows or in $ROOT/usr for cross-compile. -== Running iodine on Windows: -Get the TAP32 driver here (choose OpenVPN 2.0.9 Windows Installer, -you can choose to get only the driver): -http://openvpn.net/index.php/downloads.html +== Results of crappy Win32 API: The following fixable limitations apply: - The password is shown when entered - DNS server IP can not be fetched automatically @@ -44,3 +57,4 @@ The following (probably) un-fixable limitations apply: - Priviligies cannot be dropped - chroot() cannot be used - Detaching from terminal not possible + diff --git a/src/common.c b/src/common.c index fc12e80..ac56486 100644 --- a/src/common.c +++ b/src/common.c @@ -230,7 +230,11 @@ warn(const char *fmt, ...) va_start(list, fmt); if (fmt) fprintf(stderr, fmt, list); - fprintf(stderr, "%s\n", strerror(errno)); + if (errno == 0) { + fprintf(stderr, ": WSA error %d\n", WSAGetLastError()); + } else { + fprintf(stderr, ": %s\n", strerror(errno)); + } va_end(list); } diff --git a/src/tun.c b/src/tun.c index 0328f11..86f8a89 100644 --- a/src/tun.c +++ b/src/tun.c @@ -424,27 +424,31 @@ tun_setip(const char *ip, int netbits) r = DeviceIoControl(dev_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status, sizeof(status), &status, sizeof(status), &len, NULL); if (!r) { + printf("Failed to enable interface\n"); return -1; } - ipdata[2] = (DWORD) net.s_addr; - if (inet_aton(ip, &addr)) { - ipdata[0] = (DWORD) addr.s_addr; - ipdata[1] = ipdata[2] & ipdata[0]; /* Get network bits */ + ipdata[0] = (DWORD) addr.s_addr; /* local ip addr */ + ipdata[1] = net.s_addr & ipdata[0]; /* network addr */ + ipdata[2] = (DWORD) net.s_addr; /* netmask */ } else { return -1; } - /* Tell ip/network addr/netmask to device for arp use */ + + /* Tell ip/networkaddr/netmask to device for arp use */ r = DeviceIoControl(dev_handle, TAP_IOCTL_CONFIG_TUN, &ipdata, sizeof(ipdata), &ipdata, sizeof(ipdata), &len, NULL); if (!r) { + printf("Failed to set interface in TUN mode\n"); return -1; } - /* TODO use netsh to set ip address */ - cmdline[0] = 0; - return 0; + /* use netsh to set ip address */ + printf("Setting IP of interface '%s' to %s (can take a few seconds)...\n", if_name, ip); + snprintf(cmdline, sizeof(cmdline), "netsh interface ip set address \"%s\" static %s %s", + if_name, ip, inet_ntoa(net)); + return system(cmdline); #endif }