seccomp: add cacheflush to whitelist
[qemu/ar7.git] / include / qemu / sockets.h
blob5a183c570d5536f6ee5ac27a500666e06c521644
1 /* headers to use the BSD sockets */
2 #ifndef QEMU_SOCKET_H
3 #define QEMU_SOCKET_H
5 #ifdef _WIN32
6 #include <windows.h>
7 #include <winsock2.h>
8 #include <ws2tcpip.h>
10 #define socket_error() WSAGetLastError()
12 int inet_aton(const char *cp, struct in_addr *ia);
14 #else
16 #include <sys/types.h>
17 #include <sys/socket.h>
18 #include <netinet/in.h>
19 #include <netinet/tcp.h>
20 #include <arpa/inet.h>
21 #include <netdb.h>
22 #include <sys/un.h>
24 #define socket_error() errno
25 #define closesocket(s) close(s)
27 #endif /* !_WIN32 */
29 #include "qemu/option.h"
30 #include "qapi/error.h"
31 #include "qapi-types.h"
33 extern QemuOptsList socket_optslist;
35 /* misc helpers */
36 int qemu_socket(int domain, int type, int protocol);
37 int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
38 int socket_set_cork(int fd, int v);
39 int socket_set_nodelay(int fd);
40 void qemu_set_block(int fd);
41 void qemu_set_nonblock(int fd);
42 int socket_set_fast_reuse(int fd);
43 int send_all(int fd, const void *buf, int len1);
44 int recv_all(int fd, void *buf, int len1, bool single_read);
46 #ifdef WIN32
47 /* Windows has different names for the same constants with the same values */
48 #define SHUT_RD 0
49 #define SHUT_WR 1
50 #define SHUT_RDWR 2
51 #endif
53 /* callback function for nonblocking connect
54 * valid fd on success, negative error code on failure
56 typedef void NonBlockingConnectHandler(int fd, Error *errp, void *opaque);
58 InetSocketAddress *inet_parse(const char *str, Error **errp);
59 int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp);
60 int inet_listen(const char *str, char *ostr, int olen,
61 int socktype, int port_offset, Error **errp);
62 int inet_connect_opts(QemuOpts *opts, Error **errp,
63 NonBlockingConnectHandler *callback, void *opaque);
64 int inet_connect(const char *str, Error **errp);
65 int inet_nonblocking_connect(const char *str,
66 NonBlockingConnectHandler *callback,
67 void *opaque, Error **errp);
69 int inet_dgram_opts(QemuOpts *opts, Error **errp);
70 NetworkAddressFamily inet_netfamily(int family);
72 int unix_listen_opts(QemuOpts *opts, Error **errp);
73 int unix_listen(const char *path, char *ostr, int olen, Error **errp);
74 int unix_connect_opts(QemuOpts *opts, Error **errp,
75 NonBlockingConnectHandler *callback, void *opaque);
76 int unix_connect(const char *path, Error **errp);
77 int unix_nonblocking_connect(const char *str,
78 NonBlockingConnectHandler *callback,
79 void *opaque, Error **errp);
81 SocketAddress *socket_parse(const char *str, Error **errp);
82 int socket_connect(SocketAddress *addr, Error **errp,
83 NonBlockingConnectHandler *callback, void *opaque);
84 int socket_listen(SocketAddress *addr, Error **errp);
85 int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp);
87 /* Old, ipv4 only bits. Don't use for new code. */
88 int parse_host_port(struct sockaddr_in *saddr, const char *str);
89 int socket_init(void);
91 /**
92 * socket_local_address:
93 * @fd: the socket file handle
94 * @errp: pointer to uninitialized error object
96 * Get the string representation of the local socket
97 * address. A pointer to the allocated address information
98 * struct will be returned, which the caller is required to
99 * release with a call qapi_free_SocketAddress when no
100 * longer required.
102 * Returns: the socket address struct, or NULL on error
104 SocketAddress *socket_local_address(int fd, Error **errp);
107 * socket_remote_address:
108 * @fd: the socket file handle
109 * @errp: pointer to uninitialized error object
111 * Get the string representation of the remote socket
112 * address. A pointer to the allocated address information
113 * struct will be returned, which the caller is required to
114 * release with a call qapi_free_SocketAddress when no
115 * longer required.
117 * Returns: the socket address struct, or NULL on error
119 SocketAddress *socket_remote_address(int fd, Error **errp);
122 void qapi_copy_SocketAddress(SocketAddress **p_dest,
123 SocketAddress *src);
125 #endif /* QEMU_SOCKET_H */