1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
3 #ifndef foosocketutilhfoo
4 #define foosocketutilhfoo
7 This file is part of systemd.
9 Copyright 2010 Lennart Poettering
11 systemd is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 systemd is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 #include <sys/socket.h>
26 #include <netinet/in.h>
29 #include <asm/types.h>
30 #include <linux/netlink.h>
35 union sockaddr_union {
37 struct sockaddr_in in4;
38 struct sockaddr_in6 in6;
39 struct sockaddr_un un;
40 struct sockaddr_nl nl;
41 struct sockaddr_storage storage;
44 typedef struct SocketAddress {
45 union sockaddr_union sockaddr;
47 /* We store the size here explicitly due to the weird
48 * sockaddr_un semantics for abstract sockets */
51 /* Socket type, i.e. SOCK_STREAM, SOCK_DGRAM, ... */
54 /* Socket protocol, IPPROTO_xxx, usually 0, except for netlink */
58 typedef enum SocketAddressBindIPv6Only {
59 SOCKET_ADDRESS_DEFAULT,
61 SOCKET_ADDRESS_IPV6_ONLY,
62 _SOCKET_ADDRESS_BIND_IPV6_ONLY_MAX,
63 _SOCKET_ADDRESS_BIND_IPV6_ONLY_INVALID = -1
64 } SocketAddressBindIPv6Only;
66 #define socket_address_family(a) ((a)->sockaddr.sa.sa_family)
68 int socket_address_parse(SocketAddress *a, const char *s);
69 int socket_address_parse_netlink(SocketAddress *a, const char *s);
70 int socket_address_print(const SocketAddress *a, char **p);
71 int socket_address_verify(const SocketAddress *a);
73 bool socket_address_can_accept(const SocketAddress *a);
75 int socket_address_listen(
76 const SocketAddress *a,
78 SocketAddressBindIPv6Only only,
79 const char *bind_to_device,
82 mode_t directory_mode,
87 bool socket_address_is(const SocketAddress *a, const char *s, int type);
88 bool socket_address_is_netlink(const SocketAddress *a, const char *s);
90 bool socket_address_equal(const SocketAddress *a, const SocketAddress *b);
92 bool socket_address_needs_mount(const SocketAddress *a, const char *prefix);
94 const char* socket_address_bind_ipv6_only_to_string(SocketAddressBindIPv6Only b);
95 SocketAddressBindIPv6Only socket_address_bind_ipv6_only_from_string(const char *s);
97 const char* netlink_family_to_string(int b);
98 int netlink_family_from_string(const char *s);
100 bool socket_ipv6_is_supported(void);