chiark / gitweb /
sd-dhcp-client: fix invalid free() in client_send_request()
[elogind.git] / src / libsystemd-network / sd-dhcp-client.c
index 0300a6be93162d23eda68e378d94244a86518d5a..2a46624f2e8c328e41c520e3377c96dd15f1c92d 100644 (file)
@@ -286,6 +286,15 @@ static int client_message_init(sd_dhcp_client *client, DHCPPacket **ret,
            refuse to issue an DHCP lease if 'secs' is set to zero */
         packet->dhcp.secs = htobe16(client->secs);
 
+        /* RFC2132 section 4.1
+           A client that cannot receive unicast IP datagrams until its protocol
+           software has been configured with an IP address SHOULD set the
+           BROADCAST bit in the 'flags' field to 1 in any DHCPDISCOVER or
+           DHCPREQUEST messages that client sends.  The BROADCAST bit will
+           provide a hint to the DHCP server and BOOTP relay agent to broadcast
+           any messages to the client on the client's subnet. */
+        packet->dhcp.flags = htobe16(0x8000);
+
         /* RFC2132 section 4.1.1:
            The client MUST include its hardware address in the â€™chaddr’ field, if
            necessary for delivery of DHCP reply messages.
@@ -404,7 +413,7 @@ static int client_send_discover(sd_dhcp_client *client) {
 }
 
 static int client_send_request(sd_dhcp_client *client) {
-        _cleanup_free_ DHCPPacket *request;
+        _cleanup_free_ DHCPPacket *request = NULL;
         size_t optoffset, optlen;
         int r;