summaryrefslogtreecommitdiff
path: root/common/inet.c
diff options
context:
space:
mode:
authorTed Lemon <source@isc.org>1997-11-22 00:45:55 +0000
committerTed Lemon <source@isc.org>1997-11-22 00:45:55 +0000
commita3b267e970d4ed974dafe707a95433f767e20b62 (patch)
treec9c619d6f5c54555a649aadad617dd8631598cbe /common/inet.c
parent612bc350de0449cdbf2c1f7341a3f78ced0919b1 (diff)
downloadisc-dhcp-a3b267e970d4ed974dafe707a95433f767e20b62.tar.gz
Add broadcast_addr function which produces the broadcast address of a subnet given the subnet number and subnet mask.
Diffstat (limited to 'common/inet.c')
-rw-r--r--common/inet.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/common/inet.c b/common/inet.c
index 000d9718..b7c4ba43 100644
--- a/common/inet.c
+++ b/common/inet.c
@@ -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;