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
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
23 #ifndef _ZEBRA_SOCKUNION_H
24 #define _ZEBRA_SOCKUNION_H
33 struct sockaddr_in su_sin
;
34 struct sockaddr_in6 su_sin6
;
36 #define su_len su_si.si_len
37 #define su_family su_si.si_family
38 #define su_port su_si.si_port
44 struct sockaddr_in sin
;
46 struct sockaddr_in6 sin6
;
47 #endif /* HAVE_IPV6 */
57 /* Default address family. */
59 #define AF_INET_UNION AF_INET6
61 #define AF_INET_UNION AF_INET
64 /* Sockunion address string length. Same as INET6_ADDRSTRLEN. */
65 #define SU_ADDRSTRLEN 46
67 /* Macro to set link local index to the IPv6 address. For KAME IPv6
70 #define IN6_LINKLOCAL_IFINDEX(a) ((a).s6_addr[2] << 8 | (a).s6_addr[3])
71 #define SET_IN6_LINKLOCAL_IFINDEX(a, i) \
73 (a).s6_addr[2] = ((i) >> 8) & 0xff; \
74 (a).s6_addr[3] = (i) & 0xff; \
77 #define IN6_LINKLOCAL_IFINDEX(a)
78 #define SET_IN6_LINKLOCAL_IFINDEX(a, i)
81 /* shortcut macro to specify address field of struct sockaddr */
82 #define sock2ip(X) (((struct sockaddr_in *)(X))->sin_addr.s_addr)
84 #define sock2ip6(X) (((struct sockaddr_in6 *)(X))->sin6_addr.s6_addr)
85 #endif /* HAVE_IPV6 */
87 #define sockunion_family(X) (X)->sa.sa_family
90 extern int str2sockunion (const char *, union sockunion
*);
91 extern const char *sockunion2str (union sockunion
*, char *, size_t);
92 extern int sockunion_cmp (union sockunion
*, union sockunion
*);
93 extern int sockunion_same (union sockunion
*, union sockunion
*);
95 extern char *sockunion_su2str (union sockunion
*su
);
96 extern union sockunion
*sockunion_str2su (const char *str
);
97 extern struct in_addr
sockunion_get_in_addr (union sockunion
*su
);
98 extern int sockunion_accept (int sock
, union sockunion
*);
99 extern int sockunion_stream_socket (union sockunion
*);
100 extern int sockopt_reuseaddr (int);
101 extern int sockopt_reuseport (int);
102 extern int sockunion_bind (int sock
, union sockunion
*,
103 unsigned short, union sockunion
*);
104 extern int sockopt_ttl (int family
, int sock
, int ttl
);
105 extern int sockunion_socket (union sockunion
*su
);
106 extern const char *inet_sutop (union sockunion
*su
, char *str
);
107 extern enum connect_result
sockunion_connect (int fd
, union sockunion
*su
,
110 extern union sockunion
*sockunion_getsockname (int);
111 extern union sockunion
*sockunion_getpeername (int);
112 extern union sockunion
*sockunion_dup (union sockunion
*);
113 extern void sockunion_free (union sockunion
*);
115 #ifndef HAVE_INET_NTOP
116 extern const char * inet_ntop (int family
, const void *addrptr
,
117 char *strptr
, size_t len
);
118 #endif /* HAVE_INET_NTOP */
120 #ifndef HAVE_INET_PTON
121 extern int inet_pton (int family
, const char *strptr
, void *addrptr
);
122 #endif /* HAVE_INET_PTON */
124 #ifndef HAVE_INET_ATON
125 extern int inet_aton (const char *cp
, struct in_addr
*inaddr
);
128 #endif /* _ZEBRA_SOCKUNION_H */