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_GPR_HOST_PORT_H 20 #define GRPC_CORE_LIB_GPR_HOST_PORT_H 21 22 #include <grpc/support/port_platform.h> 23 24 /** Given a host and port, creates a newly-allocated string of the form 25 "host:port" or "[ho:st]:port", depending on whether the host contains colons 26 like an IPv6 literal. If the host is already bracketed, then additional 27 brackets will not be added. 28 29 Usage is similar to gpr_asprintf: returns the number of bytes written 30 (excluding the final '\0'), and *out points to a string which must later be 31 destroyed using gpr_free(). 32 33 In the unlikely event of an error, returns -1 and sets *out to NULL. */ 34 int gpr_join_host_port(char** out, const char* host, int port); 35 36 /** Given a name in the form "host:port" or "[ho:st]:port", split into hostname 37 and port number, into newly allocated strings, which must later be 38 destroyed using gpr_free(). 39 Return 1 on success, 0 on failure. Guarantees *host and *port == NULL on 40 failure. */ 41 int gpr_split_host_port(const char* name, char** host, char** port); 42 43 #endif /* GRPC_CORE_LIB_GPR_HOST_PORT_H */ 44