chiark / gitweb /
libsystemd-dhcp: Use be32_t for IP addresses in network order.
[elogind.git] / src / libsystemd-dhcp / dhcp-client.c
index 03a846d..fe41067 100644 (file)
@@ -36,10 +36,10 @@ struct DHCPLease {
         uint32_t t1;
         uint32_t t2;
         uint32_t lifetime;
-        uint32_t address;
-        uint32_t server_address;
-        uint32_t subnet_mask;
-        uint32_t router;
+        be32_t address;
+        be32_t server_address;
+        be32_t subnet_mask;
+        be32_t router;
 };
 
 typedef struct DHCPLease DHCPLease;
@@ -54,7 +54,7 @@ struct sd_dhcp_client {
         sd_event_source *receive_message;
         uint8_t *req_opts;
         size_t req_opts_size;
-        uint32_t last_addr;
+        be32_t last_addr;
         struct ether_addr mac_addr;
         uint32_t xid;
         usec_t start_time;
@@ -897,6 +897,9 @@ static int client_receive_raw_message(sd_event_source *s, int fd,
                         client->receive_message =
                                 sd_event_source_unref(client->receive_message);
                 }
+
+                r = 0;
+
                 break;
 
         case DHCP_STATE_INIT:
@@ -910,7 +913,7 @@ static int client_receive_raw_message(sd_event_source *s, int fd,
         }
 
 error:
-        if (r < 0)
+        if (r < 0 || r == DHCP_EVENT_NO_LEASE)
                 return client_stop(client, r);
 
         return 0;
@@ -961,6 +964,19 @@ int sd_dhcp_client_stop(sd_dhcp_client *client)
         return client_stop(client, DHCP_EVENT_STOP);
 }
 
+sd_dhcp_client *sd_dhcp_client_free(sd_dhcp_client *client)
+{
+        assert_return(client, NULL);
+
+        sd_dhcp_client_stop(client);
+
+        sd_event_unref(client->event);
+        free(client->req_opts);
+        free(client);
+
+        return NULL;
+}
+
 sd_dhcp_client *sd_dhcp_client_new(sd_event *event)
 {
         sd_dhcp_client *client;