s4-loadparm: 2nd half of lp_ to lpcfg_ conversion
[bbaumbach/samba-autobuild/.git] / source4 / lib / socket / testsuite.c
index e2f9896b332a79b59f6c2ef9e075176095b31ff6..0195064a800158aff6aec35dd0e05f79c122b1d0 100644 (file)
@@ -7,7 +7,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -16,8 +16,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
 #include "system/network.h"
 #include "lib/socket/netif.h"
 #include "torture/torture.h"
+#include "param/param.h"
+#include "libcli/resolve/resolve.h"
 
-/*
+/**
   basic testing of udp routines
 */
 static bool test_udp(struct torture_context *tctx)
@@ -39,6 +40,9 @@ static bool test_udp(struct torture_context *tctx)
        DATA_BLOB blob, blob2;
        size_t sent, nread;
        TALLOC_CTX *mem_ctx = tctx;
+       struct interface *ifaces;
+
+       load_interfaces(tctx, lpcfg_interfaces(tctx->lp_ctx), &ifaces);
 
        status = socket_create("ip", SOCKET_TYPE_DGRAM, &sock1, 0);
        torture_assert_ntstatus_ok(tctx, status, "creating DGRAM IP socket 1");
@@ -49,7 +53,7 @@ static bool test_udp(struct torture_context *tctx)
        talloc_steal(mem_ctx, sock2);
 
        localhost = socket_address_from_strings(sock1, sock1->backend_name, 
-                                               iface_best_ip("127.0.0.1"), 0);
+                                               iface_best_ip(ifaces, "127.0.0.1"), 0);
 
        torture_assert(tctx, localhost, "Localhost not found");
 
@@ -57,10 +61,11 @@ static bool test_udp(struct torture_context *tctx)
        torture_assert_ntstatus_ok(tctx, status, "listen on socket 1");
 
        srv_addr = socket_get_my_addr(sock1, mem_ctx);
-       torture_assert(tctx, srv_addr != NULL && strcmp(srv_addr->addr, iface_best_ip("127.0.0.1")) == 0,
+       torture_assert(tctx, srv_addr != NULL && 
+                      strcmp(srv_addr->addr, iface_best_ip(ifaces, "127.0.0.1")) == 0,
                                   talloc_asprintf(tctx, 
                "Expected server address of %s but got %s",
-                     iface_best_ip("127.0.0.1"), srv_addr ? srv_addr->addr : NULL));
+                     iface_best_ip(ifaces, "127.0.0.1"), srv_addr ? srv_addr->addr : NULL));
 
        torture_comment(tctx, "server port is %d\n", srv_addr->port);
 
@@ -81,7 +86,7 @@ static bool test_udp(struct torture_context *tctx)
 
        torture_assert_int_equal(tctx, nread, size, "Unexpected recvfrom size");
 
-       torture_assert(tctx, memcmp(blob2.data, blob.data, size) == 0,
+       torture_assert_mem_equal(tctx, blob2.data, blob.data, size,
                "Bad data in recvfrom");
 
        generate_random_buffer(blob.data, blob.length);
@@ -99,7 +104,7 @@ static bool test_udp(struct torture_context *tctx)
        torture_assert_int_equal(tctx, from_addr->port, srv_addr->port, 
                                   "Unexpected recvfrom port");
 
-       torture_assert(tctx, memcmp(blob2.data, blob.data, size) == 0, 
+       torture_assert_mem_equal(tctx, blob2.data, blob.data, size,
                "Bad data in recvfrom");
 
        talloc_free(sock1);
@@ -119,7 +124,8 @@ static bool test_tcp(struct torture_context *tctx)
        DATA_BLOB blob, blob2;
        size_t sent, nread;
        TALLOC_CTX *mem_ctx = tctx;
-       struct event_context *ev = event_context_init(mem_ctx);
+       struct tevent_context *ev = tctx->ev;
+       struct interface *ifaces;
 
        status = socket_create("ip", SOCKET_TYPE_STREAM, &sock1, 0);
        torture_assert_ntstatus_ok(tctx, status, "creating IP stream socket 1");
@@ -129,8 +135,9 @@ static bool test_tcp(struct torture_context *tctx)
        torture_assert_ntstatus_ok(tctx, status, "creating IP stream socket 1");
        talloc_steal(mem_ctx, sock2);
 
+       load_interfaces(tctx, lpcfg_interfaces(tctx->lp_ctx), &ifaces);
        localhost = socket_address_from_strings(sock1, sock1->backend_name, 
-                                               iface_best_ip("127.0.0.1"), 0);
+                                               iface_best_ip(ifaces, "127.0.0.1"), 0);
        torture_assert(tctx, localhost, "Localhost not found");
 
        status = socket_listen(sock1, localhost, 0, 0);
@@ -140,7 +147,7 @@ static bool test_tcp(struct torture_context *tctx)
        torture_assert(tctx, srv_addr && srv_addr->addr, 
                                   "Unexpected socket_get_my_addr NULL\n");
 
-       torture_assert_str_equal(tctx, srv_addr->addr, iface_best_ip("127.0.0.1"), 
+       torture_assert_str_equal(tctx, srv_addr->addr, iface_best_ip(ifaces, "127.0.0.1"), 
                        "Unexpected server address");
 
        torture_comment(tctx, "server port is %d\n", srv_addr->port);
@@ -174,7 +181,7 @@ static bool test_tcp(struct torture_context *tctx)
 
        torture_assert_int_equal(tctx, nread, size, "Unexpected recvfrom size");
 
-       torture_assert(tctx, memcmp(blob2.data, blob.data, size) == 0
+       torture_assert_mem_equal(tctx, blob2.data, blob.data, size
                                   "Bad data in recv");
        return true;
 }