contrib/hostapd/hostapd/vlan_init.c
static int br_addif(const char *br_name, const char *if_name)
{
	int fd;
	struct ifreq ifr;
	unsigned long args[2];
	int if_index;

	if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
		perror("socket[AF_INET,SOCK_STREAM]");
		return -1;
	}

	if_index = if_nametoindex(if_name);

	if (if_index == 0) {
		printf("Failure determining interface index for '%s'\n",
		       if_name);
		close(fd);
		return -1;
	}

	args[0] = BRCTL_ADD_IF;
	args[1] = if_index;

	os_strlcpy(ifr.ifr_name, br_name, sizeof(ifr.ifr_name));
	ifr.ifr_data = (__caddr_t) args;

	if (ioctl(fd, SIOCDEVPRIVATE, &ifr) < 0) {
		if (errno == EBUSY) {
			/* The interface is already added. */
			close(fd);
			return 1;
		}

		perror("ioctl[SIOCDEVPRIVATE,BRCTL_ADD_IF]");
		close(fd);
		return -1;
	}

	close(fd);
	return 0;
}
/*
	Add interface 'if_name' to the bridge 'br_name'

	returns -1 on error
	returns 1 if the interface is already part of the bridge
	returns 0 otherwise
*/
Add interface 'if_name' to the bridge 'br_name'
returns -1 on error
returns 1 if the interface is already part of the bridge
returns 0 otherwise
Add interface ' if_name ' to the bridge ' br_name ' returns - 1 on error returns 1 if the interface is already part of the bridge returns 0 otherwise
static int br_addif(const char *br_name, const char *if_name)
{
	int fd;
	struct ifreq ifr;
	unsigned long args[2];
	int if_index;
	if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
		perror("socket[AF_INET,SOCK_STREAM]");
		return -1;
	}
	if_index = if_nametoindex(if_name);
	if (if_index == 0) {
		printf("Failure determining interface index for '%s'\n",
		       if_name);
		close(fd);
		return -1;
	}
	args[0] = BRCTL_ADD_IF;
	args[1] = if_index;
	os_strlcpy(ifr.ifr_name, br_name, sizeof(ifr.ifr_name));
	ifr.ifr_data = (__caddr_t) args;
	if (ioctl(fd, SIOCDEVPRIVATE, &ifr) < 0) {
		if (errno == EBUSY) {
			close(fd);
			return 1;
		}
		perror("ioctl[SIOCDEVPRIVATE,BRCTL_ADD_IF]");
		close(fd);
		return -1;
	}
	close(fd);
	return 0;
}
static int br_addif ( const char * br_name , const char * if_name ) { int fd ; struct ifreq ifr ; unsigned long args [ 2 ] ; int if_index ; if ( ( fd = socket ( AF_INET , SOCK_STREAM , 0 ) ) < 0 ) { perror ( " " ) ; return -1 ; } if_index = if_nametoindex ( if_name ) ; if ( if_index == 0 ) { printf ( " \n " , if_name ) ; close ( fd ) ; return -1 ; } args [ 0 ] = BRCTL_ADD_IF ; args [ 1 ] = if_index ; os_strlcpy ( ifr . ifr_name , br_name , sizeof ( ifr . ifr_name ) ) ; ifr . ifr_data = ( __caddr_t ) args ; if ( ioctl ( fd , SIOCDEVPRIVATE , & ifr ) < 0 ) { if ( errno == EBUSY ) { close ( fd ) ; return 1 ; } perror ( " " ) ; close ( fd ) ; return -1 ; } close ( fd ) ; return 0 ; }
Add interface 'if_name' to the bridge 'br_name'
returns -1 on error
returns 1 if the interface is already part of the bridge
returns 0 otherwise
Add interface ' if_name ' to the bridge ' br_name ' returns - 1 on error returns 1 if the interface is already part of the bridge returns 0 otherwise
/* The interface is already added. */