TODO NOT NEEDED cli_connect_sock_send/recv return sock_storage
authorStefan Metzmacher <metze@samba.org>
Wed, 21 Jun 2017 14:02:20 +0000 (16:02 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 18 Feb 2019 11:47:34 +0000 (12:47 +0100)
source3/libsmb/cliconnect.c

index fcc8e0b67b8a0475ed51b43657e14e42cb543e51..f612dc2d53afa2d7735e6da4f971914bf713ebe3 100644 (file)
@@ -2548,9 +2548,12 @@ fail:
 }
 
 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;
 };
@@ -2570,7 +2573,7 @@ static struct tevent_req *cli_connect_sock_send(
        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,
@@ -2588,18 +2591,18 @@ static struct tevent_req *cli_connect_sock_send(
                 */
 
                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);
@@ -2614,15 +2617,16 @@ static struct tevent_req *cli_connect_sock_send(
        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);
        }
@@ -2638,7 +2642,8 @@ static void cli_connect_sock_done(struct tevent_req *subreq)
                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)) {
@@ -2649,7 +2654,9 @@ static void cli_connect_sock_done(struct tevent_req *subreq)
 }
 
 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);
@@ -2659,6 +2666,7 @@ static NTSTATUS cli_connect_sock_recv(struct tevent_req *req,
                return status;
        }
        *pfd = state->fd;
+       *pss = state->addrs[state->chosen_index];
        *pport = state->port;
        return NT_STATUS_OK;
 }