1 /* Copyright (c) 2019-2021, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
4 #define PROTO_HAPROXY_PRIVATE
5 #include "lib/malloc/malloc.h"
6 #include "lib/net/address.h"
7 #include "lib/string/printf.h"
8 #include "core/proto/proto_haproxy.h"
10 /** Return a newly allocated PROXY header null-terminated string. Returns NULL
11 * if addr_port->addr is incompatible with the proxy protocol.
14 haproxy_format_proxy_header_line(const tor_addr_port_t
*addr_port
)
16 tor_assert(addr_port
);
18 sa_family_t family
= tor_addr_family(&addr_port
->addr
);
19 const char *family_string
= NULL
;
20 const char *src_addr_string
= NULL
;
24 family_string
= "TCP4";
25 src_addr_string
= "0.0.0.0";
28 family_string
= "TCP6";
29 src_addr_string
= "::";
37 char addrbuf
[TOR_ADDR_BUF_LEN
];
39 tor_addr_to_str(addrbuf
, &addr_port
->addr
, sizeof(addrbuf
), 0);
41 tor_asprintf(&buf
, "PROXY %s %s %s 0 %d\r\n", family_string
, src_addr_string
,
42 addrbuf
, addr_port
->port
);