[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r25209 - gnunet/src/vpn
From: |
gnunet |
Subject: |
[GNUnet-SVN] r25209 - gnunet/src/vpn |
Date: |
Mon, 3 Dec 2012 23:58:20 +0100 |
Author: cfuchs
Date: 2012-12-03 23:58:19 +0100 (Mon, 03 Dec 2012)
New Revision: 25209
Modified:
gnunet/src/vpn/gnunet-helper-vpn-windows.c
Log:
Added logics to install virtual networks interfaces for gnunet-vpn in
win32 based on the info that can be found in the MSDN.
Current revision:
http://msdn.microsoft.com/en-us/library/windows/hardware/ff549791%28v=vs.85%29.aspx
Modified: gnunet/src/vpn/gnunet-helper-vpn-windows.c
===================================================================
--- gnunet/src/vpn/gnunet-helper-vpn-windows.c 2012-12-03 20:03:37 UTC (rev
25208)
+++ gnunet/src/vpn/gnunet-helper-vpn-windows.c 2012-12-03 22:58:19 UTC (rev
25209)
@@ -16,7 +16,7 @@
along with GNUnet; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
-*/
+ */
/**
* @file vpn/gnunet-helper-vpn-windows.c
@@ -31,8 +31,18 @@
*
*/
+#include <stdio.h>
+#include <windows.h>
+#include <setupapi.h>
#include "platform.h"
+//#include <tchar.h>
+//#include <stdlib.h>
+//#include <regstr.h>
+//#include <string.h>
+//#include <malloc.h>
+//#include <objbase.h>
+
/**
* Need 'struct GNUNET_MessageHeader'.
*/
@@ -54,6 +64,20 @@
*/
#define MAX_SIZE 65536
+/**
+ * This is our own local instance of a virtual network interface
+ * It is (somewhat) equivalent to using tun/tap in unixoid systems
+ *
+ * Upon initialization, we create such an device node.
+ * Upon termination, we remove it again.
+ *
+ * If we crash this device might stay around.
+ */
+HDEVINFO DeviceInfo = INVALID_HANDLE_VALUE;
+SP_DEVINFO_DATA DeviceNode;
+TCHAR class[128];
+GUID guid;
+
/**
* Creates a tun-interface called dev;
*
@@ -67,17 +91,16 @@
int fd;
if (NULL == dev)
- {
- errno = EINVAL;
- return -1;
- }
+ {
+ errno = EINVAL;
+ return -1;
+ }
/* Hello, I am a stub function! I did my job, yay me! */
-
+
return fd;
}
-
/**
* @brief Sets the IPv6-Address given in address on the interface dev
*
@@ -88,7 +111,7 @@
static void
set_address6 (const char *dev, const char *address, unsigned long prefix_len)
{
- int fd=0;
+ int fd = 0;
/*
* parse the new address
@@ -113,13 +136,12 @@
if (0 != close (fd))
- {
- fprintf (stderr, "close failed: %s\n", strerror (errno));
- exit (1);
- }
+ {
+ fprintf (stderr, "close failed: %s\n", strerror (errno));
+ exit (1);
+ }
}
-
/**
* @brief Sets the IPv4-Address given in address on the interface dev
*
@@ -130,7 +152,7 @@
static void
set_address4 (const char *dev, const char *address, const char *mask)
{
- int fd=0;
+ int fd = 0;
/*
* Parse the address
@@ -161,14 +183,120 @@
if (0 != close (fd))
- {
- fprintf (stderr, "close failed: %s\n", strerror (errno));
- (void) close (fd);
- exit (1);
- }
+ {
+ fprintf (stderr, "close failed: %s\n", strerror (errno));
+ (void) close (fd);
+ exit (1);
+ }
}
+static boolean
+setup_interface ()
+{
+ /*
+ * where to find our inf-file. (+ the "full" path, after windows found")
+ *
+ * We do not directly input all the props here, because openvpn will update
+ * these details over time.
+ */
+ TCHAR InfFile[] = "tapw32.inf";
+ TCHAR hwid[] = "TAP0901";
+ TCHAR * InfFilePath;
+ TCHAR * hwIdList;
+ /**
+ * Locate the inf-file, we need to store it somewhere where the system can
+ * find it. A good choice would be CWD/PDW or %WINDIR$\system32\
+ *
+ * TODO: Finde a more sane way to do this!
+ */
+
+ InfFilePath = calloc (MAX_PATH, sizeof (TCHAR));
+ if (InfFilePath == NULL)
+ {
+ return FALSE;
+ }
+ GetFullPathName (InfFile, MAX_PATH, InfFilePath, NULL);
+
+ /**
+ * Set the device's hardware ID and add it to a list.
+ * This information will later on identify this device in registry.
+ *
+ * TODO: Currently we just use TAP0901 as HWID,
+ * but we might want to add additional information
+ */
+ hwIdList = calloc (LINE_LEN + 4, sizeof (TCHAR));
+ if (hwIdList == NULL)
+ {
+ goto cleanup1;
+ }
+ strncpy (hwIdList, hwid, LINE_LEN);
+
+ /**
+ * Bootstrap our device info using the drivers inf-file
+ */
+ if (!SetupDiGetINFClass (InfFilePath,
+ &guid,
+ class, sizeof (class) / sizeof (TCHAR),
+ NULL))
+ {
+ goto cleanup2;
+ }
+
+ /**
+ * Collect all the other needed information...
+ * let the system fill our this form
+ */
+ DeviceInfo = SetupDiCreateDeviceInfoList (&guid, NULL);
+ if (DeviceInfo == INVALID_HANDLE_VALUE)
+ {
+ goto cleanup3;
+ }
+ DeviceNode.cbSize = sizeof (SP_DEVINFO_DATA);
+ if (!SetupDiCreateDeviceInfo (DeviceInfo,
+ class,
+ &guid,
+ NULL,
+ NULL,
+ DICD_GENERATE_ID,
+ &DeviceNode))
+ {
+ goto cleanup3;
+ }
+
+ /* Deploy all the information collected into the registry */
+ if (!SetupDiSetDeviceRegistryProperty (DeviceInfo,
+ &DeviceNode,
+ SPDRP_HARDWAREID,
+ (LPBYTE) hwIdList,
+ (lstrlen (hwIdList) + 2) * sizeof
(TCHAR)))
+ {
+ goto cleanup3;
+ }
+ /* Install our new class(=device) into the system */
+ if (!SetupDiCallClassInstaller (DIF_REGISTERDEVICE,
+ DeviceInfo,
+ &DeviceNode))
+ {
+ goto cleanup3;
+ }
+
+ return TRUE;
+
+ //disabled for debug-reasons...
+cleanup3:
+ //GNUNET_free(DeviceInfo);
+ ;
+cleanup2:
+ //GNUNET_free(hwIdList);
+ ;
+cleanup1:
+ //GNUNET_free(InfFilePath);
+ ;
+ return FALSE;
+
+}
+
/**
* Start forwarding to and from the tunnel.
*
@@ -194,7 +322,6 @@
/* Hello, I am a stub function! I did my job, yay me! */
}
-
/**
* Open VPN tunnel interface.
*
@@ -206,6 +333,7 @@
* 4: IPv4 address (1.2.3.4), "-" to disable
* 5: IPv4 netmask (255.255.0.0), ignored if #4 is "-"
*/
+
int
main (int argc, char **argv)
{
@@ -214,49 +342,54 @@
int global_ret;
if (6 != argc)
- {
- fprintf (stderr, "Fatal: must supply 5 arguments!\n");
- return 1;
- }
+ {
+ fprintf (stderr, "Fatal: must supply 5 arguments!\n");
+ return 1;
+ }
/*
* strncpy (dev, argv[1], IFNAMSIZ);
* dev[IFNAMSIZ - 1] = '\0';
*/
-/* if (-1 == (fd_tun = init_tun (dev)))
- {
- fprintf (stderr, "Fatal: could not initialize tun-interface with IPv6
%s/%s and IPv4 %s/%s\n",
- dev,
- argv[2],
- argv[3],
- argv[4],
- argv[5]);
- return 1;
- }
- */
+ /* if (-1 == (fd_tun = init_tun (dev)))
+ {
+ fprintf (stderr, "Fatal: could not initialize tun-interface with IPv6
%s/%s and IPv4 %s/%s\n",
+ dev,
+ argv[2],
+ argv[3],
+ argv[4],
+ argv[5]);
+ return 1;
+ }
+ */
if (0 != strcmp (argv[2], "-"))
- {
- const char *address = argv[2];
- long prefix_len = atol (argv[3]);
+ {
+ const char *address = argv[2];
+ long prefix_len = atol (argv[3]);
- if ((prefix_len < 1) || (prefix_len > 127))
+ if ((prefix_len < 1) || (prefix_len > 127))
+ {
+ fprintf (stderr, "Fatal: prefix_len out of range\n");
+ return 1;
+ }
+
+ //set_address6 (dev, address, prefix_len);
+ }
+
+ if (0 != strcmp (argv[4], "-"))
{
- fprintf (stderr, "Fatal: prefix_len out of range\n");
- return 1;
+ const char *address = argv[4];
+ const char *mask = argv[5];
+
+ set_address4 (NULL, address, mask);
}
- //set_address6 (dev, address, prefix_len);
- }
+ if (setup_interface ())
+ {
+ ;
+ }
- if (0 != strcmp (argv[4], "-"))
- {
- const char *address = argv[4];
- const char *mask = argv[5];
-
- set_address4 (NULL, address, mask);
- }
-
/*
uid_t uid = getuid ();
if (0 != setresuid (uid, uid, uid))
@@ -265,7 +398,7 @@
global_ret = 2;
goto cleanup;
}
- */
+ */
/*if (SIG_ERR == signal (SIGPIPE, SIG_IGN))
{
@@ -273,10 +406,10 @@
strerror (errno));
// no exit, we might as well die with SIGPIPE should it ever happen
}
- */
+ */
//run (fd_tun);
global_ret = 0;
- cleanup:
+cleanup:
//close (fd_tun);
return global_ret;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r25209 - gnunet/src/vpn,
gnunet <=