]> git.proxmox.com Git - mirror_frr.git/blame - lib/sockunion.h
sockopt: add support for querying tcp round-trip-time
[mirror_frr.git] / lib / sockunion.h
CommitLineData
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
DS
26#include "privs.h"
27
718e3744 28union sockunion
29{
30 struct sockaddr sa;
31 struct sockaddr_in sin;
718e3744 32 struct sockaddr_in6 sin6;
718e3744 33};
34
35enum connect_result
36{
37 connect_error,
38 connect_success,
39 connect_in_progress
40};
41
42/* Default address family. */
43#ifdef HAVE_IPV6
44#define AF_INET_UNION AF_INET6
45#else
46#define AF_INET_UNION AF_INET
47#endif
48
49/* Sockunion address string length. Same as INET6_ADDRSTRLEN. */
50#define SU_ADDRSTRLEN 46
51
52/* Macro to set link local index to the IPv6 address. For KAME IPv6
53 stack. */
54#ifdef KAME
55#define IN6_LINKLOCAL_IFINDEX(a) ((a).s6_addr[2] << 8 | (a).s6_addr[3])
56#define SET_IN6_LINKLOCAL_IFINDEX(a, i) \
57 do { \
58 (a).s6_addr[2] = ((i) >> 8) & 0xff; \
59 (a).s6_addr[3] = (i) & 0xff; \
60 } while (0)
61#else
62#define IN6_LINKLOCAL_IFINDEX(a)
63#define SET_IN6_LINKLOCAL_IFINDEX(a, i)
64#endif /* KAME */
65
718e3744 66#define sockunion_family(X) (X)->sa.sa_family
67
0c5ed3ed
JBD
68#define sockunion2ip(X) (X)->sin.sin_addr.s_addr
69
718e3744 70/* Prototypes. */
8cc4198f 71extern int str2sockunion (const char *, union sockunion *);
72extern const char *sockunion2str (union sockunion *, char *, size_t);
73extern int sockunion_cmp (union sockunion *, union sockunion *);
3f9c7369 74extern int sockunion_same (const union sockunion *, const union sockunion *);
7cb5cdbb 75extern unsigned int sockunion_hash (const union sockunion *);
718e3744 76
2fb2a455 77extern union sockunion *sockunion_str2su (const char *str);
8cc4198f 78extern int sockunion_accept (int sock, union sockunion *);
79extern int sockunion_stream_socket (union sockunion *);
80extern int sockopt_reuseaddr (int);
81extern int sockopt_reuseport (int);
ca051269 82extern int sockopt_v6only (int family, int sock);
8cc4198f 83extern int sockunion_bind (int sock, union sockunion *,
84 unsigned short, union sockunion *);
85extern int sockopt_ttl (int family, int sock, int ttl);
fa411a21 86extern int sockopt_minttl (int family, int sock, int minttl);
58192df7 87extern int sockopt_cork (int sock, int onoff);
ed40466a 88extern int sockopt_mark_default(int sock, int mark, struct zebra_privs_t *);
8cc4198f 89extern int sockunion_socket (union sockunion *su);
90extern const char *inet_sutop (union sockunion *su, char *str);
91extern enum connect_result sockunion_connect (int fd, union sockunion *su,
92 unsigned short port,
93 unsigned int);
94extern union sockunion *sockunion_getsockname (int);
95extern union sockunion *sockunion_getpeername (int);
96extern union sockunion *sockunion_dup (union sockunion *);
97extern void sockunion_free (union sockunion *);
dd793e4a 98extern void sockunion_init (union sockunion *);
718e3744 99
100#ifndef HAVE_INET_NTOP
8cc4198f 101extern const char * inet_ntop (int family, const void *addrptr,
102 char *strptr, size_t len);
718e3744 103#endif /* HAVE_INET_NTOP */
104
105#ifndef HAVE_INET_PTON
8cc4198f 106extern int inet_pton (int family, const char *strptr, void *addrptr);
718e3744 107#endif /* HAVE_INET_PTON */
108
109#ifndef HAVE_INET_ATON
8cc4198f 110extern int inet_aton (const char *cp, struct in_addr *inaddr);
718e3744 111#endif
112
113#endif /* _ZEBRA_SOCKUNION_H */