]>
Commit | Line | Data |
---|---|---|
42f4e3c4 LP |
1 | /*-*- Mode: C; c-basic-offset: 8 -*-*/ |
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 | ||
542563ba | 33 | typedef struct SocketAddress { |
42f4e3c4 LP |
34 | union { |
35 | struct sockaddr sa; | |
36 | struct sockaddr_in in4; | |
37 | struct sockaddr_in6 in6; | |
38 | struct sockaddr_un un; | |
39 | struct sockaddr_storage storage; | |
40 | } sockaddr; | |
41 | ||
42 | /* We store the size here explicitly due to the weird | |
43 | * sockaddr_un semantics for abstract sockets */ | |
44 | socklen_t size; | |
45 | ||
46 | /* Socket type, i.e. SOCK_STREAM, SOCK_DGRAM, ... */ | |
47 | int type; | |
542563ba | 48 | } SocketAddress; |
42f4e3c4 | 49 | |
542563ba LP |
50 | typedef enum SocketAddressBindIPv6Only { |
51 | SOCKET_ADDRESS_DEFAULT, | |
52 | SOCKET_ADDRESS_BOTH, | |
53 | SOCKET_ADDRESS_IPV6_ONLY | |
54 | } SocketAddressBindIPv6Only; | |
42f4e3c4 | 55 | |
542563ba | 56 | #define socket_address_family(a) ((a)->sockaddr.sa.sa_family) |
42f4e3c4 | 57 | |
542563ba LP |
58 | int socket_address_parse(SocketAddress *a, const char *s); |
59 | int socket_address_print(const SocketAddress *a, char **p); | |
60 | int socket_address_verify(const SocketAddress *a); | |
b5a0699f | 61 | |
4f2d528d LP |
62 | bool socket_address_can_accept(const SocketAddress *a); |
63 | ||
b5a0699f LP |
64 | int socket_address_listen( |
65 | const SocketAddress *a, | |
66 | int backlog, | |
67 | SocketAddressBindIPv6Only only, | |
68 | const char *bind_to_device, | |
69 | mode_t directory_mode, | |
70 | mode_t socket_mode, | |
71 | int *ret); | |
42f4e3c4 LP |
72 | |
73 | #endif |