]>
Commit | Line | Data |
---|---|---|
42f4e3c4 LP |
1 | /*-*- Mode: C; c-basic-offset: 8 -*-*/ |
2 | ||
3 | #ifndef foosocketutilhfoo | |
4 | #define foosocketutilhfoo | |
5 | ||
6 | #include <sys/socket.h> | |
7 | #include <netinet/in.h> | |
8 | #include <sys/un.h> | |
acbb0225 | 9 | #include <net/if.h> |
42f4e3c4 LP |
10 | |
11 | #include "macro.h" | |
12 | #include "util.h" | |
13 | ||
542563ba | 14 | typedef struct SocketAddress { |
42f4e3c4 LP |
15 | union { |
16 | struct sockaddr sa; | |
17 | struct sockaddr_in in4; | |
18 | struct sockaddr_in6 in6; | |
19 | struct sockaddr_un un; | |
20 | struct sockaddr_storage storage; | |
21 | } sockaddr; | |
22 | ||
23 | /* We store the size here explicitly due to the weird | |
24 | * sockaddr_un semantics for abstract sockets */ | |
25 | socklen_t size; | |
26 | ||
27 | /* Socket type, i.e. SOCK_STREAM, SOCK_DGRAM, ... */ | |
28 | int type; | |
542563ba | 29 | } SocketAddress; |
42f4e3c4 | 30 | |
542563ba LP |
31 | typedef enum SocketAddressBindIPv6Only { |
32 | SOCKET_ADDRESS_DEFAULT, | |
33 | SOCKET_ADDRESS_BOTH, | |
34 | SOCKET_ADDRESS_IPV6_ONLY | |
35 | } SocketAddressBindIPv6Only; | |
42f4e3c4 | 36 | |
542563ba | 37 | #define socket_address_family(a) ((a)->sockaddr.sa.sa_family) |
42f4e3c4 | 38 | |
542563ba LP |
39 | int socket_address_parse(SocketAddress *a, const char *s); |
40 | int socket_address_print(const SocketAddress *a, char **p); | |
41 | int socket_address_verify(const SocketAddress *a); | |
acbb0225 | 42 | int socket_address_listen(const SocketAddress *a, int backlog, SocketAddressBindIPv6Only only, const char *bind_to_device, int *ret); |
42f4e3c4 LP |
43 | |
44 | #endif |