chiark / gitweb /
importd: create a loopback btrfs file system for /var/lib/machines, if necessary
[elogind.git] / src / libsystemd-network / test-dhcp-client.c
index a3d69f338c2b28b22ba4e8f0502c815d3b2b4f20..d341210887c43f6d7e99cbef26e4cca392a5a95a 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <stdlib.h>
-#include <assert.h>
 #include <errno.h>
 #include <stdio.h>
-#include <sys/types.h>
 #include <sys/socket.h>
 #include <unistd.h>
 
 #include "util.h"
-#include "socket-util.h"
 #include "sd-event.h"
 #include "event-util.h"
 
@@ -218,7 +214,13 @@ int dhcp_network_bind_raw_socket(int index, union sockaddr_union *link,
 
 int dhcp_network_bind_udp_socket(be32_t address, uint16_t port)
 {
-        return 0;
+        int fd;
+
+        fd = socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC, 0);
+        if (fd < 0)
+                return -errno;
+
+        return fd;
 }
 
 int dhcp_network_send_udp_socket(int s, be32_t address, uint16_t port,
@@ -474,8 +476,7 @@ static void test_addr_acq(sd_event *e) {
         assert_se(sd_dhcp_client_set_index(client, 42) >= 0);
         assert_se(sd_dhcp_client_set_mac(client, mac_addr, ETH_ALEN, ARPHRD_ETHER) >= 0);
 
-        assert_se(sd_dhcp_client_set_callback(client, test_addr_acq_acquired, e)
-                >= 0);
+        assert_se(sd_dhcp_client_set_callback(client, test_addr_acq_acquired, e) >= 0);
 
         callback_recv = test_addr_acq_recv_discover;
 
@@ -516,5 +517,12 @@ int main(int argc, char *argv[]) {
         test_discover_message(e);
         test_addr_acq(e);
 
+#ifdef VALGRIND
+        /* Make sure the async_close thread has finished.
+         * valgrind would report some of the phread_* structures
+         * as not cleaned up properly. */
+        sleep(1);
+#endif
+
         return 0;
 }