Skip to content

Commit a0052da

Browse files
committed
DHCP: work with the broadcast flag correctly
1 parent 2ceeb23 commit a0052da

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/dhcp.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ dhcp_outputipudp(const struct interface *ifp, const struct in_addr *src,
343343
udp.uh_dport = htons(BOOTPS);
344344
} else {
345345
if ((bootp->ciaddr == INADDR_ANY &&
346-
bootp->flags & BROADCAST_FLAG) ||
346+
ntohs(bootp->flags) & BROADCAST_FLAG) ||
347347
type == DHCP_NAK)
348348
ip.ip_dst.s_addr = INADDR_BROADCAST;
349349
else
@@ -860,6 +860,7 @@ dhcp_output(const struct interface *ifp, const struct dhcp_lease *lease,
860860

861861
memset(bootp, 0, sizeof(*bootp));
862862
bootp->op = BOOTREPLY;
863+
bootp->flags = htons(ntohs(req->flags) & BROADCAST_FLAG);
863864
bootp->htype = req->htype;
864865
bootp->hlen = req->hlen;
865866
if (req->hlen > 0)
@@ -1239,8 +1240,9 @@ dhcp_handlebootp(struct interface *ifp, struct bootp *bootp, size_t len,
12391240
return;
12401241
}
12411242

1242-
logdebugx("%s: %s 0x%x %s: %s", ifp->if_name, flags ? "cont" : "recv",
1243-
bootp->xid, dhcp_message_type(type), clid);
1243+
logdebugx("%s: %s 0x%x %s%s: %s", ifp->if_name, flags ? "cont" : "recv",
1244+
bootp->xid, dhcp_message_type(type),
1245+
ntohs(bootp->flags) & BROADCAST_FLAG ? "(bcast)" : "", clid);
12441246

12451247
lease = dhcp_newlease(ctx, clientid);
12461248
if (lease == NULL)

0 commit comments

Comments
 (0)