summaryrefslogtreecommitdiff
path: root/src/libsystemd-network/dhcp-packet.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-04-06 14:05:32 +0200
committerTom Gundersen <teg@jklm.no>2014-04-06 19:36:05 +0200
commit3b7ca119fdc501e21f017695dc9b6f82fdbd1d93 (patch)
treeefefc912fa1925f1197dd0e5b56a14ad2282de38 /src/libsystemd-network/dhcp-packet.c
parent19aa72f74e41045510b4af3f1415b419d42ff20b (diff)
sd-dhcp-client: move magic cookie into DHCPMessage struct
Also move the checking of it to the main message handler, rather than the options parser. Fix a bug, so we now drop the packet if any of the magic bytes don't match. Before we used to only drop the packet if they were all wrong.
Diffstat (limited to 'src/libsystemd-network/dhcp-packet.c')
-rw-r--r--src/libsystemd-network/dhcp-packet.c14
1 files changed, 2 insertions, 12 deletions
diff --git a/src/libsystemd-network/dhcp-packet.c b/src/libsystemd-network/dhcp-packet.c
index 4f90c283a2..0549f575ac 100644
--- a/src/libsystemd-network/dhcp-packet.c
+++ b/src/libsystemd-network/dhcp-packet.c
@@ -43,23 +43,13 @@ int dhcp_message_init(DHCPMessage *message, uint8_t op, uint32_t xid,
assert(op == BOOTREQUEST || op == BOOTREPLY);
- *opt = (uint8_t *)(message + 1);
-
- if (*optlen < 4)
- return -ENOBUFS;
- *optlen -= 4;
-
message->op = op;
message->htype = ARPHRD_ETHER;
message->hlen = ETHER_ADDR_LEN;
message->xid = htobe32(xid);
+ message->magic = htobe32(DHCP_MAGIC_COOKIE);
- (*opt)[0] = 0x63;
- (*opt)[1] = 0x82;
- (*opt)[2] = 0x53;
- (*opt)[3] = 0x63;
-
- *opt += 4;
+ *opt = (uint8_t *)(message + 1);
err = dhcp_option_append(opt, optlen, DHCP_OPTION_MESSAGE_TYPE, 1,
&type);