1
#pragma once
2

            
3
#include <cstdint>
4
#include <string>
5

            
6
#include "envoy/common/platform.h"
7

            
8
#include "source/common/common/statusor.h"
9

            
10
namespace Envoy {
11
namespace Network {
12

            
13
// Utilities for parsing numeric IP addresses into sockaddr structures.
14
// These helper methods avoid higher-level dependencies and are suitable for
15
// use by multiple components that need low-level parsing without constructing
16
// `Address::Instance` objects.
17
namespace IpAddressParsing {
18

            
19
// Parse an IPv4 address string into a sockaddr_in with the provided port.
20
// Returns a failure status if the address is not a valid numeric IPv4 string.
21
StatusOr<sockaddr_in> parseIPv4(const std::string& ip_address, uint16_t port);
22

            
23
// Parse an IPv6 address string (optionally with a scope id, e.g. ``fe80::1%2``
24
// or ``fe80::1%eth0``) into a sockaddr_in6 with the provided port.
25
//
26
// Uses getaddrinfo() with ``AI_NUMERICHOST|AI_NUMERICSERV`` to avoid DNS lookups
27
// and to support scoped addresses consistently across all platforms.
28
//
29
// Returns a failure status if the address is not a valid numeric IPv6 string.
30
StatusOr<sockaddr_in6> parseIPv6(const std::string& ip_address, uint16_t port);
31

            
32
} // namespace IpAddressParsing
33
} // namespace Network
34
} // namespace Envoy