diff options
author | Christian Pointner <equinox@spreadspace.org> | 2010-11-28 23:24:16 +0000 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2010-11-28 23:24:16 +0000 |
commit | 64ef9b77afabde7f0856d908489a5255107606ff (patch) | |
tree | a80035ed6f920e09f1c08762c831bd2479c83aba /src/clients.c | |
parent | replaced inet_ntop with getnameinfo (diff) |
added length field to tcp_endpoint_t
git-svn-id: https://svn.spreadspace.org/tcpproxy/trunk@15 e61f0598-a718-4e21-a8f0-0aadfa62ad6b
Diffstat (limited to 'src/clients.c')
-rw-r--r-- | src/clients.c | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/src/clients.c b/src/clients.c index 6db10fc..7179961 100644 --- a/src/clients.c +++ b/src/clients.c @@ -63,7 +63,7 @@ void clients_clear(clients_t* list) slist_clear(list); } -int clients_add(clients_t* list, int fd, const tcp_endpoint_t* remote_end, const tcp_endpoint_t* source_end) +int clients_add(clients_t* list, int fd, const tcp_endpoint_t remote_end, const tcp_endpoint_t source_end) { if(!list) @@ -79,7 +79,7 @@ int clients_add(clients_t* list, int fd, const tcp_endpoint_t* remote_end, const element->write_buf_len_[1] = 0; element->fd_[0] = fd; - element->fd_[1] = socket(remote_end->ss_family, SOCK_STREAM, 0); + element->fd_[1] = socket(remote_end.addr_.ss_family, SOCK_STREAM, 0); if(element->fd_[1] < 0) { log_printf(INFO, "Error on socket(): %s, not adding client %d", strerror(errno), element->fd_[0]); close(element->fd_[0]); @@ -87,14 +87,8 @@ int clients_add(clients_t* list, int fd, const tcp_endpoint_t* remote_end, const return -1; } - if(source_end->ss_family != AF_UNSPEC) { - socklen_t socklen = sizeof(*source_end); - if(source_end->ss_family == AF_INET) - socklen = sizeof(struct sockaddr_in); - else if (source_end->ss_family == AF_INET6) - socklen = sizeof(struct sockaddr_in6); - - if(bind(element->fd_[1], (struct sockaddr *)source_end, socklen)==-1) { + if(source_end.addr_.ss_family != AF_UNSPEC) { + if(bind(element->fd_[1], (struct sockaddr *)&(source_end.addr_), source_end.len_)==-1) { log_printf(INFO, "Error on bind(): %s, not adding client %d", strerror(errno), element->fd_[0]); close(element->fd_[0]); close(element->fd_[1]); @@ -103,13 +97,7 @@ int clients_add(clients_t* list, int fd, const tcp_endpoint_t* remote_end, const } } - socklen_t socklen = sizeof(*remote_end); - if(remote_end->ss_family == AF_INET) - socklen = sizeof(struct sockaddr_in); - else if (remote_end->ss_family == AF_INET6) - socklen = sizeof(struct sockaddr_in6); - - if(connect(element->fd_[1], (struct sockaddr *)remote_end, socklen)==-1) { + if(connect(element->fd_[1], (struct sockaddr *)&(remote_end.addr_), remote_end.len_)==-1) { log_printf(INFO, "Error on connect(): %s, not adding client %d", strerror(errno), element->fd_[0]); close(element->fd_[0]); close(element->fd_[1]); |