diff options
author | Christian Pointner <equinox@spreadspace.org> | 2010-11-28 22:55:24 +0000 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2010-11-28 22:55:24 +0000 |
commit | 174a9f39da1f09c6ffd9c6f0b3a6a42da5ec4163 (patch) | |
tree | 74bb2be118291b2df2ad7d18d33a6816626a32e6 /src/clients.c | |
parent | first minial version working (diff) |
source address to connect from can now be specified
git-svn-id: https://svn.spreadspace.org/tcpproxy/trunk@13 e61f0598-a718-4e21-a8f0-0aadfa62ad6b
Diffstat (limited to 'src/clients.c')
-rw-r--r-- | src/clients.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/clients.c b/src/clients.c index 9e5c9fc..6db10fc 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) +int clients_add(clients_t* list, int fd, const tcp_endpoint_t* remote_end, const tcp_endpoint_t* source_end) { if(!list) @@ -87,6 +87,22 @@ int clients_add(clients_t* list, int fd, const tcp_endpoint_t* remote_end) 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) { + log_printf(INFO, "Error on bind(): %s, not adding client %d", strerror(errno), element->fd_[0]); + close(element->fd_[0]); + close(element->fd_[1]); + free(element); + return -1; + } + } + socklen_t socklen = sizeof(*remote_end); if(remote_end->ss_family == AF_INET) socklen = sizeof(struct sockaddr_in); |