sockets: remove use of QemuOpts from header file
[qemu/ar7.git] / include / qemu / sockets.h
blob7286f162db8fae74d10d28ec95b521239825a90d
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 /* misc helpers */
34 int qemu_socket(int domain, int type, int protocol);
35 int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
36 int socket_set_cork(int fd, int v);
37 int socket_set_nodelay(int fd);
38 void qemu_set_block(int fd);
39 void qemu_set_nonblock(int fd);
40 int socket_set_fast_reuse(int fd);
42 #ifdef WIN32
43 /* Windows has different names for the same constants with the same values */
44 #define SHUT_RD 0
45 #define SHUT_WR 1
46 #define SHUT_RDWR 2
47 #endif
49 /* callback function for nonblocking connect
50 * valid fd on success, negative error code on failure
52 typedef void NonBlockingConnectHandler(int fd, Error *err, void *opaque);
54 InetSocketAddress *inet_parse(const char *str, Error **errp);
55 int inet_listen(const char *str, char *ostr, int olen,
56 int socktype, int port_offset, Error **errp);
57 int inet_connect(const char *str, Error **errp);
58 int inet_nonblocking_connect(const char *str,
59 NonBlockingConnectHandler *callback,
60 void *opaque, Error **errp);
62 NetworkAddressFamily inet_netfamily(int family);
64 int unix_listen(const char *path, char *ostr, int olen, Error **errp);
65 int unix_connect(const char *path, Error **errp);
66 int unix_nonblocking_connect(const char *str,
67 NonBlockingConnectHandler *callback,
68 void *opaque, Error **errp);
70 SocketAddress *socket_parse(const char *str, Error **errp);
71 int socket_connect(SocketAddress *addr, Error **errp,
72 NonBlockingConnectHandler *callback, void *opaque);
73 int socket_listen(SocketAddress *addr, Error **errp);
74 int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp);
76 /* Old, ipv4 only bits. Don't use for new code. */
77 int parse_host_port(struct sockaddr_in *saddr, const char *str);
78 int socket_init(void);
80 /**
81 * socket_sockaddr_to_address:
82 * @sa: socket address struct
83 * @salen: size of @sa struct
84 * @errp: pointer to uninitialized error object
86 * Get the string representation of the socket
87 * address. A pointer to the allocated address information
88 * struct will be returned, which the caller is required to
89 * release with a call qapi_free_SocketAddress when no
90 * longer required.
92 * Returns: the socket address struct, or NULL on error
94 SocketAddress *
95 socket_sockaddr_to_address(struct sockaddr_storage *sa,
96 socklen_t salen,
97 Error **errp);
99 /**
100 * socket_local_address:
101 * @fd: the socket file handle
102 * @errp: pointer to uninitialized error object
104 * Get the string representation of the local socket
105 * address. A pointer to the allocated address information
106 * struct will be returned, which the caller is required to
107 * release with a call qapi_free_SocketAddress when no
108 * longer required.
110 * Returns: the socket address struct, or NULL on error
112 SocketAddress *socket_local_address(int fd, Error **errp);
115 * socket_remote_address:
116 * @fd: the socket file handle
117 * @errp: pointer to uninitialized error object
119 * Get the string representation of the remote socket
120 * address. A pointer to the allocated address information
121 * struct will be returned, which the caller is required to
122 * release with a call qapi_free_SocketAddress when no
123 * longer required.
125 * Returns: the socket address struct, or NULL on error
127 SocketAddress *socket_remote_address(int fd, Error **errp);
130 void qapi_copy_SocketAddress(SocketAddress **p_dest,
131 SocketAddress *src);
133 #endif /* QEMU_SOCKET_H */