]>
Commit | Line | Data |
---|---|---|
6ca957f0 FB |
1 | /* headers to use the BSD sockets */ |
2 | #ifndef QEMU_SOCKET_H | |
3 | #define QEMU_SOCKET_H | |
4 | ||
5 | #ifdef _WIN32 | |
6ca957f0 FB |
6 | #include <windows.h> |
7 | #include <winsock2.h> | |
8 | #include <ws2tcpip.h> | |
9 | ||
10 | #define socket_error() WSAGetLastError() | |
6ca957f0 | 11 | |
03ff3ca3 AL |
12 | int inet_aton(const char *cp, struct in_addr *ia); |
13 | ||
6ca957f0 FB |
14 | #else |
15 | ||
80bb8cba | 16 | #include <sys/types.h> |
6ca957f0 FB |
17 | #include <sys/socket.h> |
18 | #include <netinet/in.h> | |
19 | #include <netinet/tcp.h> | |
03ff3ca3 AL |
20 | #include <arpa/inet.h> |
21 | #include <netdb.h> | |
ffd843bc | 22 | #include <sys/un.h> |
6ca957f0 FB |
23 | |
24 | #define socket_error() errno | |
25 | #define closesocket(s) close(s) | |
26 | ||
27 | #endif /* !_WIN32 */ | |
28 | ||
1de7afc9 | 29 | #include "qemu/option.h" |
7b1b5d19 | 30 | #include "qapi/error.h" |
a589569f | 31 | #include "qapi-types.h" |
2af2bf67 | 32 | |
e62be888 KW |
33 | extern QemuOptsList socket_optslist; |
34 | ||
d247d25f | 35 | /* misc helpers */ |
40ff6d7e KW |
36 | int qemu_socket(int domain, int type, int protocol); |
37 | int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen); | |
128aa589 | 38 | int socket_set_cork(int fd, int v); |
bf1c852a | 39 | int socket_set_nodelay(int fd); |
f9e8cacc SH |
40 | void qemu_set_block(int fd); |
41 | void qemu_set_nonblock(int fd); | |
606600a1 | 42 | int socket_set_fast_reuse(int fd); |
d247d25f | 43 | int send_all(int fd, const void *buf, int len1); |
4549a8b7 | 44 | int recv_all(int fd, void *buf, int len1, bool single_read); |
d247d25f | 45 | |
e1a8c9b6 DDAG |
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 | |
52 | ||
233aa5c2 OW |
53 | /* callback function for nonblocking connect |
54 | * valid fd on success, negative error code on failure | |
55 | */ | |
51795029 | 56 | typedef void NonBlockingConnectHandler(int fd, Error *errp, void *opaque); |
233aa5c2 | 57 | |
f17c90be | 58 | InetSocketAddress *inet_parse(const char *str, Error **errp); |
029409e5 | 59 | int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp); |
d247d25f | 60 | int inet_listen(const char *str, char *ostr, int olen, |
029409e5 | 61 | int socktype, int port_offset, Error **errp); |
233aa5c2 OW |
62 | int inet_connect_opts(QemuOpts *opts, Error **errp, |
63 | NonBlockingConnectHandler *callback, void *opaque); | |
5db5f44c | 64 | int inet_connect(const char *str, Error **errp); |
233aa5c2 OW |
65 | int inet_nonblocking_connect(const char *str, |
66 | NonBlockingConnectHandler *callback, | |
67 | void *opaque, Error **errp); | |
68 | ||
7fc4e63e | 69 | int inet_dgram_opts(QemuOpts *opts, Error **errp); |
a589569f | 70 | NetworkAddressFamily inet_netfamily(int family); |
d247d25f | 71 | |
7fc4e63e PB |
72 | int unix_listen_opts(QemuOpts *opts, Error **errp); |
73 | int unix_listen(const char *path, char *ostr, int olen, Error **errp); | |
1fc05adf PB |
74 | int unix_connect_opts(QemuOpts *opts, Error **errp, |
75 | NonBlockingConnectHandler *callback, void *opaque); | |
7fc4e63e | 76 | int unix_connect(const char *path, Error **errp); |
1fc05adf PB |
77 | int unix_nonblocking_connect(const char *str, |
78 | NonBlockingConnectHandler *callback, | |
79 | void *opaque, Error **errp); | |
d247d25f | 80 | |
101f9cbc PB |
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); | |
3ecc059d | 85 | int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp); |
101f9cbc | 86 | |
d247d25f | 87 | /* Old, ipv4 only bits. Don't use for new code. */ |
5bb7910a | 88 | int parse_host_port(struct sockaddr_in *saddr, const char *str); |
0706a4dc | 89 | int socket_init(void); |
6ca957f0 FB |
90 | |
91 | #endif /* QEMU_SOCKET_H */ |