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_PARSE_ADDRESS_H
20 #define GRPC_CORE_LIB_ADDRESS_UTILS_PARSE_ADDRESS_H
21 
22 #include <grpc/support/port_platform.h>
23 
24 #include <stddef.h>
25 
26 #include "absl/strings/string_view.h"
27 
28 #include "src/core/lib/iomgr/resolve_address.h"
29 #include "src/core/lib/uri/uri_parser.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 an
42  * IPv4 host:port pair. Returns true upon success. */
43 bool grpc_parse_ipv4(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  * IPv6 host:port pair. Returns true upon success. */
48 bool grpc_parse_ipv6(const grpc_core::URI& uri,
49                      grpc_resolved_address* resolved_addr);
50 
51 /** Populate \a resolved_addr from \a uri. Returns true upon success. */
52 bool grpc_parse_uri(const grpc_core::URI& uri,
53                     grpc_resolved_address* resolved_addr);
54 
55 /** Parse bare IPv4 or IPv6 "IP:port" strings. */
56 bool grpc_parse_ipv4_hostport(absl::string_view hostport,
57                               grpc_resolved_address* addr, bool log_errors);
58 bool grpc_parse_ipv6_hostport(absl::string_view hostport,
59                               grpc_resolved_address* addr, bool log_errors);
60 
61 /* Converts named or numeric port to a uint16 suitable for use in a sockaddr. */
62 uint16_t grpc_strhtons(const char* port);
63 
64 namespace grpc_core {
65 
66 /** Populate \a resolved_addr to be a unix socket at |path| */
67 grpc_error_handle UnixSockaddrPopulate(absl::string_view path,
68                                        grpc_resolved_address* resolved_addr);
69 
70 /** Populate \a resolved_addr to be a unix socket in the abstract namespace
71  * at |path| */
72 grpc_error_handle UnixAbstractSockaddrPopulate(
73     absl::string_view path, grpc_resolved_address* resolved_addr);
74 
75 }  // namespace grpc_core
76 
77 #endif /* GRPC_CORE_LIB_ADDRESS_UTILS_PARSE_ADDRESS_H */
78