summaryrefslogtreecommitdiff
path: root/source4/lib/socket
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2007-12-11 22:23:20 +0100
committerStefan Metzmacher <metze@samba.org>2007-12-21 05:49:33 +0100
commit70f1f33af8e6e82506d0ee9ff6cc7e0923a7d0a1 (patch)
tree8003912164545843cab60521541e5f068708a5d8 /source4/lib/socket
parent6f2252dace1629d7b5c5637b103caa28d2c89b07 (diff)
downloadsamba-70f1f33af8e6e82506d0ee9ff6cc7e0923a7d0a1.tar.gz
samba-70f1f33af8e6e82506d0ee9ff6cc7e0923a7d0a1.tar.bz2
samba-70f1f33af8e6e82506d0ee9ff6cc7e0923a7d0a1.zip
r26402: Require a talloc context in libnetif.
(This used to be commit a35e51871bbf1ab33fc316fa59e597b722769c50)
Diffstat (limited to 'source4/lib/socket')
-rw-r--r--source4/lib/socket/interface.c21
-rw-r--r--source4/lib/socket/testsuite.c4
2 files changed, 13 insertions, 12 deletions
diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c
index d21923d972..241fcbff5e 100644
--- a/source4/lib/socket/interface.c
+++ b/source4/lib/socket/interface.c
@@ -63,7 +63,7 @@ static struct interface *iface_find(struct interface *interfaces,
/****************************************************************************
add an interface to the linked list of interfaces
****************************************************************************/
-static void add_interface(struct in_addr ip, struct in_addr nmask, struct interface **interfaces)
+static void add_interface(TALLOC_CTX *mem_ctx, struct in_addr ip, struct in_addr nmask, struct interface **interfaces)
{
struct interface *iface;
struct in_addr bcast;
@@ -73,7 +73,7 @@ static void add_interface(struct in_addr ip, struct in_addr nmask, struct interf
return;
}
- iface = talloc(*interfaces == NULL ? talloc_autofree_context() : *interfaces, struct interface);
+ iface = talloc(*interfaces == NULL ? mem_ctx : *interfaces, struct interface);
if (iface == NULL)
return;
@@ -110,7 +110,8 @@ This handles the following different forms:
4) ip/mask
5) bcast/mask
**/
-static void interpret_interface(const char *token,
+static void interpret_interface(TALLOC_CTX *mem_ctx,
+ const char *token,
struct iface_struct *probed_ifaces,
int total_probed,
struct interface **local_interfaces)
@@ -125,7 +126,7 @@ static void interpret_interface(const char *token,
/* first check if it is an interface name */
for (i=0;i<total_probed;i++) {
if (gen_fnmatch(token, probed_ifaces[i].name) == 0) {
- add_interface(probed_ifaces[i].ip,
+ add_interface(mem_ctx, probed_ifaces[i].ip,
probed_ifaces[i].netmask,
local_interfaces);
added = 1;
@@ -143,7 +144,7 @@ static void interpret_interface(const char *token,
ip.s_addr = interpret_addr2(token).s_addr;
for (i=0;i<total_probed;i++) {
if (ip.s_addr == probed_ifaces[i].ip.s_addr) {
- add_interface(probed_ifaces[i].ip,
+ add_interface(mem_ctx, probed_ifaces[i].ip,
probed_ifaces[i].netmask,
local_interfaces);
return;
@@ -169,7 +170,7 @@ static void interpret_interface(const char *token,
ip.s_addr == MKNETADDR(ip.s_addr, nmask.s_addr)) {
for (i=0;i<total_probed;i++) {
if (same_net(ip, probed_ifaces[i].ip, nmask)) {
- add_interface(probed_ifaces[i].ip, nmask,
+ add_interface(mem_ctx, probed_ifaces[i].ip, nmask,
local_interfaces);
return;
}
@@ -178,14 +179,14 @@ static void interpret_interface(const char *token,
return;
}
- add_interface(ip, nmask, local_interfaces);
+ add_interface(mem_ctx, ip, nmask, local_interfaces);
}
/**
load the list of network interfaces
**/
-void load_interfaces(const char **interfaces, struct interface **local_interfaces)
+void load_interfaces(TALLOC_CTX *mem_ctx, const char **interfaces, struct interface **local_interfaces)
{
const char **ptr = interfaces;
int i;
@@ -208,14 +209,14 @@ void load_interfaces(const char **interfaces, struct interface **local_interface
}
for (i=0;i<total_probed;i++) {
if (ifaces[i].ip.s_addr != loopback_ip.s_addr) {
- add_interface(ifaces[i].ip,
+ add_interface(mem_ctx, ifaces[i].ip,
ifaces[i].netmask, local_interfaces);
}
}
}
while (ptr && *ptr) {
- interpret_interface(*ptr, ifaces, total_probed, local_interfaces);
+ interpret_interface(mem_ctx, *ptr, ifaces, total_probed, local_interfaces);
ptr++;
}
diff --git a/source4/lib/socket/testsuite.c b/source4/lib/socket/testsuite.c
index a99ae078b5..6d4d81a884 100644
--- a/source4/lib/socket/testsuite.c
+++ b/source4/lib/socket/testsuite.c
@@ -42,7 +42,7 @@ static bool test_udp(struct torture_context *tctx)
TALLOC_CTX *mem_ctx = tctx;
struct interface *ifaces;
- load_interfaces(lp_interfaces(tctx->lp_ctx), &ifaces);
+ load_interfaces(tctx, lp_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");
@@ -135,7 +135,7 @@ 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(lp_interfaces(tctx->lp_ctx), &ifaces);
+ load_interfaces(tctx, lp_interfaces(tctx->lp_ctx), &ifaces);
localhost = socket_address_from_strings(sock1, sock1->backend_name,
iface_best_ip(ifaces, "127.0.0.1"), 0);
torture_assert(tctx, localhost, "Localhost not found");