summaryrefslogtreecommitdiff
path: root/src/libsystemd-network/sd-dhcp-lease.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-10-27 17:38:03 +0100
committerTom Gundersen <teg@jklm.no>2014-10-27 17:40:24 +0100
commitdf40eee8edccb6bf09a57c2b96f69d233032ce52 (patch)
tree3b2c4fbf001cba0b9a5ea0bb6b152899525c25bd /src/libsystemd-network/sd-dhcp-lease.c
parent1dfcee5985e8097fdbe0a77ca31fa23f683fadc2 (diff)
shared: in-addr-utils - add default_subnet_mask and default_prefixlen methods
These use the (deprecated) IPv4 address classes to deduce the corresponding subnet masks. This is useful when addresses without subnet masks and prefix lengths are given. Make use of these new functions from sd-dhcp-lease.
Diffstat (limited to 'src/libsystemd-network/sd-dhcp-lease.c')
-rw-r--r--src/libsystemd-network/sd-dhcp-lease.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c
index 6680d06736..4fb01c0729 100644
--- a/src/libsystemd-network/sd-dhcp-lease.c
+++ b/src/libsystemd-network/sd-dhcp-lease.c
@@ -30,6 +30,7 @@
#include "list.h"
#include "mkdir.h"
#include "fileio.h"
+#include "in-addr-util.h"
#include "dhcp-protocol.h"
#include "dhcp-internal.h"
@@ -803,27 +804,20 @@ int dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret) {
}
int dhcp_lease_set_default_subnet_mask(sd_dhcp_lease *lease) {
- uint32_t address;
+ struct in_addr address;
+ struct in_addr mask;
+ int r;
assert(lease);
- assert(lease->address != INADDR_ANY);
- address = be32toh(lease->address);
+ address.s_addr = lease->address;
/* fall back to the default subnet masks based on address class */
+ r = in_addr_default_subnet_mask(&address, &mask);
+ if (r < 0)
+ return r;
- if ((address >> 31) == 0x0)
- /* class A, leading bits: 0 */
- lease->subnet_mask = htobe32(0xff000000);
- else if ((address >> 30) == 0x2)
- /* class B, leading bits 10 */
- lease->subnet_mask = htobe32(0xffff0000);
- else if ((address >> 29) == 0x6)
- /* class C, leading bits 110 */
- lease->subnet_mask = htobe32(0xffffff00);
- else
- /* class D or E, no default mask. give up */
- return -ERANGE;
+ lease->subnet_mask = mask.s_addr;
return 0;
}