summaryrefslogtreecommitdiff
path: root/source4/lib/socket
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2010-03-10 16:04:44 +1100
committerAndrew Bartlett <abartlet@samba.org>2010-03-11 11:27:47 +1100
commit79b4a3b22e8a70844b9654f057f6169c553cc809 (patch)
treef05f99d5aafe6335644bf6ec5a207815822056d4 /source4/lib/socket
parent9457b7ea2214aaa3a466e5dbc2daa0b931975073 (diff)
downloadsamba-79b4a3b22e8a70844b9654f057f6169c553cc809.tar.gz
samba-79b4a3b22e8a70844b9654f057f6169c553cc809.tar.bz2
samba-79b4a3b22e8a70844b9654f057f6169c553cc809.zip
s4:lib/socket Don't go via a string when resolving addresses in connect_multi
This also removes the special case for IP addresses, and leaves that to the code in the resolver library. Andrew Bartlett
Diffstat (limited to 'source4/lib/socket')
-rw-r--r--source4/lib/socket/connect_multi.c48
1 files changed, 20 insertions, 28 deletions
diff --git a/source4/lib/socket/connect_multi.c b/source4/lib/socket/connect_multi.c
index 68386ba565..300e5fb1e5 100644
--- a/source4/lib/socket/connect_multi.c
+++ b/source4/lib/socket/connect_multi.c
@@ -33,7 +33,7 @@
overall state
*/
struct connect_multi_state {
- const char *server_address;
+ struct socket_address *server_address;
int num_ports;
uint16_t *ports;
@@ -64,7 +64,7 @@ static void continue_one(struct composite_context *creq);
*/
_PUBLIC_ struct composite_context *socket_connect_multi_send(
TALLOC_CTX *mem_ctx,
- const char *server_address,
+ const char *server_name,
int num_server_ports,
uint16_t *server_ports,
struct resolve_context *resolve_ctx,
@@ -74,6 +74,9 @@ _PUBLIC_ struct composite_context *socket_connect_multi_send(
struct connect_multi_state *multi;
int i;
+ struct nbt_name name;
+ struct composite_context *creq;
+
result = talloc_zero(mem_ctx, struct composite_context);
if (result == NULL) return NULL;
result->state = COMPOSITE_STATE_IN_PROGRESS;
@@ -83,9 +86,6 @@ _PUBLIC_ struct composite_context *socket_connect_multi_send(
if (composite_nomem(multi, result)) goto failed;
result->private_data = multi;
- multi->server_address = talloc_strdup(multi, server_address);
- if (composite_nomem(multi->server_address, result)) goto failed;
-
multi->num_ports = num_server_ports;
multi->ports = talloc_array(multi, uint16_t, multi->num_ports);
if (composite_nomem(multi->ports, result)) goto failed;
@@ -94,30 +94,21 @@ _PUBLIC_ struct composite_context *socket_connect_multi_send(
multi->ports[i] = server_ports[i];
}
- if (!is_ipaddress(server_address)) {
- /*
- we don't want to do the name resolution separately
+ /*
+ we don't want to do the name resolution separately
for each port, so start it now, then only start on
the real sockets once we have an IP
- */
- struct nbt_name name;
- struct composite_context *creq;
- make_nbt_name_server(&name, server_address);
- creq = resolve_name_send(resolve_ctx, multi, &name, result->event_ctx);
- if (composite_nomem(creq, result)) goto failed;
- composite_continue(result, creq, continue_resolve_name, result);
- return result;
- }
+ */
+ make_nbt_name_server(&name, server_name);
- /* now we've setup the state we can process the first socket */
- connect_multi_next_socket(result);
+ creq = resolve_name_all_send(resolve_ctx, multi, 0, multi->ports[0], &name, result->event_ctx);
+ if (composite_nomem(creq, result)) goto failed;
- if (!NT_STATUS_IS_OK(result->status)) {
- goto failed;
- }
+ composite_continue(result, creq, continue_resolve_name, result);
return result;
+
failed:
composite_error(result, result->status);
return result;
@@ -148,11 +139,11 @@ static void connect_multi_next_socket(struct composite_context *result)
result->status = socket_create("ipv4", SOCKET_TYPE_STREAM, &state->sock, 0);
if (!composite_is_ok(result)) return;
- /* Form up the particular address we are interested in */
- state->addr = socket_address_from_strings(state, state->sock->backend_name,
- multi->server_address, multi->ports[next]);
+ state->addr = socket_address_copy(state, multi->server_address);
if (composite_nomem(state->addr, result)) return;
+ socket_address_set_port(state->addr, multi->ports[next]);
+
talloc_steal(state, state->sock);
creq = socket_connect_send(state->sock, NULL,
@@ -197,12 +188,13 @@ static void continue_resolve_name(struct composite_context *creq)
struct composite_context);
struct connect_multi_state *multi = talloc_get_type(result->private_data,
struct connect_multi_state);
- const char *addr;
+ struct socket_address **addr;
- result->status = resolve_name_recv(creq, multi, &addr);
+ result->status = resolve_name_all_recv(creq, multi, &addr, NULL);
if (!composite_is_ok(result)) return;
- multi->server_address = addr;
+ /* Let's just go for the first for now */
+ multi->server_address = addr[0];
connect_multi_next_socket(result);
}