From 542f717bf9a01c5a84e357f23a17fd403be4b237 Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Tue, 25 Apr 2023 08:16:19 +0200 Subject: [PATCH] - adjust generic proxy-protocol header for IPv6 support with ifdef. --- util/proxy_protocol.c | 11 ++++++++++- util/proxy_protocol.h | 7 ++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/util/proxy_protocol.c b/util/proxy_protocol.c index fd253372f..03db06037 100644 --- a/util/proxy_protocol.c +++ b/util/proxy_protocol.c @@ -83,7 +83,12 @@ pp_lookup_error(enum pp_parse_errors error) { } size_t -pp2_write_to_buf(uint8_t* buf, size_t buflen, struct sockaddr_storage* src, +pp2_write_to_buf(uint8_t* buf, size_t buflen, +#ifdef INET6 + struct sockaddr_storage* src, +#else + struct sockaddr_in* src, +#endif int stream) { int af; @@ -123,6 +128,7 @@ pp2_write_to_buf(uint8_t* buf, size_t buflen, struct sockaddr_storage* src, /* dst port */ (*pp_data.write_uint16)(buf, 12); } else { +#ifdef INET6 /* family and protocol */ *buf = (PP2_AF_INET6<<4) | (stream?PP2_PROT_STREAM:PP2_PROT_DGRAM); @@ -142,6 +148,9 @@ pp2_write_to_buf(uint8_t* buf, size_t buflen, struct sockaddr_storage* src, buf += 2; /* dst port */ (*pp_data.write_uint16)(buf, 0); +#else + return 0; +#endif /* INET6 */ } return expected_size; } diff --git a/util/proxy_protocol.h b/util/proxy_protocol.h index f4867ad6c..58d3f8d57 100644 --- a/util/proxy_protocol.h +++ b/util/proxy_protocol.h @@ -144,7 +144,12 @@ const char* pp_lookup_error(enum pp_parse_errors error); * @return 1 on success, 0 on failure. */ size_t pp2_write_to_buf(uint8_t* buf, size_t buflen, - struct sockaddr_storage* src, int stream); +#ifdef INET6 + struct sockaddr_storage* src, +#else + struct sockaddr_in* src, +#endif + int stream); /** * Read a PROXYv2 header from the current position of the buffer. -- 2.47.3