Reverse proxy IPv6 and IPv4

This commit is contained in:
2021-09-12 19:25:57 +02:00
parent 52ea670d36
commit 433cc7861f
2 changed files with 9 additions and 6 deletions

View File

@ -1,5 +1,5 @@
CFLAGS=-std=c11 -Wall CFLAGS=-std=gnu11 -Wall
INCLUDE=-lssl -lcrypto -lmagic -lz -lmaxminddb -lbrotlienc INCLUDE=-lssl -lcrypto -lmagic -lz -lmaxminddb -lbrotlienc
LIBS=src/lib/*.c LIBS=src/lib/*.c

View File

@ -192,13 +192,16 @@ int rev_proxy_init(http_req *req, http_res *res, host_config *conf, sock *client
goto proxy_err; goto proxy_err;
} }
struct hostent *host_ent = gethostbyname(conf->rev_proxy.hostname); struct hostent *host_ent = gethostbyname2(conf->rev_proxy.hostname, AF_INET6);
if (host_ent == NULL) {
host_ent = gethostbyname2(conf->rev_proxy.hostname, AF_INET);
if (host_ent == NULL) { if (host_ent == NULL) {
res->status = http_get_status(503); res->status = http_get_status(503);
print(ERR_STR "Unable to connect to server: Name or service not known" CLR_STR); print(ERR_STR "Unable to connect to server: Name or service not known" CLR_STR);
sprintf(err_msg, "Unable to connect to server: Name or service not known."); sprintf(err_msg, "Unable to connect to server: Name or service not known.");
goto proxy_err; goto proxy_err;
} }
}
struct sockaddr_in6 address = {.sin6_family = AF_INET6, .sin6_port = htons(conf->rev_proxy.port)}; struct sockaddr_in6 address = {.sin6_family = AF_INET6, .sin6_port = htons(conf->rev_proxy.port)};
if (host_ent->h_addrtype == AF_INET6) { if (host_ent->h_addrtype == AF_INET6) {