+static const struct sockaddr_in blank_sin = {
+ sizeof(struct sockaddr_in),
+ AF_INET,
+ 0,
+ { 0 },
+ { 0, 0, 0, 0, 0, 0, 0, 0 }
+};
+
+static int
+inet_aifaddr(struct socket * so, const char * name,
+ const struct in_addr * addr,
+ const struct in_addr * mask,
+ const struct in_addr * broadcast)
+{
+ struct ifaliasreq ifra;
+
+ bzero(&ifra, sizeof(ifra));
+ strlcpy(ifra.ifra_name, name, sizeof(ifra.ifra_name));
+ if (addr) {
+ *((struct sockaddr_in *)(void *)&ifra.ifra_addr) = blank_sin;
+ ((struct sockaddr_in *)(void *)&ifra.ifra_addr)->sin_addr = *addr;
+ }
+ if (mask) {
+ *((struct sockaddr_in *)(void *)&ifra.ifra_mask) = blank_sin;
+ ((struct sockaddr_in *)(void *)&ifra.ifra_mask)->sin_addr = *mask;
+ }
+ if (broadcast) {
+ *((struct sockaddr_in *)(void *)&ifra.ifra_broadaddr) = blank_sin;
+ ((struct sockaddr_in *)(void *)&ifra.ifra_broadaddr)->sin_addr = *broadcast;
+ }
+ return (ifioctl(so, SIOCAIFADDR, (caddr_t)&ifra, current_proc()));
+}
+
+