]>
Commit | Line | Data |
---|---|---|
6ca957f0 | 1 | /* headers to use the BSD sockets */ |
121d0712 MA |
2 | |
3 | #ifndef QEMU_SOCKETS_H | |
4 | #define QEMU_SOCKETS_H | |
6ca957f0 FB |
5 | |
6 | #ifdef _WIN32 | |
6ca957f0 | 7 | |
03ff3ca3 AL |
8 | int inet_aton(const char *cp, struct in_addr *ia); |
9 | ||
6ca957f0 FB |
10 | #endif /* !_WIN32 */ |
11 | ||
a589569f | 12 | #include "qapi-types.h" |
2af2bf67 | 13 | |
d247d25f | 14 | /* misc helpers */ |
40ff6d7e KW |
15 | int qemu_socket(int domain, int type, int protocol); |
16 | int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen); | |
128aa589 | 17 | int socket_set_cork(int fd, int v); |
bf1c852a | 18 | int socket_set_nodelay(int fd); |
f9e8cacc SH |
19 | void qemu_set_block(int fd); |
20 | void qemu_set_nonblock(int fd); | |
606600a1 | 21 | int socket_set_fast_reuse(int fd); |
d247d25f | 22 | |
e1a8c9b6 DDAG |
23 | #ifdef WIN32 |
24 | /* Windows has different names for the same constants with the same values */ | |
25 | #define SHUT_RD 0 | |
26 | #define SHUT_WR 1 | |
27 | #define SHUT_RDWR 2 | |
28 | #endif | |
29 | ||
233aa5c2 OW |
30 | /* callback function for nonblocking connect |
31 | * valid fd on success, negative error code on failure | |
32 | */ | |
533fdaed | 33 | typedef void NonBlockingConnectHandler(int fd, Error *err, void *opaque); |
233aa5c2 | 34 | |
c1b412f1 DB |
35 | int inet_ai_family_from_address(InetSocketAddress *addr, |
36 | Error **errp); | |
0785bd7a | 37 | int inet_parse(InetSocketAddress *addr, const char *str, Error **errp); |
5db5f44c | 38 | int inet_connect(const char *str, Error **errp); |
6dffc1f6 FZ |
39 | int inet_connect_saddr(InetSocketAddress *saddr, |
40 | NonBlockingConnectHandler *callback, void *opaque, | |
41 | Error **errp); | |
233aa5c2 | 42 | |
a589569f | 43 | NetworkAddressFamily inet_netfamily(int family); |
d247d25f | 44 | |
7fc4e63e | 45 | int unix_listen(const char *path, char *ostr, int olen, Error **errp); |
7fc4e63e | 46 | int unix_connect(const char *path, Error **errp); |
d247d25f | 47 | |
bd269ebc MA |
48 | SocketAddress *socket_parse(const char *str, Error **errp); |
49 | int socket_connect(SocketAddress *addr, NonBlockingConnectHandler *callback, | |
226799ce | 50 | void *opaque, Error **errp); |
bd269ebc | 51 | int socket_listen(SocketAddress *addr, Error **errp); |
74b6ce43 | 52 | void socket_listen_cleanup(int fd, Error **errp); |
bd269ebc | 53 | int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp); |
101f9cbc | 54 | |
d247d25f | 55 | /* Old, ipv4 only bits. Don't use for new code. */ |
5bb7910a | 56 | int parse_host_port(struct sockaddr_in *saddr, const char *str); |
0706a4dc | 57 | int socket_init(void); |
6ca957f0 | 58 | |
559607ea DB |
59 | /** |
60 | * socket_sockaddr_to_address: | |
61 | * @sa: socket address struct | |
62 | * @salen: size of @sa struct | |
63 | * @errp: pointer to uninitialized error object | |
64 | * | |
65 | * Get the string representation of the socket | |
66 | * address. A pointer to the allocated address information | |
67 | * struct will be returned, which the caller is required to | |
bd269ebc | 68 | * release with a call qapi_free_SocketAddress() when no |
559607ea DB |
69 | * longer required. |
70 | * | |
71 | * Returns: the socket address struct, or NULL on error | |
72 | */ | |
bd269ebc | 73 | SocketAddress * |
559607ea DB |
74 | socket_sockaddr_to_address(struct sockaddr_storage *sa, |
75 | socklen_t salen, | |
76 | Error **errp); | |
77 | ||
17c55dec DB |
78 | /** |
79 | * socket_local_address: | |
80 | * @fd: the socket file handle | |
81 | * @errp: pointer to uninitialized error object | |
82 | * | |
83 | * Get the string representation of the local socket | |
84 | * address. A pointer to the allocated address information | |
85 | * struct will be returned, which the caller is required to | |
bd269ebc | 86 | * release with a call qapi_free_SocketAddress() when no |
17c55dec DB |
87 | * longer required. |
88 | * | |
89 | * Returns: the socket address struct, or NULL on error | |
90 | */ | |
bd269ebc | 91 | SocketAddress *socket_local_address(int fd, Error **errp); |
17c55dec DB |
92 | |
93 | /** | |
94 | * socket_remote_address: | |
95 | * @fd: the socket file handle | |
96 | * @errp: pointer to uninitialized error object | |
97 | * | |
98 | * Get the string representation of the remote socket | |
99 | * address. A pointer to the allocated address information | |
100 | * struct will be returned, which the caller is required to | |
bd269ebc | 101 | * release with a call qapi_free_SocketAddress() when no |
17c55dec DB |
102 | * longer required. |
103 | * | |
104 | * Returns: the socket address struct, or NULL on error | |
105 | */ | |
bd269ebc | 106 | SocketAddress *socket_remote_address(int fd, Error **errp); |
17c55dec | 107 | |
bd269ebc MA |
108 | /** |
109 | * socket_address_flatten: | |
110 | * @addr: the socket address to flatten | |
111 | * | |
112 | * Convert SocketAddressLegacy to SocketAddress. Caller is responsible | |
113 | * for freeing with qapi_free_SocketAddress(). | |
114 | * | |
115 | * Returns: the argument converted to SocketAddress. | |
116 | */ | |
117 | SocketAddress *socket_address_flatten(SocketAddressLegacy *addr); | |
118 | ||
121d0712 | 119 | #endif /* QEMU_SOCKETS_H */ |