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