12#include <event/lib/Proxy.h>
19 bool read_ipv4(string_iter& start,
const string_iter end, std::uint32_t& addr)
22 while (p != end && (std::isdigit(*p) ||
'.' == *p)) {
25 if (!(p == end ||
' ' == *p)) {
28 std::string tmp(start, p);
29 int r = inet_pton(AF_INET, tmp.c_str(), &addr);
31 start = (p == end) ? p : p+1;
37 bool read_ipv6(string_iter& start,
const string_iter end, in6_addr & addr)
40 while (p != end && (std::isdigit(*p) ||
':' == *p || (
'a' <= *p &&
'f' >= *p) ||
41 (
'A' <= *p &&
'F' >= *p))) {
44 if (!(p == end ||
' ' == *p)) {
47 std::string tmp(start, p);
48 int r = inet_pton(AF_INET6, tmp.c_str(), &addr);
50 start = (p == end) ? p : p+1;
56 bool read_port(string_iter& start, string_iter end, std::uint16_t& port)
59 bool in_digits =
false;
60 while (p != end && isdigit(*p)) {
67 if (!(p == end ||
' ' == *p)) {
70 const std::string port_str(start, p);
71 if (port_str.length() > 5) {
74 auto port_int = std::atoi(port_str.c_str());
75 if (port_int > 65535) {
79 start = (p == end) ? p : p+1;
83 bool read_proxy_ipv4(
const std::string& addr, ipv4_addr& proxy_header)
87 if (!read_ipv4(p, end, proxy_header.src_addr)) {
90 if (!read_ipv4(p, end, proxy_header.dst_addr)) {
93 if (!read_port(p, end, proxy_header.src_port)) {
96 if (!read_port(p, end, proxy_header.dst_port)) {
102 bool read_proxy_ipv6(
const std::string& addr, ipv6_addr& proxy_header)
104 auto end(addr.end());
105 auto p(addr.begin());
106 if (!read_ipv6(p, end, proxy_header.src_addr)) {
109 if (!read_ipv6(p, end, proxy_header.dst_addr)) {
112 if (!read_port(p, end, proxy_header.src_port)) {
115 if (!read_port(p, end, proxy_header.dst_port)) {
Interface between a user of a stream and the provider of a stream.