}
struct cli_connect_sock_state {
+ struct sockaddr_storage *addrs;
+ size_t num_addrs;
const char **called_names;
const char **calling_names;
int *called_types;
+ size_t chosen_index;
int fd;
uint16_t port;
};
struct tevent_req *req, *subreq;
struct cli_connect_sock_state *state;
struct sockaddr_storage *addrs;
- unsigned i, num_addrs;
+ size_t i;
NTSTATUS status;
req = tevent_req_create(mem_ctx, &state,
*/
status = resolve_name_list(state, host, name_type,
- &addrs, &num_addrs);
+ &state->addrs, &state->num_addrs);
if (!NT_STATUS_IS_OK(status)) {
tevent_req_nterror(req, status);
return tevent_req_post(req, ev);
}
} else {
- addrs = talloc_array(state, struct sockaddr_storage, 1);
- if (tevent_req_nomem(addrs, req)) {
+ state->addrs = talloc_array(state, struct sockaddr_storage, 1);
+ if (tevent_req_nomem(state->addrs, req)) {
return tevent_req_post(req, ev);
}
- addrs[0] = *pss;
- num_addrs = 1;
+ state->addrs[0] = *pss;
+ state->num_addrs = 1;
}
state->called_names = talloc_array(state, const char *, num_addrs);
if (tevent_req_nomem(state->calling_names, req)) {
return tevent_req_post(req, ev);
}
- for (i=0; i<num_addrs; i++) {
+ for (i=0; i<state->num_addrs; i++) {
state->called_names[i] = host;
state->called_types[i] = name_type;
state->calling_names[i] = myname;
}
subreq = smbsock_any_connect_send(
- state, ev, addrs, state->called_names, state->called_types,
- state->calling_names, NULL, num_addrs, port);
+ state, ev, state->addrs,
+ state->called_names, state->called_types, state->calling_names,
+ NULL, state->num_addrs, port);
if (tevent_req_nomem(subreq, req)) {
return tevent_req_post(req, ev);
}
req, struct cli_connect_sock_state);
NTSTATUS status;
- status = smbsock_any_connect_recv(subreq, &state->fd, NULL,
+ status = smbsock_any_connect_recv(subreq, &state->fd,
+ &state->chosen_index,
&state->port);
TALLOC_FREE(subreq);
if (tevent_req_nterror(req, status)) {
}
static NTSTATUS cli_connect_sock_recv(struct tevent_req *req,
- int *pfd, uint16_t *pport)
+ int *pfd,
+ struct sockaddr_storage *pss,
+ uint16_t *pport)
{
struct cli_connect_sock_state *state = tevent_req_data(
req, struct cli_connect_sock_state);
return status;
}
*pfd = state->fd;
+ *pss = state->addrs[state->chosen_index];
*pport = state->port;
return NT_STATUS_OK;
}