]> www.infradead.org Git - users/dwmw2/vpnc-scripts.git/commitdiff
Add netunshare
authorDavid Woodhouse <David.Woodhouse@intel.com>
Sat, 6 Jun 2009 12:19:27 +0000 (13:19 +0100)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Sat, 6 Jun 2009 12:19:27 +0000 (13:19 +0100)
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
netunshare.c [new file with mode: 0644]

diff --git a/netunshare.c b/netunshare.c
new file mode 100644 (file)
index 0000000..6c3fbfd
--- /dev/null
@@ -0,0 +1,30 @@
+#define _GNU_SOURCE
+#include <sched.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+
+#ifndef CLONE_NEWNET
+#error CLONE_NEWNET not defined
+#endif
+
+int main(int argc, char *argv[])
+{      
+       if (argc < 1) {
+               fprintf(stderr, "usage: %s <command> [<args...>]\n",
+                       basename(argv[0]));
+               return 1;
+       }
+       argv++;
+
+       if (unshare(CLONE_NEWNET) == -1) {
+               perror("unshare");
+               return 1;
+       } 
+       
+       execv(argv[0], argv);
+       /* Failed... */
+       perror("execve");
+       return 1;
+}
+