All pastes #943835 Raw Edit

Mine

public text v1 · immutable
·published 2008-03-15 17:14 UTC
rendered paste body
int _tunnel_create_device(tunnel * tun) {
	struct ifreq ifr;
	struct ifreq ifrq;
	int fd;
	int s;
	struct sockaddr_in *sin;

	if((fd = open("/dev/net/tun", O_RDWR)) < 0) {
		return -1;
	}
	
	memset(&ifr, 0, sizeof(ifr));
	//ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
	ifr.ifr_flags = IFF_TUN;
	if(tun->dev[0] != 0) {
		strncpy(ifr.ifr_name, tun->dev, IFNAMSIZ);
	}

	if (ioctl(fd, TUNSETIFF, (void *) &ifr) < 0) {
		if (errno == EBADFD) {
			/* Try old ioctl */
			//if (ioctl(fd, OTUNSETIFF, (void *) &ifr) < 0) {
				close(fd);
				return -1;
			//}
		} else {
			close(fd);
			return -1;
		}
	}
	
	tun->local_fd = fd;

	
	
	strcpy(tun->dev, ifr.ifr_name);
	log_message(LOG_LEVEL_DEBUG, "Device %s opened", tun->dev);
	tun->local_fd = fd;
	return 0;
}