1 From fe285afc183e72301bc823933e8f6059cd29a0b9 Mon Sep 17 00:00:00 2001
2 From: Andreas Oberritter <obi@opendreambox.org>
3 Date: Mon, 14 May 2012 17:32:16 +0200
4 Subject: [PATCH 3/8] udhcpc: calculate broadcast address if not given by
7 * This is more efficient than doing it in the scripts
9 Signed-off-by: Andreas Oberritter <obi@opendreambox.org>
11 networking/udhcp/common.h | 2 +-
12 networking/udhcp/dhcpc.c | 17 +++++++++++++++++
13 2 files changed, 18 insertions(+), 1 deletion(-)
15 diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h
16 index cfd5867..c48dd0a 100644
17 --- a/networking/udhcp/common.h
18 +++ b/networking/udhcp/common.h
19 @@ -126,7 +126,7 @@ enum {
20 //#define DHCP_ROOT_PATH 0x11
21 //#define DHCP_IP_TTL 0x17
22 //#define DHCP_MTU 0x1a
23 -//#define DHCP_BROADCAST 0x1c
24 +#define DHCP_BROADCAST 0x1c
25 //#define DHCP_ROUTES 0x21
26 //#define DHCP_NIS_DOMAIN 0x28
27 //#define DHCP_NIS_SERVER 0x29
28 diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
29 index ddb328d..5a6c220 100644
30 --- a/networking/udhcp/dhcpc.c
31 +++ b/networking/udhcp/dhcpc.c
32 @@ -533,6 +533,23 @@ static char **fill_envp(struct dhcp_packet *packet)
36 + /* Calculate the broadcast address, if it wasn't provided
37 + * by the server, but a subnet mask of /30 or lower was given.
39 + if (udhcp_get_option(packet, DHCP_BROADCAST) == NULL) {
40 + temp = udhcp_get_option(packet, DHCP_SUBNET);
43 + move_from_unaligned32(subnet, temp);
44 + if (ntohl(subnet) <= 0xfffffffc) {
45 + uint32_t broadcast = packet->yiaddr | ~subnet;
46 + *curr = xmalloc(sizeof("broadcast=255.255.255.255"));
47 + sprint_nip(*curr, "broadcast=", (uint8_t *)&broadcast);