diff options
author | Anoop C S <anoopcs@redhat.com> | 2017-08-29 14:34:58 +0530 |
---|---|---|
committer | Andreas Schneider <asn@samba.org> | 2018-05-02 14:23:34 +0200 |
commit | d0b13efcd590722784baaca85bb5c9b0d5ee2d92 (patch) | |
tree | f986a304701e54a8c433352dc48c72bf972ad280 /src | |
parent | e30b080e3188c4498af322c8464569489365d0c3 (diff) | |
download | socket_wrapper-d0b13efcd590722784baaca85bb5c9b0d5ee2d92.tar.gz socket_wrapper-d0b13efcd590722784baaca85bb5c9b0d5ee2d92.tar.xz socket_wrapper-d0b13efcd590722784baaca85bb5c9b0d5ee2d92.zip |
swrap: Use swrap_create_socket within swrap_accept
Replace the current logic of socket creation within swrap_accept
with more cleaner version using swrap_create_socket.
Signed-off-by: Anoop C S <anoopcs@redhat.com>
Reviewed-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/socket_wrapper.c | 40 |
1 files changed, 12 insertions, 28 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c index 65b7585..243a938 100644 --- a/src/socket_wrapper.c +++ b/src/socket_wrapper.c @@ -3094,7 +3094,7 @@ static int swrap_accept(int s, int flags) { struct socket_info *parent_si, *child_si; - struct socket_info_fd *child_fi; + struct socket_info new_si = { 0 }; int fd; int idx; struct swrap_address un_addr = { @@ -3158,21 +3158,7 @@ static int swrap_accept(int s, return ret; } - idx = socket_wrapper_first_free_index(); - if (idx == -1) { - return -1; - } - - child_si = swrap_get_socket_info(idx); - - child_fi = (struct socket_info_fd *)calloc(1, sizeof(struct socket_info_fd)); - if (child_fi == NULL) { - close(fd); - errno = ENOMEM; - return -1; - } - - child_fi->fd = fd; + child_si = &new_si; child_si->family = parent_si->family; child_si->type = parent_si->type; @@ -3198,7 +3184,6 @@ static int swrap_accept(int s, &un_my_addr.sa.s, &un_my_addr.sa_socklen); if (ret == -1) { - free(child_fi); close(fd); return ret; } @@ -3210,7 +3195,6 @@ static int swrap_accept(int s, &in_my_addr.sa.s, &in_my_addr.sa_socklen); if (ret == -1) { - free(child_fi); close(fd); return ret; } @@ -3224,18 +3208,18 @@ static int swrap_accept(int s, }; memcpy(&child_si->myname.sa.ss, &in_my_addr.sa.ss, in_my_addr.sa_socklen); - swrap_inc_refcount(child_si); - first_free = swrap_get_next_free(child_si); - swrap_set_next_free(child_si, 0); - - child_fi->si_index = idx; - - SWRAP_DLIST_ADD(socket_fds, child_fi); + idx = swrap_create_socket(&new_si, fd); + if (idx == -1) { + close (fd); + return -1; + } if (addr != NULL) { - swrap_pcap_dump_packet(child_si, addr, SWRAP_ACCEPT_SEND, NULL, 0); - swrap_pcap_dump_packet(child_si, addr, SWRAP_ACCEPT_RECV, NULL, 0); - swrap_pcap_dump_packet(child_si, addr, SWRAP_ACCEPT_ACK, NULL, 0); + struct socket_info *si = swrap_get_socket_info(idx); + + swrap_pcap_dump_packet(si, addr, SWRAP_ACCEPT_SEND, NULL, 0); + swrap_pcap_dump_packet(si, addr, SWRAP_ACCEPT_RECV, NULL, 0); + swrap_pcap_dump_packet(si, addr, SWRAP_ACCEPT_ACK, NULL, 0); } return fd; |