summaryrefslogtreecommitdiffhomepage
path: root/src/transparent-proxy.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transparent-proxy.c')
-rw-r--r--src/transparent-proxy.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/transparent-proxy.c b/src/transparent-proxy.c
index 2c1e069..d090ae3 100644
--- a/src/transparent-proxy.c
+++ b/src/transparent-proxy.c
@@ -53,17 +53,17 @@ static int build_url (char **url, const char *host, int port, const char *path)
}
int
-do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
+do_transparent_proxy (struct conn_s *connptr, orderedmap hashofheaders,
struct request_s *request, struct config_s *conf,
char **url)
{
socklen_t length;
char *data;
size_t ulen = strlen (*url);
- ssize_t i;
+ size_t i;
- length = hashmap_entry_by_key (hashofheaders, "host", (void **) &data);
- if (length <= 0) {
+ data = orderedmap_find (hashofheaders, "host");
+ if (!data) {
union sockaddr_union dest_addr;
const void *dest_inaddr;
char namebuf[INET6_ADDRSTRLEN+1];
@@ -83,16 +83,14 @@ do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
return 0;
}
- af = length == sizeof(dest_addr.v4) ? AF_INET : AF_INET6;
- if (af == AF_INET) dest_inaddr = &dest_addr.v4.sin_addr;
- else dest_inaddr = &dest_addr.v6.sin6_addr;
+ af = SOCKADDR_UNION_AF(&dest_addr);
+ dest_inaddr = SOCKADDR_UNION_ADDRESS(&dest_addr);
if (!inet_ntop(af, dest_inaddr, namebuf, sizeof namebuf))
goto addr_err;
request->host = safestrdup (namebuf);
- request->port = ntohs (af == AF_INET ? dest_addr.v4.sin_port
- : dest_addr.v6.sin6_port);
+ request->port = ntohs (SOCKADDR_UNION_PORT(&dest_addr));
request->path = (char *) safemalloc (ulen + 1);
strlcpy (request->path, *url, ulen + 1);
@@ -102,6 +100,7 @@ do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
"process_request: trans IP %s %s for %d",
request->method, *url, connptr->client_fd);
} else {
+ length = strlen (data);
request->host = (char *) safemalloc (length + 1);
if (sscanf (data, "%[^:]:%hu", request->host, &request->port) !=
2) {
@@ -122,12 +121,12 @@ do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
return 1;
}
- for (i = 0; i < vector_length(conf->listen_addrs); i++) {
- const char *addr;
+ for (i = 0; i < sblist_getsize(conf->listen_addrs); i++) {
+ char **addr;
- addr = (char *)vector_getentry(conf->listen_addrs, i, NULL);
+ addr = sblist_get(conf->listen_addrs, i);
- if (addr && strcmp(request->host, addr) == 0) {
+ if (addr && *addr && strcmp(request->host, *addr) == 0) {
log_message(LOG_ERR,
"transparent: destination IP %s is local "
"on socket fd %d",