FreeBSD/usr.sbin/uhsoctl/uhsoctl.c
/* Add/remove IP address from an interface */
Add/remove IP address from an interface
Add / remove IP address from an interface
static int
ifaddr_ad(int d, const char *ifnam, struct sockaddr *sa, struct sockaddr *mask)
{
	struct ifaliasreq req;
	int fd, error;
	fd = socket(AF_INET, SOCK_DGRAM, 0);
	if (fd < 0)
		return (-1);
	memset(&req, 0, sizeof(struct ifaliasreq));
	strlcpy(req.ifra_name, ifnam, sizeof(req.ifra_name));
	memcpy(&req.ifra_addr, sa, sa->sa_len);
	memcpy(&req.ifra_mask, mask, mask->sa_len);
	error = ioctl(fd, d, (char *)&req);
	close(fd);
	return (error);
}
static int ifaddr_ad ( int d , const char * ifnam , struct sockaddr * sa , struct sockaddr * mask ) { struct ifaliasreq req ; int fd , error ; fd = socket ( AF_INET , SOCK_DGRAM , 0 ) ; if ( fd < 0 ) return ( -1 ) ; memset ( & req , 0 , sizeof ( struct ifaliasreq ) ) ; strlcpy ( req . ifra_name , ifnam , sizeof ( req . ifra_name ) ) ; memcpy ( & req . ifra_addr , sa , sa -> sa_len ) ; memcpy ( & req . ifra_mask , mask , mask -> sa_len ) ; error = ioctl ( fd , d , ( char * ) & req ) ; close ( fd ) ; return ( error ) ; }
Add/remove IP address from an interface
Add / remove IP address from an interface