]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* |
2 | * Socket union header. | |
3 | * Copyright (c) 1997 Kunihiro Ishiguro | |
4 | * | |
5 | * This file is part of GNU Zebra. | |
6 | * | |
7 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License as published by the | |
9 | * Free Software Foundation; either version 2, or (at your option) any | |
10 | * later version. | |
11 | * | |
12 | * GNU Zebra is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with GNU Zebra; see the file COPYING. If not, write to the Free | |
19 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
20 | * 02111-1307, USA. | |
21 | */ | |
22 | ||
23 | #ifndef _ZEBRA_SOCKUNION_H | |
24 | #define _ZEBRA_SOCKUNION_H | |
25 | ||
ed40466a | 26 | #include "privs.h" |
b892f1dd | 27 | #include "if.h" |
d3e2c74a RW |
28 | #if defined HAVE_MPLS && defined __OpenBSD__ |
29 | #include <netmpls/mpls.h> | |
30 | #endif | |
ed40466a | 31 | |
718e3744 | 32 | union sockunion |
33 | { | |
34 | struct sockaddr sa; | |
35 | struct sockaddr_in sin; | |
718e3744 | 36 | struct sockaddr_in6 sin6; |
d3e2c74a RW |
37 | #if defined HAVE_MPLS && defined __OpenBSD__ |
38 | struct sockaddr_mpls smpls; | |
39 | #endif | |
718e3744 | 40 | }; |
41 | ||
42 | enum connect_result | |
43 | { | |
44 | connect_error, | |
45 | connect_success, | |
46 | connect_in_progress | |
47 | }; | |
48 | ||
49 | /* Default address family. */ | |
50 | #ifdef HAVE_IPV6 | |
51 | #define AF_INET_UNION AF_INET6 | |
52 | #else | |
53 | #define AF_INET_UNION AF_INET | |
54 | #endif | |
55 | ||
56 | /* Sockunion address string length. Same as INET6_ADDRSTRLEN. */ | |
57 | #define SU_ADDRSTRLEN 46 | |
58 | ||
59 | /* Macro to set link local index to the IPv6 address. For KAME IPv6 | |
60 | stack. */ | |
61 | #ifdef KAME | |
62 | #define IN6_LINKLOCAL_IFINDEX(a) ((a).s6_addr[2] << 8 | (a).s6_addr[3]) | |
63 | #define SET_IN6_LINKLOCAL_IFINDEX(a, i) \ | |
64 | do { \ | |
65 | (a).s6_addr[2] = ((i) >> 8) & 0xff; \ | |
66 | (a).s6_addr[3] = (i) & 0xff; \ | |
67 | } while (0) | |
68 | #else | |
69 | #define IN6_LINKLOCAL_IFINDEX(a) | |
70 | #define SET_IN6_LINKLOCAL_IFINDEX(a, i) | |
71 | #endif /* KAME */ | |
72 | ||
718e3744 | 73 | #define sockunion_family(X) (X)->sa.sa_family |
74 | ||
0c5ed3ed JBD |
75 | #define sockunion2ip(X) (X)->sin.sin_addr.s_addr |
76 | ||
718e3744 | 77 | /* Prototypes. */ |
8cc4198f | 78 | extern int str2sockunion (const char *, union sockunion *); |
c0d8db4d TT |
79 | extern const char *sockunion2str (const union sockunion *, char *, size_t); |
80 | extern int sockunion_cmp (const union sockunion *, const union sockunion *); | |
3f9c7369 | 81 | extern int sockunion_same (const union sockunion *, const union sockunion *); |
7cb5cdbb | 82 | extern unsigned int sockunion_hash (const union sockunion *); |
718e3744 | 83 | |
95e0999c TT |
84 | extern size_t family2addrsize(int family); |
85 | extern size_t sockunion_get_addrlen(const union sockunion *); | |
86 | extern const u_char *sockunion_get_addr(const union sockunion *); | |
87 | extern void sockunion_set(union sockunion *, int family, const u_char *addr, size_t bytes); | |
88 | ||
2fb2a455 | 89 | extern union sockunion *sockunion_str2su (const char *str); |
8cc4198f | 90 | extern int sockunion_accept (int sock, union sockunion *); |
91 | extern int sockunion_stream_socket (union sockunion *); | |
92 | extern int sockopt_reuseaddr (int); | |
93 | extern int sockopt_reuseport (int); | |
ca051269 | 94 | extern int sockopt_v6only (int family, int sock); |
8cc4198f | 95 | extern int sockunion_bind (int sock, union sockunion *, |
96 | unsigned short, union sockunion *); | |
97 | extern int sockopt_ttl (int family, int sock, int ttl); | |
fa411a21 | 98 | extern int sockopt_minttl (int family, int sock, int minttl); |
58192df7 | 99 | extern int sockopt_cork (int sock, int onoff); |
ed40466a | 100 | extern int sockopt_mark_default(int sock, int mark, struct zebra_privs_t *); |
c0d8db4d TT |
101 | extern int sockunion_socket (const union sockunion *su); |
102 | extern const char *inet_sutop (const union sockunion *su, char *str); | |
103 | extern enum connect_result sockunion_connect (int fd, const union sockunion *su, | |
8cc4198f | 104 | unsigned short port, |
b892f1dd | 105 | ifindex_t); |
8cc4198f | 106 | extern union sockunion *sockunion_getsockname (int); |
107 | extern union sockunion *sockunion_getpeername (int); | |
c0d8db4d | 108 | extern union sockunion *sockunion_dup (const union sockunion *); |
8cc4198f | 109 | extern void sockunion_free (union sockunion *); |
dd793e4a | 110 | extern void sockunion_init (union sockunion *); |
718e3744 | 111 | |
112 | #ifndef HAVE_INET_NTOP | |
8cc4198f | 113 | extern const char * inet_ntop (int family, const void *addrptr, |
114 | char *strptr, size_t len); | |
718e3744 | 115 | #endif /* HAVE_INET_NTOP */ |
116 | ||
117 | #ifndef HAVE_INET_PTON | |
8cc4198f | 118 | extern int inet_pton (int family, const char *strptr, void *addrptr); |
718e3744 | 119 | #endif /* HAVE_INET_PTON */ |
120 | ||
121 | #ifndef HAVE_INET_ATON | |
8cc4198f | 122 | extern int inet_aton (const char *cp, struct in_addr *inaddr); |
718e3744 | 123 | #endif |
124 | ||
125 | #endif /* _ZEBRA_SOCKUNION_H */ |