]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Calculate netmask from cidr more efficiently.
authorRoy Marples <roy@marples.name>
Mon, 20 Oct 2008 09:56:21 +0000 (09:56 +0000)
committerRoy Marples <roy@marples.name>
Mon, 20 Oct 2008 09:56:21 +0000 (09:56 +0000)
dhcp.c

diff --git a/dhcp.c b/dhcp.c
index 79d7b0035eebe9e3aa6c29793d4a18aad192f7c8..bdcc04eafd26c122b2dd93c728d05dbf8ab33917 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -534,13 +534,8 @@ decode_rfc3442_rt(int dl, const uint8_t *data)
                /* If we have ocets then we have a destination and netmask */
                if (ocets > 0) {
                        memcpy(&rt->dest.s_addr, p, ocets);
-                       memset(&rt->net.s_addr, 255, ocets);
-                       memset((uint8_t *)&rt->net.s_addr + (ocets - 1),
-                              (256 - (1 << (32 - cidr) % 8)), 1);
                        p += ocets;
-               } else {
-                       rt->dest.s_addr = 0;
-                       rt->net.s_addr = 0;
+                       rt->net.s_addr = htonl(~0 << (32 - cidr));
                }
 
                /* Finally, snag the router */