FreeBSD/tools/regression/netinet/msocket_ifnet_remove/msocket_ifnet_remove.c
/*
 * Configure an IP address and netmask on a network interface.
 */
Configure an IP address and netmask on a network interface.
Configure an IP address and netmask on a network interface .
static int
ifconfig_inet(char *ifname, int ifunit, char *ip, char *netmask)
{
	struct sockaddr_in *sinp;
	struct ifaliasreq ifra;
	int s;
	s = socket(PF_INET, SOCK_RAW, 0);
	if (s < 0) {
		warn("ifconfig_inet: socket(PF_INET, SOCK_RAW, 0)");
		return (-1);
	}
	bzero(&ifra, sizeof(ifra));
	snprintf(ifra.ifra_name, sizeof(ifra.ifra_name), "%s%d", ifname,
	    ifunit);
	sinp = (struct sockaddr_in *)&ifra.ifra_addr;
	sinp->sin_family = AF_INET;
	sinp->sin_len = sizeof(ifra.ifra_addr);
	sinp->sin_addr.s_addr = inet_addr(ip);
	sinp = (struct sockaddr_in *)&ifra.ifra_mask;
	sinp->sin_family = AF_INET;
	sinp->sin_len = sizeof(ifra.ifra_addr);
	sinp->sin_addr.s_addr = inet_addr(netmask);
	if (ioctl(s, SIOCAIFADDR, &ifra) < 0) {
		warn("ifconfig_inet: ioctl(%s%d, SIOCAIFADDR, %s)", ifname,
		    ifunit, ip);
		close(s);
		return (-1);
	}
	close(s);
	return (0);
}
static int ifconfig_inet ( char * ifname , int ifunit , char * ip , char * netmask ) { struct sockaddr_in * sinp ; struct ifaliasreq ifra ; int s ; s = socket ( PF_INET , SOCK_RAW , 0 ) ; if ( s < 0 ) { warn ( " " ) ; return ( -1 ) ; } bzero ( & ifra , sizeof ( ifra ) ) ; snprintf ( ifra . ifra_name , sizeof ( ifra . ifra_name ) , " " , ifname , ifunit ) ; sinp = ( struct sockaddr_in * ) & ifra . ifra_addr ; sinp -> sin_family = AF_INET ; sinp -> sin_len = sizeof ( ifra . ifra_addr ) ; sinp -> sin_addr . s_addr = inet_addr ( ip ) ; sinp = ( struct sockaddr_in * ) & ifra . ifra_mask ; sinp -> sin_family = AF_INET ; sinp -> sin_len = sizeof ( ifra . ifra_addr ) ; sinp -> sin_addr . s_addr = inet_addr ( netmask ) ; if ( ioctl ( s , SIOCAIFADDR , & ifra ) < 0 ) { warn ( " " , ifname , ifunit , ip ) ; close ( s ) ; return ( -1 ) ; } close ( s ) ; return ( 0 ) ; }
Configure an IP address and netmask on a network interface.
Configure an IP address and netmask on a network interface .