]>
git.proxmox.com Git - mirror_frr.git/blob - lib/sockunion.h
3 * Copyright (c) 1997 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
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
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.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #ifndef _ZEBRA_SOCKUNION_H
23 #define _ZEBRA_SOCKUNION_H
28 #include <netmpls/mpls.h>
33 struct sockaddr_in sin
;
34 struct sockaddr_in6 sin6
;
36 struct sockaddr_mpls smpls
;
37 struct sockaddr_rtlabel rtlabel
;
41 enum connect_result
{ connect_error
, connect_success
, connect_in_progress
};
43 /* Default address family. */
44 #define AF_INET_UNION AF_INET6
46 /* Sockunion address string length. Same as INET6_ADDRSTRLEN. */
47 #define SU_ADDRSTRLEN 46
49 /* Macro to set link local index to the IPv6 address. For KAME IPv6
52 #define IN6_LINKLOCAL_IFINDEX(a) ((a).s6_addr[2] << 8 | (a).s6_addr[3])
53 #define SET_IN6_LINKLOCAL_IFINDEX(a, i) \
55 (a).s6_addr[2] = ((i) >> 8) & 0xff; \
56 (a).s6_addr[3] = (i)&0xff; \
59 #define IN6_LINKLOCAL_IFINDEX(a)
60 #define SET_IN6_LINKLOCAL_IFINDEX(a, i)
63 #define sockunion_family(X) (X)->sa.sa_family
65 #define sockunion2ip(X) (X)->sin.sin_addr.s_addr
68 extern int str2sockunion(const char *, union sockunion
*);
69 extern const char *sockunion2str(const union sockunion
*, char *, size_t);
70 extern int sockunion_cmp(const union sockunion
*, const union sockunion
*);
71 extern int sockunion_same(const union sockunion
*, const union sockunion
*);
72 extern unsigned int sockunion_hash(const union sockunion
*);
74 extern size_t family2addrsize(int family
);
75 extern size_t sockunion_get_addrlen(const union sockunion
*);
76 extern const u_char
*sockunion_get_addr(const union sockunion
*);
77 extern void sockunion_set(union sockunion
*, int family
, const u_char
*addr
,
80 extern union sockunion
*sockunion_str2su(const char *str
);
81 extern int sockunion_accept(int sock
, union sockunion
*);
82 extern int sockunion_stream_socket(union sockunion
*);
83 extern int sockopt_reuseaddr(int);
84 extern int sockopt_reuseport(int);
85 extern int sockopt_v6only(int family
, int sock
);
86 extern int sockunion_bind(int sock
, union sockunion
*, unsigned short,
88 extern int sockopt_ttl(int family
, int sock
, int ttl
);
89 extern int sockopt_minttl(int family
, int sock
, int minttl
);
90 extern int sockopt_cork(int sock
, int onoff
);
91 extern int sockopt_mark_default(int sock
, int mark
, struct zebra_privs_t
*);
92 extern int sockunion_socket(const union sockunion
*su
);
93 extern const char *inet_sutop(const union sockunion
*su
, char *str
);
94 extern enum connect_result
sockunion_connect(int fd
, const union sockunion
*su
,
95 unsigned short port
, ifindex_t
);
96 extern union sockunion
*sockunion_getsockname(int);
97 extern union sockunion
*sockunion_getpeername(int);
98 extern union sockunion
*sockunion_dup(const union sockunion
*);
99 extern void sockunion_free(union sockunion
*);
100 extern void sockunion_init(union sockunion
*);
102 #endif /* _ZEBRA_SOCKUNION_H */