]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/socket-util.h
main: use a shorter default $PATH if /usr is merged
[thirdparty/systemd.git] / src / socket-util.h
CommitLineData
03467c88 1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
42f4e3c4
LP
2
3#ifndef foosocketutilhfoo
4#define foosocketutilhfoo
5
a7334b09
LP
6/***
7 This file is part of systemd.
8
9 Copyright 2010 Lennart Poettering
10
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.
15
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.
20
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/>.
23***/
24
42f4e3c4
LP
25#include <sys/socket.h>
26#include <netinet/in.h>
27#include <sys/un.h>
acbb0225 28#include <net/if.h>
7a22745a
LP
29#include <asm/types.h>
30#include <linux/netlink.h>
42f4e3c4
LP
31
32#include "macro.h"
33#include "util.h"
34
f6144808
LP
35union sockaddr_union {
36 struct sockaddr sa;
37 struct sockaddr_in in4;
38 struct sockaddr_in6 in6;
39 struct sockaddr_un un;
7a22745a 40 struct sockaddr_nl nl;
f6144808
LP
41 struct sockaddr_storage storage;
42};
43
542563ba 44typedef struct SocketAddress {
f6144808 45 union sockaddr_union sockaddr;
42f4e3c4
LP
46
47 /* We store the size here explicitly due to the weird
48 * sockaddr_un semantics for abstract sockets */
49 socklen_t size;
50
51 /* Socket type, i.e. SOCK_STREAM, SOCK_DGRAM, ... */
52 int type;
7a22745a
LP
53
54 /* Socket protocol, IPPROTO_xxx, usually 0, except for netlink */
55 int protocol;
542563ba 56} SocketAddress;
42f4e3c4 57
542563ba
LP
58typedef enum SocketAddressBindIPv6Only {
59 SOCKET_ADDRESS_DEFAULT,
60 SOCKET_ADDRESS_BOTH,
c0120d99
LP
61 SOCKET_ADDRESS_IPV6_ONLY,
62 _SOCKET_ADDRESS_BIND_IPV6_ONLY_MAX,
63 _SOCKET_ADDRESS_BIND_IPV6_ONLY_INVALID = -1
542563ba 64} SocketAddressBindIPv6Only;
42f4e3c4 65
542563ba 66#define socket_address_family(a) ((a)->sockaddr.sa.sa_family)
42f4e3c4 67
542563ba 68int socket_address_parse(SocketAddress *a, const char *s);
7a22745a 69int socket_address_parse_netlink(SocketAddress *a, const char *s);
542563ba
LP
70int socket_address_print(const SocketAddress *a, char **p);
71int socket_address_verify(const SocketAddress *a);
b5a0699f 72
4f2d528d
LP
73bool socket_address_can_accept(const SocketAddress *a);
74
b5a0699f
LP
75int socket_address_listen(
76 const SocketAddress *a,
77 int backlog,
78 SocketAddressBindIPv6Only only,
79 const char *bind_to_device,
4fd5948e 80 bool free_bind,
6b6d2dee 81 bool transparent,
b5a0699f
LP
82 mode_t directory_mode,
83 mode_t socket_mode,
56cf987f 84 const char *label,
b5a0699f 85 int *ret);
42f4e3c4 86
27ca8d7a 87bool socket_address_is(const SocketAddress *a, const char *s, int type);
7a22745a 88bool socket_address_is_netlink(const SocketAddress *a, const char *s);
a16e1123
LP
89
90bool socket_address_equal(const SocketAddress *a, const SocketAddress *b);
91
6e2ef85b
LP
92bool socket_address_needs_mount(const SocketAddress *a, const char *prefix);
93
c0120d99
LP
94const char* socket_address_bind_ipv6_only_to_string(SocketAddressBindIPv6Only b);
95SocketAddressBindIPv6Only socket_address_bind_ipv6_only_from_string(const char *s);
96
7a22745a
LP
97const char* netlink_family_to_string(int b);
98int netlink_family_from_string(const char *s);
99
5bfcc1c6
FF
100bool socket_ipv6_is_supported(void);
101
42f4e3c4 102#endif