rem: if (cmd == SIOCDIFADDR && ia == NULL)
add: if (cmd == (int) SIOCDIFADDR && ia == NULL)
context: int in_control(struct socket *so, int cmd, caddr_t data, struct ifnet *ifp){	struct ifreq *ifr = (struct ifreq*)data;	struct in_ifaddr *ia = NULL;	struct ifaddr *ifa;	struct in_ifaddr *oia;	struct in_aliasreq *ifra = (struct in_aliasreq*)data;	struct sockaddr_in oldaddr;	int error = 0, hostIsNew, maskIsNew;	long i;	if (ifp) /* we need to find the in_ifaddr */		for (ia = in_ifaddr;ia; ia = ia->ia_next)			if (ia->ia_ifp == ifp)				break;			switch (cmd) {		case SIOCAIFADDR:			printf("SIOCAIFADDR\n");			/* add an address */		case SIOCDIFADDR:			printf("SIODIFADDR\n");			/* delete an address */			if (ifra->ifra_addr.sin_family == AF_INET)				for (oia = ia; ia; ia = ia->ia_next) {					if (ia->ia_ifp == ifp &&					    ia->ia_addr.sin_addr.s_addr == ifra->ifra_addr.sin_addr.s_addr)						break;				}			if (cmd == SIOCDIFADDR && ia == NULL)				return EADDRNOTAVAIL;		case SIOCSIFADDR:			printf("SIOCSIFADDR\n");			/* set an address */		case SIOCSIFNETMASK:			printf("SIOCSIFNETMASK #1 (%d)\n", cmd);			/* set a net mask */		case SIOCSIFDSTADDR:			/* set the destination address of a point to point link */			if (!ifp) {				printf("No interface pointer!\n");				return EINVAL;			}			if (ia == NULL) {				oia = (struct in_ifaddr*)malloc(sizeof(struct in_ifaddr));				if (oia == NULL)					return ENOMEM;				memset(oia, 0, sizeof(*oia));				if ((ia = in_ifaddr)) {					/* we've got other structures - add at end */					for (; ia->ia_next; ia = ia->ia_next)						continue;					ia->ia_next = oia;				} else					in_ifaddr = oia;								ia = oia;				if ((ifa = ifp->if_addrlist)) {					for (; ifa->ifa_next; ifa = ifa->ifa_next)						continue;					ifa->ifa_next = (struct ifaddr*)ia;				} else					ifp->if_addrlist =  (struct ifaddr*)ia;								ia->ia_ifa.ifa_addr     = (struct sockaddr*) &ia->ia_addr;				ia->ia_ifa.ifa_dstaddr  = (struct sockaddr*) &ia->ia_dstaddr;				ia->ia_ifa.ifa_netmask  = (struct sockaddr*) &ia->ia_sockmask;				ia->ia_sockmask.sin_len = 8;				if (ifp->if_flags & IFF_BROADCAST) {					ia->ia_broadaddr.sin_len = sizeof(ia->ia_addr);					ia->ia_broadaddr.sin_family = AF_INET;				}				ia->ia_ifp = ifp;			}			break;		case SIOCSIFBRDADDR:		case SIOCGIFADDR:		case SIOCGIFNETMASK:		case SIOCGIFDSTADDR:		case SIOCGIFBRDADDR:			if (ia == NULL)				return EADDRNOTAVAIL;			break;					}		printf("loop #2 : %d [%ld]\n", cmd, SIOCSIFNETMASK);		switch(cmd) {		case SIOCGIFADDR:			/* get interface address */			*((struct sockaddr_in*) &ifr->ifr_addr) = ia->ia_addr;			break;		case SIOCGIFDSTADDR:			/* get interface point to point destination address */			if ((ifp->if_flags & IFF_POINTOPOINT) == 0)				/* we're not a point to point interface */				return EINVAL;			*((struct sockaddr_in*) &ifr->ifr_dstaddr) = ia->ia_dstaddr;			break;		case SIOCGIFBRDADDR:			/* get interface broadcast address */			if ((ifp->if_flags & IFF_BROADCAST) == 0)				/* we're not a broadcast capable interface */				return EINVAL;			*((struct sockaddr_in*) &ifr->ifr_dstaddr) = ia->ia_broadaddr;			break;		case SIOCGIFNETMASK:			/* get interface netmask */			*((struct sockaddr_in*) &ifr->ifr_addr) = ia->ia_sockmask;			break;		case SIOCSIFADDR:			printf("SIOCSIFADDR #2\n");			return in_ifinit(ifp, ia, (struct sockaddr_in*)&ifr->ifr_addr, 1);		case SIOCSIFNETMASK:			printf("Setting netmask\n");			/* set the netmask for the interface... */			/* set i to the network netmask (network host order) */			i = ifra->ifra_addr.sin_addr.s_addr;			/* set the host byte order netmask into ia_subnetmask */			ia->ia_subnetmask = ntohl((ia->ia_sockmask.sin_addr.s_addr = i));printf("ia->ia_subnetmask: %08lx\n", ia->ia_subnetmask);			break;		case SIOCSIFDSTADDR:			if ((ifp->if_flags & IFF_POINTOPOINT) == 0)				return EINVAL;			oldaddr = ia->ia_dstaddr;			ia->ia_dstaddr = *(struct sockaddr_in*)&ifr->ifr_dstaddr;			/* update the interface if required */			if (ifp->ioctl) {				error = ifp->ioctl(ifp, SIOCSIFDSTADDR, (caddr_t) ia);				if (error) {					ia->ia_dstaddr = oldaddr;					return error;				}			}			/* change the routing info if it's been set */			if (ia->ia_flags & IFA_ROUTE) {				ia->ia_ifa.ifa_dstaddr = (struct sockaddr*)&oldaddr;				rtinit(&(ia->ia_ifa), RTM_DELETE, RTF_HOST);				ia->ia_ifa.ifa_dstaddr = (struct sockaddr*)&ia->ia_dstaddr;				rtinit(&(ia->ia_ifa), RTM_ADD, RTF_HOST|RTF_UP);			}			break;		case SIOCSIFBRDADDR:			/* set the broadcast address if interface supports it */			if ((ifp->if_flags & IFF_BROADCAST) == 0)				/* we don't support broadcast on that interface */				return EINVAL;			ia->ia_broadaddr = *(struct sockaddr_in*) &ifr->ifr_broadaddr;			break;		case SIOCAIFADDR:			maskIsNew = 0;			hostIsNew = 1;			error = 0;			if (ia->ia_addr.sin_family == AF_INET) {				if (ifra->ifra_addr.sin_len == 0) {					ifra->ifra_addr = ia->ia_addr;					hostIsNew = 0;				} else if (ifra->ifra_addr.sin_addr.s_addr == 				           ia->ia_addr.sin_addr.s_addr)					hostIsNew = 0;			}			if (ifra->ifra_mask.sin_len) {				in_scrubprefix(ia);				ia->ia_sockmask = ifra->ifra_mask;				ia->ia_subnetmask = ia->ia_sockmask.sin_addr.s_addr;				maskIsNew = 1;			}			if ((ifp->if_flags & IFF_POINTOPOINT) &&			    (ifra->ifra_dstaddr.sin_family == AF_INET)) {				in_scrubprefix(ia);				ia->ia_dstaddr = ifra->ifra_dstaddr;				maskIsNew = 1;			}			if (ifra->ifra_addr.sin_family == AF_INET &&			    (hostIsNew || maskIsNew))				error = in_ifinit(ifp, ia, &ifra->ifra_addr, 0);			if ((ifp->if_flags & IFF_BROADCAST) &&			    (ifra->ifra_broadaddr.sin_family == AF_INET))				ia->ia_broadaddr = ifra->ifra_broadaddr;			return error;		default:		printf("2nd iteration: default (%d)\n", cmd);			/* if we don't have enough to do the default, return */			if (ifp == NULL || ifp->ioctl == NULL)				return EINVAL; /* XXX - should be EOPNOTSUPP */			/* send to the card and let it process it */			return ifp->ioctl(ifp, cmd, data);	}	return 0;}