Statistics
| Branch: | Revision:

root / include / qemu / sockets.h @ a5c82852

History | View | Annotate | Download (2.8 kB)

1
/* headers to use the BSD sockets */
2
#ifndef QEMU_SOCKET_H
3
#define QEMU_SOCKET_H
4

    
5
#ifdef _WIN32
6
#include <windows.h>
7
#include <winsock2.h>
8
#include <ws2tcpip.h>
9

    
10
#define socket_error() WSAGetLastError()
11

    
12
int inet_aton(const char *cp, struct in_addr *ia);
13

    
14
#else
15

    
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>
23

    
24
#define socket_error() errno
25
#define closesocket(s) close(s)
26

    
27
#endif /* !_WIN32 */
28

    
29
#include "qemu/option.h"
30
#include "qapi/error.h"
31
#include "qapi/qmp/qerror.h"
32

    
33
extern QemuOptsList socket_optslist;
34

    
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);
45

    
46
/* callback function for nonblocking connect
47
 * valid fd on success, negative error code on failure
48
 */
49
typedef void NonBlockingConnectHandler(int fd, void *opaque);
50

    
51
InetSocketAddress *inet_parse(const char *str, Error **errp);
52
int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp);
53
int inet_listen(const char *str, char *ostr, int olen,
54
                int socktype, int port_offset, Error **errp);
55
int inet_connect_opts(QemuOpts *opts, Error **errp,
56
                      NonBlockingConnectHandler *callback, void *opaque);
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);
61

    
62
int inet_dgram_opts(QemuOpts *opts, Error **errp);
63
const char *inet_strfamily(int family);
64

    
65
int unix_listen_opts(QemuOpts *opts, Error **errp);
66
int unix_listen(const char *path, char *ostr, int olen, Error **errp);
67
int unix_connect_opts(QemuOpts *opts, Error **errp,
68
                      NonBlockingConnectHandler *callback, void *opaque);
69
int unix_connect(const char *path, Error **errp);
70
int unix_nonblocking_connect(const char *str,
71
                             NonBlockingConnectHandler *callback,
72
                             void *opaque, Error **errp);
73

    
74
SocketAddress *socket_parse(const char *str, Error **errp);
75
int socket_connect(SocketAddress *addr, Error **errp,
76
                   NonBlockingConnectHandler *callback, void *opaque);
77
int socket_listen(SocketAddress *addr, Error **errp);
78
int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp);
79

    
80
/* Old, ipv4 only bits.  Don't use for new code. */
81
int parse_host_port(struct sockaddr_in *saddr, const char *str);
82
int socket_init(void);
83

    
84
#endif /* QEMU_SOCKET_H */