On Wed, Mar 04, 2009 at 04:59:02PM +0000, Nick Martin wrote: > ifr.ifr_flags = IFF_TUN | IFF_NO_PI; /* Create a TUN device */ > > if ( *dev ) > strncpy(ifr.ifr_name, dev, IFNAMSIZ); > > if ( (err = ioctl(fd, TUNSETIFF, (void*) &ifr)) < 0 ) > return err; > > /* Set no check sum - from the example */ > ioctl(fd, TUNSETNOCSUM, 1);
IMHO you should pass a reference to int as 3d arg, not literal "1": int one = 1; ioctl(fd, TUNSETNOCSUM, &one); > /* Get the flags that are set */ > err = ioctl(fd, SIOCGIFFLAGS, (void*) &ifr); > if ( err < 0 ) > return err; > > /* Set the flags that bring the device up */ > ifr.ifr_flags |= ( IFF_UP | IFF_RUNNING ); > err = ioctl(fd, SIOCSIFFLAGS, (void*) &ifr); > if ( err < 0 ) > return err; > > As far as I can tell this is what ifconfig does, but it doesn't work. Linux? It works for me: s0 = socket(PF_INET,SOCK_DGRAM,0); if (s0<0) perror ("socket"); ret = ioctl(s0, SIOCSIFFLAGS, &ifr); if (ret < 0) perror("set flags"); I think that if SIOCGIFFLAGS succeeds on some fd, then SIOCSIFFLAGS should also succeed or return an error. So this is a kernel bug. Can you check it on different OSes? -- Eugene Berdnikov ------------------------------------------------------------------------------ Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H _______________________________________________ VTun-devel mailing list VTun-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vtun-devel