* This is more efficient than doing it in the scripts

Signed-off-by: Andreas Oberritter <[email protected]>
---
 networking/udhcp/common.h |    2 +-
 networking/udhcp/dhcpc.c  |   17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h
index 0e8e45f..af8c105 100644
--- a/networking/udhcp/common.h
+++ b/networking/udhcp/common.h
@@ -126,7 +126,7 @@ enum {
 //#define DHCP_ROOT_PATH        0x11
 //#define DHCP_IP_TTL           0x17
 //#define DHCP_MTU              0x1a
-//#define DHCP_BROADCAST        0x1c
+#define DHCP_BROADCAST          0x1c
 //#define DHCP_ROUTES           0x21
 //#define DHCP_NIS_DOMAIN       0x28
 //#define DHCP_NIS_SERVER       0x29
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 0862288..fe2e681 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -533,6 +533,23 @@ static char **fill_envp(struct dhcp_packet *packet)
                i++;
        }
 
+       /* Calculate the broadcast address, if it wasn't provided
+        * by the server, but a subnet mask of /30 or lower was given.
+        */
+       if (udhcp_get_option(packet, DHCP_BROADCAST) == NULL) {
+               temp = udhcp_get_option(packet, DHCP_SUBNET);
+               if (temp) {
+                       uint32_t subnet;
+                       move_from_unaligned32(subnet, temp);
+                       if (ntohl(subnet) <= 0xfffffffc) {
+                               uint32_t broadcast = packet->yiaddr | ~subnet;
+                               *curr = 
xmalloc(sizeof("broadcast=255.255.255.255"));
+                               sprint_nip(*curr, "broadcast=", (uint8_t 
*)&broadcast);
+                               putenv(*curr++);
+                       }
+               }
+       }
+
        return envp;
 }
 
-- 
1.7.10.4

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to