chiark / gitweb /
sd-dhcp-client: test - fix for jenkins
[elogind.git] / src / libsystemd-network / test-dhcp-client.c
index ca44cfbdc52b0269665b97226117dfdc7b5cf265..71b06b17a9bd3ee5670010c72a62892dc6f89110 100644 (file)
@@ -152,7 +152,7 @@ int dhcp_network_send_raw_socket(int s, const union sockaddr_union *link,
         assert_se(s >= 0);
         assert_se(packet);
 
-        size = sizeof(DHCPPacket) + 4;
+        size = sizeof(DHCPPacket);
         assert_se(len > size);
 
         discover = memdup(packet, len);
@@ -190,7 +190,7 @@ int dhcp_network_send_raw_socket(int s, const union sockaddr_union *link,
         return 575;
 }
 
-int dhcp_network_bind_raw_socket(int index, union sockaddr_union *link)
+int dhcp_network_bind_raw_socket(int index, union sockaddr_union *link, uint32_t id)
 {
         if (socketpair(AF_UNIX, SOCK_STREAM, 0, test_fd) < 0)
                 return -errno;
@@ -253,8 +253,7 @@ static void test_discover_message(sd_event *e)
         sd_dhcp_client_stop(client);
         sd_dhcp_client_free(client);
 
-        close(test_fd[0]);
-        close(test_fd[1]);
+        test_fd[1] = safe_close(test_fd[1]);
 
         callback_recv = NULL;
 }
@@ -339,7 +338,7 @@ static uint8_t test_addr_acq_ack[] = {
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x63, 0x82, 0x53, 0x63, 0x35, 0x01, 0x05, 0x36,
         0x04, 0xc0, 0xa8, 0x02, 0x01, 0x33, 0x04, 0x00,
-        0x00, 0x02, 0x58, 0x01, 0x04,   0xff, 0xff, 0xff,
+        0x00, 0x02, 0x58, 0x01, 0x04, 0xff, 0xff, 0xff,
         0x00, 0x2a, 0x04, 0xc0, 0xa8, 0x02, 0x01, 0x0f,
         0x09, 0x6c, 0x61, 0x62, 0x2e, 0x69, 0x6e, 0x74,
         0x72, 0x61, 0x03, 0x04, 0xc0, 0xa8, 0x02, 0x01,
@@ -348,8 +347,7 @@ static uint8_t test_addr_acq_ack[] = {
 };
 
 static void test_addr_acq_acquired(sd_dhcp_client *client, int event,
-                                   void *userdata)
-{
+                                   void *userdata) {
         sd_event *e = userdata;
         sd_dhcp_lease *lease;
         struct in_addr addr;
@@ -378,8 +376,7 @@ static void test_addr_acq_acquired(sd_dhcp_client *client, int event,
         sd_event_exit(e, 0);
 }
 
-static int test_addr_acq_recv_request(size_t size, DHCPMessage *request)
-{
+static int test_addr_acq_recv_request(size_t size, DHCPMessage *request) {
         uint16_t udp_check = 0;
         uint8_t *msg_bytes = (uint8_t *)request;
         int res;
@@ -410,8 +407,7 @@ static int test_addr_acq_recv_request(size_t size, DHCPMessage *request)
         return 0;
 };
 
-static int test_addr_acq_recv_discover(size_t size, DHCPMessage *discover)
-{
+static int test_addr_acq_recv_discover(size_t size, DHCPMessage *discover) {
         uint16_t udp_check = 0;
         uint8_t *msg_bytes = (uint8_t *)discover;
         int res;
@@ -438,13 +434,12 @@ static int test_addr_acq_recv_discover(size_t size, DHCPMessage *discover)
         assert_se(res == sizeof(test_addr_acq_offer));
 
         if (verbose)
-                printf("  send DHCP Offer\n");
+                printf("  sent DHCP Offer\n");
 
         return 0;
 }
 
-static void test_addr_acq(sd_event *e)
-{
+static void test_addr_acq(sd_event *e) {
         usec_t time_now = now(CLOCK_MONOTONIC);
         sd_dhcp_client *client;
         int res, r;
@@ -467,9 +462,10 @@ static void test_addr_acq(sd_event *e)
 
         callback_recv = test_addr_acq_recv_discover;
 
-        assert_se(sd_event_add_monotonic(e, &test_hangcheck,
-                                         time_now + 2 * USEC_PER_SEC, 0,
-                                         test_dhcp_hangcheck, NULL) >= 0);
+        assert_se(sd_event_add_time(e, &test_hangcheck,
+                                    CLOCK_MONOTONIC,
+                                    time_now + 2 * USEC_PER_SEC, 0,
+                                    test_dhcp_hangcheck, NULL) >= 0);
 
         res = sd_dhcp_client_start(client);
         assert_se(res == 0 || res == -EINPROGRESS);
@@ -482,15 +478,13 @@ static void test_addr_acq(sd_event *e)
         sd_dhcp_client_stop(client);
         sd_dhcp_client_free(client);
 
-        close(test_fd[0]);
-        close(test_fd[1]);
+        test_fd[1] = safe_close(test_fd[1]);
 
         callback_recv = NULL;
         xid = 0;
 }
 
-int main(int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
         sd_event *e;
 
         assert_se(sd_event_new(&e) >= 0);