BZERO(&ifr, sizeof(ifr)); strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1); ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0'; if (ioctl(sockfd, SIOCDIFADDR, (caddr_t) &ifr) < 0) { if (errno != EADDRNOTAVAIL) syslog(LOG_WARNING, "Couldn't remove interface address: %m"); }
sifaddr(u, o, h, m)    int u;    u_int32_t o, h, m;{    struct ifaliasreq ifra;    strncpy(ifra.ifra_name, ifname, sizeof(ifra.ifra_name) - 1);    ifra.ifra_name[sizeof(ifra.ifra_name) - 1] = '\0';    SET_SA_FAMILY(ifra.ifra_addr, AF_INET);    ((struct sockaddr_in *) &ifra.ifra_addr)->sin_addr.s_addr = o;    SET_SA_FAMILY(ifra.ifra_broadaddr, AF_INET);    ((struct sockaddr_in *) &ifra.ifra_broadaddr)->sin_addr.s_addr = h;    if (m != 0) {	SET_SA_FAMILY(ifra.ifra_mask, AF_INET);	((struct sockaddr_in *) &ifra.ifra_mask)->sin_addr.s_addr = m;    } else	BZERO(&ifra.ifra_mask, sizeof(ifra.ifra_mask));    if (ioctl(sockfd, SIOCAIFADDR, (caddr_t) &ifra) < 0) {	if (errno != EEXIST) {	    syslog(LOG_ERR, "Couldn't set interface address: %m");	    return 0;	}	syslog(LOG_WARNING,	       "Couldn't set interface address: Address %s already exists",	       ip_ntoa(o));    }    ifaddrs[0] = o;    ifaddrs[1] = h;    return 1;}