• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SRC_CORE_LIB_ADDRESS_UTILS_PARSE_ADDRESS_H
20 #define GRPC_SRC_CORE_LIB_ADDRESS_UTILS_PARSE_ADDRESS_H
21 
22 #include <grpc/support/port_platform.h>
23 #include <stdint.h>
24 
25 #include "absl/status/statusor.h"
26 #include "absl/strings/string_view.h"
27 #include "src/core/lib/iomgr/error.h"
28 #include "src/core/lib/iomgr/resolved_address.h"
29 #include "src/core/util/uri.h"
30 
31 /// Populate \a resolved_addr from \a uri, whose path is expected to contain a
32 /// unix socket path. Returns true upon success.
33 bool grpc_parse_unix(const grpc_core::URI& uri,
34                      grpc_resolved_address* resolved_addr);
35 
36 /// Populate \a resolved_addr from \a uri, whose path is expected to contain a
37 /// unix socket path in the abstract namespace. Returns true upon success.
38 bool grpc_parse_unix_abstract(const grpc_core::URI& uri,
39                               grpc_resolved_address* resolved_addr);
40 
41 /// Populate \a resolved_addr from \a uri, whose path is expected to contain a
42 /// vsock cid:port pair. Returns true upon success.
43 bool grpc_parse_vsock(const grpc_core::URI& uri,
44                       grpc_resolved_address* resolved_addr);
45 
46 /// Populate \a resolved_addr from \a uri, whose path is expected to contain an
47 /// IPv4 host:port pair. Returns true upon success.
48 bool grpc_parse_ipv4(const grpc_core::URI& uri,
49                      grpc_resolved_address* resolved_addr);
50 
51 /// Populate \a resolved_addr from \a uri, whose path is expected to contain an
52 /// IPv6 host:port pair. Returns true upon success.
53 bool grpc_parse_ipv6(const grpc_core::URI& uri,
54                      grpc_resolved_address* resolved_addr);
55 
56 /// Populate \a resolved_addr from \a uri. Returns true upon success.
57 bool grpc_parse_uri(const grpc_core::URI& uri,
58                     grpc_resolved_address* resolved_addr);
59 
60 /// Parse bare IPv4 or IPv6 "IP:port" strings.
61 bool grpc_parse_ipv4_hostport(absl::string_view hostport,
62                               grpc_resolved_address* addr, bool log_errors);
63 bool grpc_parse_ipv6_hostport(absl::string_view hostport,
64                               grpc_resolved_address* addr, bool log_errors);
65 
66 // Converts named or numeric port to a uint16 suitable for use in a sockaddr.
67 uint16_t grpc_strhtons(const char* port);
68 
69 namespace grpc_core {
70 
71 // Parses an IPv4 or IPv6 address string and returns a sockaddr with the
72 // specified address and port.
73 absl::StatusOr<grpc_resolved_address> StringToSockaddr(
74     absl::string_view address_and_port);
75 absl::StatusOr<grpc_resolved_address> StringToSockaddr(
76     absl::string_view address, int port);
77 
78 /// Populate \a resolved_addr to be a unix socket at |path|
79 grpc_error_handle UnixSockaddrPopulate(absl::string_view path,
80                                        grpc_resolved_address* resolved_addr);
81 
82 /// Populate \a resolved_addr to be a unix socket in the abstract namespace
83 /// at |path|
84 grpc_error_handle UnixAbstractSockaddrPopulate(
85     absl::string_view path, grpc_resolved_address* resolved_addr);
86 
87 /// Populate \a resolved_addr to be a vsock at \a path
88 grpc_error_handle VSockaddrPopulate(absl::string_view path,
89                                     grpc_resolved_address* resolved_addr);
90 }  // namespace grpc_core
91 
92 #endif  // GRPC_SRC_CORE_LIB_ADDRESS_UTILS_PARSE_ADDRESS_H
93