All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
as_lookup.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2016 Aerospike, Inc.
3  *
4  * Portions may be licensed to Aerospike, Inc. under one or more contributor
5  * license agreements.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
8  * use this file except in compliance with the License. You may obtain a copy of
9  * the License at 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, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14  * License for the specific language governing permissions and limitations under
15  * the License.
16  */
17 #pragma once
18 
19 #include <aerospike/as_cluster.h>
20 #include <netdb.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /******************************************************************************
27  * TYPES
28  ******************************************************************************/
29 
30 /**
31  * @private
32  * Iterator for IP addresses.
33  */
34 typedef struct as_sockaddr_iterator_s {
35  struct addrinfo* addresses;
36  struct addrinfo* current;
37  in_port_t port_be;
40 
41 /******************************************************************************
42  * FUNCTIONS
43  ******************************************************************************/
44 
45 /**
46  * @private
47  * Lookup hostname and initialize address iterator.
48  */
50 as_lookup_host(as_address_iterator* iter, as_error* err, const char* hostname, in_port_t port);
51 
52 /**
53  * @private
54  * Get next socket address with assigned port. Return false when there are no more addresses.
55  */
56 static inline bool
57 as_lookup_next(as_address_iterator* iter, struct sockaddr** addr)
58 {
59  if (! iter->current) {
60  return false;
61  }
62 
63  struct sockaddr* sa = iter->current->ai_addr;
64  iter->current = iter->current->ai_next;
65 
66  if (sa->sa_family == AF_INET) {
67  ((struct sockaddr_in*)sa)->sin_port = iter->port_be;
68  }
69  else {
70  ((struct sockaddr_in6*)sa)->sin6_port = iter->port_be;
71  }
72  *addr = sa;
73  return true;
74 }
75 
76 /**
77  * @private
78  * Release memory associated with address iterator.
79  */
80 static inline void
82 {
83  freeaddrinfo(iter->addresses);
84 }
85 
86 /**
87  * @private
88  * Lookup and validate node.
89  */
91 as_lookup_node(as_cluster* cluster, as_error* err, const char* tls_name, struct sockaddr* addr, as_node_info* node_info);
92 
93 #ifdef __cplusplus
94 } // end extern "C"
95 #endif
static bool as_lookup_next(as_address_iterator *iter, struct sockaddr **addr)
Definition: as_lookup.h:57
as_status
Definition: as_status.h:30
in_port_t port_be
Definition: as_lookup.h:37
as_status as_lookup_node(as_cluster *cluster, as_error *err, const char *tls_name, struct sockaddr *addr, as_node_info *node_info)
struct addrinfo * current
Definition: as_lookup.h:36
struct addrinfo * addresses
Definition: as_lookup.h:35
static void as_lookup_end(as_address_iterator *iter)
Definition: as_lookup.h:81
as_status as_lookup_host(as_address_iterator *iter, as_error *err, const char *hostname, in_port_t port)