sockaddr_utils.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_LIB_ADDRESS_UTILS_SOCKADDR_UTILS_H
20 #define GRPC_CORE_LIB_ADDRESS_UTILS_SOCKADDR_UTILS_H
21 
23 
24 #include <stdint.h>
25 
26 #include <string>
27 
28 #include "absl/status/statusor.h"
29 
31 
32 /* Returns true if addr is an IPv4-mapped IPv6 address within the
33  ::ffff:0.0.0.0/96 range, or false otherwise.
34 
35  If addr4_out is non-NULL, the inner IPv4 address will be copied here when
36  returning true. */
38  grpc_resolved_address* addr4_out);
39 
40 /* If addr is an AF_INET address, writes the corresponding ::ffff:0.0.0.0/96
41  address to addr6_out and returns true. Otherwise returns false. */
43  grpc_resolved_address* addr6_out);
44 
45 /* If addr is ::, 0.0.0.0, or ::ffff:0.0.0.0, writes the port number to
46  *port_out (if not NULL) and returns true, otherwise returns false. */
47 int grpc_sockaddr_is_wildcard(const grpc_resolved_address* addr, int* port_out);
48 
49 /* Writes 0.0.0.0:port and [::]:port to separate sockaddrs. */
51  grpc_resolved_address* wild6_out);
52 
53 /* Writes 0.0.0.0:port. */
55 
56 /* Writes [::]:port. */
58 
59 /* Return the IP port number of a sockaddr */
61 
62 /* Set IP port number of a sockaddr */
64 
65 // Converts a sockaddr into a newly-allocated human-readable string.
66 //
67 // Currently, only the AF_INET, AF_INET6, and AF_UNIX families are recognized.
68 // If the normalize flag is enabled, ::ffff:0.0.0.0/96 IPv6 addresses are
69 // displayed as plain IPv4.
72 
73 /* Returns the URI string corresponding to \a addr */
76 
77 /* Returns the URI scheme corresponding to \a addr */
79 
80 int grpc_sockaddr_get_family(const grpc_resolved_address* resolved_addr);
81 
83  const grpc_resolved_address* resolved_addr);
84 
85 // Applies a mask of \a mask_bits to IPv4/IPv6 addresses. Has no effect if the
86 // address type is not IPv4/IPv6.
88  uint32_t mask_bits);
89 
90 // If \a address is IPv4/IPv6, checks if the IP address falls in the CIDR
91 // specified by \a subnet_address and \a mask_bits.
92 // Returns false if \a address is not an IPv4/IPv6 address. The ports (if set)
93 // are ignored for matching purposes. Note that, \a subnet_address should be
94 // normalized, i.e., `grpc_sockaddr_mask_bits` should have been called on it if
95 // necessary.
97  const grpc_resolved_address* subnet_address,
98  uint32_t mask_bits);
99 
100 #endif /* GRPC_CORE_LIB_ADDRESS_UTILS_SOCKADDR_UTILS_H */
grpc_sockaddr_is_v4mapped
int grpc_sockaddr_is_v4mapped(const grpc_resolved_address *addr, grpc_resolved_address *addr4_out)
Definition: sockaddr_utils.cc:81
grpc_sockaddr_get_uri_scheme
const char * grpc_sockaddr_get_uri_scheme(const grpc_resolved_address *addr)
Definition: sockaddr_utils.cc:282
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc_resolved_address
Definition: resolved_address.h:34
resolved_address.h
grpc_sockaddr_mask_bits
void grpc_sockaddr_mask_bits(grpc_resolved_address *address, uint32_t mask_bits)
Definition: sockaddr_utils.cc:363
grpc_sockaddr_get_port
int grpc_sockaddr_get_port(const grpc_resolved_address *addr)
Definition: sockaddr_utils.cc:303
grpc_sockaddr_get_family
int grpc_sockaddr_get_family(const grpc_resolved_address *resolved_addr)
Definition: sockaddr_utils.cc:297
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
grpc_sockaddr_set_port
int grpc_sockaddr_set_port(grpc_resolved_address *addr, int port)
Definition: sockaddr_utils.cc:324
grpc_sockaddr_to_v4mapped
int grpc_sockaddr_to_v4mapped(const grpc_resolved_address *addr, grpc_resolved_address *addr6_out)
Definition: sockaddr_utils.cc:111
grpc_sockaddr_make_wildcards
void grpc_sockaddr_make_wildcards(int port, grpc_resolved_address *wild4_out, grpc_resolved_address *wild6_out)
Definition: sockaddr_utils.cc:166
gtest_json_test_utils.normalize
def normalize(obj)
Definition: bloaty/third_party/googletest/googletest/test/gtest_json_test_utils.py:35
grpc_sockaddr_is_wildcard
int grpc_sockaddr_is_wildcard(const grpc_resolved_address *addr, int *port_out)
Definition: sockaddr_utils.cc:132
grpc_sockaddr_make_wildcard4
void grpc_sockaddr_make_wildcard4(int port, grpc_resolved_address *wild_out)
Definition: sockaddr_utils.cc:172
stdint.h
grpc_sockaddr_to_uri
absl::StatusOr< std::string > grpc_sockaddr_to_uri(const grpc_resolved_address *addr)
Definition: sockaddr_utils.cc:260
tests.unit._exit_scenarios.port
port
Definition: _exit_scenarios.py:179
grpc_sockaddr_match_subnet
bool grpc_sockaddr_match_subnet(const grpc_resolved_address *address, const grpc_resolved_address *subnet_address, uint32_t mask_bits)
Definition: sockaddr_utils.cc:415
GRPC_MUST_USE_RESULT
#define GRPC_MUST_USE_RESULT
Definition: impl/codegen/port_platform.h:584
grpc_sockaddr_get_packed_host
std::string grpc_sockaddr_get_packed_host(const grpc_resolved_address *resolved_addr)
Definition: sockaddr_utils.cc:344
absl::StatusOr< std::string >
grpc_sockaddr_make_wildcard6
void grpc_sockaddr_make_wildcard6(int port, grpc_resolved_address *wild_out)
Definition: sockaddr_utils.cc:183
addr
struct sockaddr_in addr
Definition: libuv/docs/code/tcp-echo-server/main.c:10
grpc_sockaddr_to_string
absl::StatusOr< std::string > grpc_sockaddr_to_string(const grpc_resolved_address *addr, bool normalize) GRPC_MUST_USE_RESULT
Definition: sockaddr_utils.cc:194
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:19