chiark / gitweb /
add new unit_add_dependency_by_name() call
[elogind.git] / socket-util.h
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>
9 #include <net/if.h>
10
11 #include "macro.h"
12 #include "util.h"
13
14 typedef struct SocketAddress {
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;
29 } SocketAddress;
30
31 typedef enum SocketAddressBindIPv6Only {
32         SOCKET_ADDRESS_DEFAULT,
33         SOCKET_ADDRESS_BOTH,
34         SOCKET_ADDRESS_IPV6_ONLY
35 } SocketAddressBindIPv6Only;
36
37 #define socket_address_family(a) ((a)->sockaddr.sa.sa_family)
38
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);
42 int socket_address_listen(const SocketAddress *a, int backlog, SocketAddressBindIPv6Only only, const char *bind_to_device, int *ret);
43
44 #endif