1
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
12int 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
28
29#include "qemu/option.h"
30#include "qapi/error.h"
31#include "qapi-types.h"
32
33extern QemuOptsList socket_optslist;
34
35
36int qemu_socket(int domain, int type, int protocol);
37int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
38int socket_set_cork(int fd, int v);
39int socket_set_nodelay(int fd);
40void qemu_set_block(int fd);
41void qemu_set_nonblock(int fd);
42int socket_set_fast_reuse(int fd);
43int send_all(int fd, const void *buf, int len1);
44int recv_all(int fd, void *buf, int len1, bool single_read);
45
46#ifdef WIN32
47
48#define SHUT_RD 0
49#define SHUT_WR 1
50#define SHUT_RDWR 2
51#endif
52
53
54
55
56typedef void NonBlockingConnectHandler(int fd, Error *errp, void *opaque);
57
58InetSocketAddress *inet_parse(const char *str, Error **errp);
59int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp);
60int inet_listen(const char *str, char *ostr, int olen,
61 int socktype, int port_offset, Error **errp);
62int inet_connect_opts(QemuOpts *opts, Error **errp,
63 NonBlockingConnectHandler *callback, void *opaque);
64int inet_connect(const char *str, Error **errp);
65int inet_nonblocking_connect(const char *str,
66 NonBlockingConnectHandler *callback,
67 void *opaque, Error **errp);
68
69int inet_dgram_opts(QemuOpts *opts, Error **errp);
70NetworkAddressFamily inet_netfamily(int family);
71
72int unix_listen_opts(QemuOpts *opts, Error **errp);
73int unix_listen(const char *path, char *ostr, int olen, Error **errp);
74int unix_connect_opts(QemuOpts *opts, Error **errp,
75 NonBlockingConnectHandler *callback, void *opaque);
76int unix_connect(const char *path, Error **errp);
77int unix_nonblocking_connect(const char *str,
78 NonBlockingConnectHandler *callback,
79 void *opaque, Error **errp);
80
81SocketAddress *socket_parse(const char *str, Error **errp);
82int socket_connect(SocketAddress *addr, Error **errp,
83 NonBlockingConnectHandler *callback, void *opaque);
84int socket_listen(SocketAddress *addr, Error **errp);
85int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp);
86
87
88int parse_host_port(struct sockaddr_in *saddr, const char *str);
89int socket_init(void);
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104SocketAddress *socket_local_address(int fd, Error **errp);
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119SocketAddress *socket_remote_address(int fd, Error **errp);
120
121
122void qapi_copy_SocketAddress(SocketAddress **p_dest,
123 SocketAddress *src);
124
125#endif
126