[lxc-devel] creation of netwok name space
Daniel Lezcano
daniel.lezcano at free.fr
Wed Feb 9 14:00:48 UTC 2011
On 02/09/2011 02:11 PM, Maheswara Reddy C - ERS, HCL Tech wrote:
> Hi,
>
> I have created a namespace (below sample program) and how can I create a network name space.
>
> #include<stdio.h>
> #include<sched.h>
> #include<alloca.h>
> #include<signal.h>
> #include<sys/types.h>
> #include<unistd.h>
>
> struct clone_arg {
> int (*fn)(void *);
> void *arg;
> };
>
> static int do_start(void *data)
> {
> printf("do_start");
> }
>
> static int do_clone(void *arg)
> {
> struct clone_arg *clone_arg = arg;
> printf("inside do_clone");
> return clone_arg->fn(clone_arg->arg);
> }
>
> int main()
> {
> int (*fn)(void *) ;
> fn=do_start;
> struct clone_arg clone_arg ={.fn=fn,.arg=NULL };
> long stack_size = sysconf(_SC_PAGESIZE);
> void *stack = alloca(stack_size) + stack_size;
> int flags= CLONE_NEWNS;
int flags = CLONE_NEWNET;
Or instead of clone, do it directly in the current process context:
unshare(CLONE_NEWNET);
> pid_t ret;
> printf("inside main");
> ret = clone(do_clone, stack, flags ,&clone_arg);
>
> return 1;
>
> }Lxc-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/lxc-devel
More information about the lxc-devel
mailing list