File: netunshare.c

package info (click to toggle)
vpnc-scripts 0.1~git20220510-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 272 kB
  • sloc: sh: 1,577; javascript: 193; ansic: 24; makefile: 12
file content (30 lines) | stat: -rw-r--r-- 463 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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;
}