]>
Commit | Line | Data |
---|---|---|
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> |
42f4e3c4 LP |
29 | |
30 | #include "macro.h" | |
31 | #include "util.h" | |
32 | ||
f6144808 LP |
33 | union sockaddr_union { |
34 | struct sockaddr sa; | |
35 | struct sockaddr_in in4; | |
36 | struct sockaddr_in6 in6; | |
37 | struct sockaddr_un un; | |
38 | struct sockaddr_storage storage; | |
39 | }; | |
40 | ||
542563ba | 41 | typedef struct SocketAddress { |
f6144808 | 42 | union sockaddr_union sockaddr; |
42f4e3c4 LP |
43 | |
44 | /* We store the size here explicitly due to the weird | |
45 | * sockaddr_un semantics for abstract sockets */ | |
46 | socklen_t size; | |
47 | ||
48 | /* Socket type, i.e. SOCK_STREAM, SOCK_DGRAM, ... */ | |
49 | int type; | |
542563ba | 50 | } SocketAddress; |
42f4e3c4 | 51 | |
542563ba LP |
52 | typedef enum SocketAddressBindIPv6Only { |
53 | SOCKET_ADDRESS_DEFAULT, | |
54 | SOCKET_ADDRESS_BOTH, | |
c0120d99 LP |
55 | SOCKET_ADDRESS_IPV6_ONLY, |
56 | _SOCKET_ADDRESS_BIND_IPV6_ONLY_MAX, | |
57 | _SOCKET_ADDRESS_BIND_IPV6_ONLY_INVALID = -1 | |
542563ba | 58 | } SocketAddressBindIPv6Only; |
42f4e3c4 | 59 | |
542563ba | 60 | #define socket_address_family(a) ((a)->sockaddr.sa.sa_family) |
42f4e3c4 | 61 | |
542563ba LP |
62 | int socket_address_parse(SocketAddress *a, const char *s); |
63 | int socket_address_print(const SocketAddress *a, char **p); | |
64 | int socket_address_verify(const SocketAddress *a); | |
b5a0699f | 65 | |
4f2d528d LP |
66 | bool socket_address_can_accept(const SocketAddress *a); |
67 | ||
b5a0699f LP |
68 | int socket_address_listen( |
69 | const SocketAddress *a, | |
70 | int backlog, | |
71 | SocketAddressBindIPv6Only only, | |
72 | const char *bind_to_device, | |
4fd5948e | 73 | bool free_bind, |
b5a0699f LP |
74 | mode_t directory_mode, |
75 | mode_t socket_mode, | |
56cf987f | 76 | const char *label, |
b5a0699f | 77 | int *ret); |
42f4e3c4 | 78 | |
27ca8d7a | 79 | bool socket_address_is(const SocketAddress *a, const char *s, int type); |
a16e1123 LP |
80 | |
81 | bool socket_address_equal(const SocketAddress *a, const SocketAddress *b); | |
82 | ||
6e2ef85b LP |
83 | bool socket_address_needs_mount(const SocketAddress *a, const char *prefix); |
84 | ||
c0120d99 LP |
85 | const char* socket_address_bind_ipv6_only_to_string(SocketAddressBindIPv6Only b); |
86 | SocketAddressBindIPv6Only socket_address_bind_ipv6_only_from_string(const char *s); | |
87 | ||
42f4e3c4 | 88 | #endif |