]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
Add broadcast_addr function which produces the broadcast address of a subnet given...
authorTed Lemon <source@isc.org>
Sat, 22 Nov 1997 00:45:55 +0000 (00:45 +0000)
committerTed Lemon <source@isc.org>
Sat, 22 Nov 1997 00:45:55 +0000 (00:45 +0000)
common/inet.c

index 000d97183905af14c68a855318a03da123cb1b25..b7c4ba4384803911d0cbcbe46b055c544845abf2 100644 (file)
@@ -106,6 +106,30 @@ struct iaddr ip_addr (subnet, mask, host_address)
        return rv;
 }
 
+/* Given a subnet number and netmask, return the address on that subnet
+   for which the host portion of the address is all ones (the standard
+   broadcast address). */
+
+struct iaddr broadcast_addr (subnet, mask)
+       struct iaddr subnet;
+       struct iaddr mask;
+{
+       int i, j, k;
+       struct iaddr rv;
+
+       if (subnet.len != mask.len) {
+               rv.len = 0;
+               return rv;
+       }
+
+       for (i = 0; i < subnet.len; i++) {
+               rv.iabuf [i] = subnet.iabuf [i] | (~mask.iabuf [i] & 255);
+       }
+       rv.len = subnet.len;
+
+       return rv;
+}
+
 u_int32_t host_addr (addr, mask)
        struct iaddr addr;
        struct iaddr mask;