corosync  2.4.4-dirty
totemip.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005-2010 Red Hat, Inc.
3  *
4  * All rights reserved.
5  *
6  * Author: Patrick Caulfield (pcaulfie@redhat.com)
7  *
8  * This software licensed under BSD license, the text of which follows:
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  *
13  * - Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  * - Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  * - Neither the name of the MontaVista Software, Inc. nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32  * THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 /* IPv4/6 abstraction */
36 
37 #ifndef TOTEMIP_H_DEFINED
38 #define TOTEMIP_H_DEFINED
39 
40 #include <sys/types.h>
41 #include <sys/socket.h>
42 #include <netinet/in.h>
43 #include <stdint.h>
44 #include <corosync/list.h>
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 #ifdef SO_NOSIGPIPE
51 #ifndef MSG_NOSIGNAL
52 #define MSG_NOSIGNAL 0
53 #endif
54 void totemip_nosigpipe(int s);
55 #else
56 #define totemip_nosigpipe(s)
57 #endif
58 
59 #define TOTEMIP_ADDRLEN (sizeof(struct in6_addr))
60 
61 /* These are the things that get passed around */
62 #define TOTEM_IP_ADDRESS
63 struct totem_ip_address
64 {
65  unsigned int nodeid;
66  unsigned short family;
67  unsigned char addr[TOTEMIP_ADDRLEN];
68 } __attribute__((packed));
69 
71 {
72  struct totem_ip_address ip_addr;
73  struct totem_ip_address mask_addr;
76  char *name;
77  struct list_head list;
78 };
79 
80 extern int totemip_equal(const struct totem_ip_address *addr1,
81  const struct totem_ip_address *addr2);
82 extern int totemip_compare(const void *a, const void *b);
83 extern int totemip_is_mcast(struct totem_ip_address *addr);
84 extern void totemip_copy(struct totem_ip_address *addr1,
85  const struct totem_ip_address *addr2);
86 extern void totemip_copy_endian_convert(struct totem_ip_address *addr1,
87  const struct totem_ip_address *addr2);
88 int totemip_localhost(int family, struct totem_ip_address *localhost);
89 extern int totemip_localhost_check(const struct totem_ip_address *addr);
90 extern const char *totemip_print(const struct totem_ip_address *addr);
91 extern int totemip_sockaddr_to_totemip_convert(const struct sockaddr_storage *saddr,
92  struct totem_ip_address *ip_addr);
93 extern int totemip_totemip_to_sockaddr_convert(struct totem_ip_address *ip_addr,
94  uint16_t port, struct sockaddr_storage *saddr, int *addrlen);
95 extern int totemip_parse(struct totem_ip_address *totemip, const char *addr,
96  int family);
97 extern int totemip_iface_check(struct totem_ip_address *bindnet,
98  struct totem_ip_address *boundto,
99  int *interface_up,
100  int *interface_num,
101  int mask_high_bit);
102 
103 extern int totemip_getifaddrs(struct list_head *addrs);
104 
105 extern void totemip_freeifaddrs(struct list_head *addrs);
106 
107 /* These two simulate a zero in_addr by clearing the family field */
108 static inline void totemip_zero_set(struct totem_ip_address *addr)
109 {
110  addr->family = 0;
111 }
112 static inline int totemip_zero_check(const struct totem_ip_address *addr)
113 {
114  return (addr->family == 0);
115 }
116 
117 extern size_t totemip_udpip_header_size(int family);
118 
119 #ifdef __cplusplus
120 }
121 #endif
122 
123 #endif
unsigned short family
Definition: coroapi.h:113
#define TOTEMIP_ADDRLEN
Definition: totemip.h:59
int totemip_localhost(int family, struct totem_ip_address *localhost)
Definition: totemip.c:182
void totemip_copy_endian_convert(struct totem_ip_address *addr1, const struct totem_ip_address *addr2)
Definition: totemip.c:101
The totem_ip_address struct.
Definition: coroapi.h:111
const char * totemip_print(const struct totem_ip_address *addr)
Definition: totemip.c:214
unsigned char addr[TOTEMIP_ADDRLEN]
Definition: coroapi.h:114
int totemip_parse(struct totem_ip_address *totemip, const char *addr, int family)
Definition: totemip.c:263
int totemip_compare(const void *a, const void *b)
Definition: totemip.c:130
int totemip_is_mcast(struct totem_ip_address *addr)
Definition: totemip.c:114
void totemip_copy(struct totem_ip_address *addr1, const struct totem_ip_address *addr2)
Definition: totemip.c:95
Definition: list.h:46
#define totemip_nosigpipe(s)
Definition: totemip.h:56
int totemip_iface_check(struct totem_ip_address *bindnet, struct totem_ip_address *boundto, int *interface_up, int *interface_num, int mask_high_bit)
Definition: totemip.c:405
struct totem_ip_if_address __attribute__
unsigned int nodeid
Definition: coroapi.h:112
Linked list API.
size_t totemip_udpip_header_size(int family)
Definition: totemip.c:496
void totemip_freeifaddrs(struct list_head *addrs)
Definition: totemip.c:389
int totemip_localhost_check(const struct totem_ip_address *addr)
Definition: totemip.c:205
int totemip_getifaddrs(struct list_head *addrs)
Definition: totemip.c:321
int totemip_totemip_to_sockaddr_convert(struct totem_ip_address *ip_addr, uint16_t port, struct sockaddr_storage *saddr, int *addrlen)
Definition: totemip.c:222
int totemip_sockaddr_to_totemip_convert(const struct sockaddr_storage *saddr, struct totem_ip_address *ip_addr)
Definition: totemip.c:295
int totemip_equal(const struct totem_ip_address *addr1, const struct totem_ip_address *addr2)
Definition: totemip.c:71