src/tunalloc.c
int receive_vif_fd(int fd, char *vif_name) {
	struct msghdr msg;
	struct iovec iov;
	int rv;
	size_t ccmsg[CMSG_SPACE(sizeof(int)) / sizeof(size_t)];
	struct cmsghdr *cmsg;

    /* Use IOV to read interface name */
	iov.iov_base = vif_name;
	iov.iov_len = IFNAMSIZ;

	msg.msg_name = 0;
	msg.msg_namelen = 0;
	msg.msg_iov = &iov;
	msg.msg_iovlen = 1;
	/* old BSD implementations should use msg_accrights instead of
	 * msg_control; the interface is different. */
	msg.msg_control = ccmsg;
	msg.msg_controllen = sizeof(ccmsg);

	while(((rv = recvmsg(fd, &msg, 0)) == -1) && errno == EINTR);
	if (rv == -1) die("recvmsg");
	if(!rv) return -1;

	cmsg = CMSG_FIRSTHDR(&msg);
	if (!cmsg->cmsg_type == SCM_RIGHTS) {
		debug_print("got control message of unknown type %d\n",
			cmsg->cmsg_type);
		return -1;
	}
	return *(int*)CMSG_DATA(cmsg);
}
/* Reads vif FD from "fd", writes interface name to vif_name, and returns vif FD.
 * vif_name should be IFNAMSIZ chars long. */
Reads vif FD from "fd", writes interface name to vif_name, and returns vif FD.
vif_name should be IFNAMSIZ chars long.
Reads vif FD from " fd " writes interface name to vif_name and returns vif FD . vif_name should be IFNAMSIZ chars long .
int receive_vif_fd(int fd, char *vif_name) {
	struct msghdr msg;
	struct iovec iov;
	int rv;
	size_t ccmsg[CMSG_SPACE(sizeof(int)) / sizeof(size_t)];
	struct cmsghdr *cmsg;
	iov.iov_base = vif_name;
	iov.iov_len = IFNAMSIZ;
	msg.msg_name = 0;
	msg.msg_namelen = 0;
	msg.msg_iov = &iov;
	msg.msg_iovlen = 1;
	msg.msg_control = ccmsg;
	msg.msg_controllen = sizeof(ccmsg);
	while(((rv = recvmsg(fd, &msg, 0)) == -1) && errno == EINTR);
	if (rv == -1) die("recvmsg");
	if(!rv) return -1;
	cmsg = CMSG_FIRSTHDR(&msg);
	if (!cmsg->cmsg_type == SCM_RIGHTS) {
		debug_print("got control message of unknown type %d\n",
			cmsg->cmsg_type);
		return -1;
	}
	return *(int*)CMSG_DATA(cmsg);
}
int receive_vif_fd ( int fd , char * vif_name ) { struct msghdr msg ; struct iovec iov ; int rv ; size_t ccmsg [ CMSG_SPACE ( sizeof ( int ) ) / sizeof ( size_t ) ] ; struct cmsghdr * cmsg ; iov . iov_base = vif_name ; iov . iov_len = IFNAMSIZ ; msg . msg_name = 0 ; msg . msg_namelen = 0 ; msg . msg_iov = & iov ; msg . msg_iovlen = 1 ; msg . msg_control = ccmsg ; msg . msg_controllen = sizeof ( ccmsg ) ; while ( ( ( rv = recvmsg ( fd , & msg , 0 ) ) == -1 ) && errno == EINTR ) ; if ( rv == -1 ) die ( " " ) ; if ( ! rv ) return -1 ; cmsg = CMSG_FIRSTHDR ( & msg ) ; if ( ! cmsg -> cmsg_type == SCM_RIGHTS ) { debug_print ( " \n " , cmsg -> cmsg_type ) ; return -1 ; } return * ( int * ) CMSG_DATA ( cmsg ) ; }
Reads vif FD from "fd", writes interface name to vif_name, and returns vif FD.
Reads vif FD from " fd " writes interface name to vif_name and returns vif FD .
/* Use IOV to read interface name */ /* old BSD implementations should use msg_accrights instead of
	 * msg_control; the interface is different. */