Proxy.h
1
2//
3// Copyright (c) 2025, Isode Limited, London, England.
4// All rights reserved.
5//
6// Acquisition and use of this software and related materials for any
7// purpose requires a written licence agreement from Isode
8// Limited, or a written licence from an organisation licenced by Isode
9// Limited to grant such a licence.
10//
11#pragma once
12
13#if defined(_WIN32)
14#include <ws2tcpip.h>
15#else
16#include <arpa/inet.h>
17#endif
18
19#include <cstdint>
20#include <cstddef>
21#include <cstring>
22#include <string>
23
24namespace Stream {
25 // Type for a function (or closure) reading some data
26 using ReadFunction = size_t (*)(char *, size_t);
27
28 struct ipv4_addr{ /* for TCP/UDP over IPv4, len = 12 */
29 std::uint32_t src_addr;
30 std::uint32_t dst_addr;
31 std::uint16_t src_port;
32 std::uint16_t dst_port;
33 };
34 struct ipv6_addr { /* for TCP/UDP over IPv6, len = 36 */
35 in6_addr src_addr;
36 in6_addr dst_addr;
37 std::uint16_t src_port;
38 std::uint16_t dst_port;
39 };
40 bool read_proxy_ipv4(const std::string& addr, ipv4_addr &proxy_header);
41 bool read_proxy_ipv6(const std::string& addr, ipv6_addr &proxy_header);
42
43 struct proxy_hdr_v2 {
44 std::uint8_t sig[12]; /* hex 0D 0A 0D 0A 00 0D 0A 51 55 49 54 0A */
45 std::uint8_t ver_cmd; /* protocol version and command */
46 std::uint8_t fam; /* protocol family and address */
47 std::uint16_t len; /* number of following bytes part of the header */
48 };
49
50 using string_iter = std::string::const_iterator;
51 bool read_ipv4(string_iter& start, const string_iter end, std::uint32_t& addr);
52 bool read_ipv6(string_iter& start, const string_iter end, in6_addr & addr);
53 bool read_port(string_iter& start, const string_iter end, std::uint16_t& port);
54
55 const char v2sig[13] = "\x0D\x0A\x0D\x0A\x00\x0D\x0A\x51\x55\x49\x54\x0A";
56}
Interface between a user of a stream and the provider of a stream.

All rights reserved © 2002 - 2024 Isode Ltd.