]> git.proxmox.com Git - mirror_qemu.git/blame - include/qemu/sockets.h
Merge tag 'pull-target-arm-20231127' of https://git.linaro.org/people/pmaydell/qemu...
[mirror_qemu.git] / include / qemu / sockets.h
CommitLineData
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
8int inet_aton(const char *cp, struct in_addr *ia);
9
6ca957f0
FB
10#endif /* !_WIN32 */
11
9af23989 12#include "qapi/qapi-types-sockets.h"
2af2bf67 13
d247d25f 14/* misc helpers */
58dc31f1 15bool fd_is_socket(int fd);
40ff6d7e 16int qemu_socket(int domain, int type, int protocol);
3c63b4e9 17
3c63b4e9
GT
18/**
19 * qemu_socketpair:
20 * @domain: specifies a communication domain, such as PF_UNIX
21 * @type: specifies the socket type.
22 * @protocol: specifies a particular protocol to be used with the socket
23 * @sv: an array to store the pair of socket created
24 *
25 * Creates an unnamed pair of connected sockets in the specified domain,
26 * of the specified type, and using the optionally specified protocol.
27 * And automatically set the close-on-exec flags on the returned sockets
28 *
29 * Return 0 on success.
30 */
31int qemu_socketpair(int domain, int type, int protocol, int sv[2]);
3c63b4e9 32
40ff6d7e 33int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
84c662d2
XC
34/*
35 * A variant of send(2) which handles partial send.
36 *
37 * Return the number of bytes transferred over the socket.
38 * Set errno if fewer than `count' bytes are sent.
39 *
40 * This function don't work with non-blocking socket's.
41 * Any of the possibilities with non-blocking socket's is bad:
42 * - return a short write (then name is wrong)
43 * - busy wait adding (errno == EAGAIN) to the loop
44 */
45ssize_t qemu_send_full(int s, const void *buf, size_t count)
46 G_GNUC_WARN_UNUSED_RESULT;
128aa589 47int socket_set_cork(int fd, int v);
bf1c852a 48int socket_set_nodelay(int fd);
ff5927ba
MAL
49void qemu_socket_set_block(int fd);
50int qemu_socket_try_set_nonblock(int fd);
51void qemu_socket_set_nonblock(int fd);
606600a1 52int socket_set_fast_reuse(int fd);
d247d25f 53
e1a8c9b6
DDAG
54#ifdef WIN32
55/* Windows has different names for the same constants with the same values */
56#define SHUT_RD 0
57#define SHUT_WR 1
58#define SHUT_RDWR 2
59#endif
60
c1b412f1
DB
61int inet_ai_family_from_address(InetSocketAddress *addr,
62 Error **errp);
0785bd7a 63int inet_parse(InetSocketAddress *addr, const char *str, Error **errp);
5db5f44c 64int inet_connect(const char *str, Error **errp);
b2587932 65int inet_connect_saddr(InetSocketAddress *saddr, Error **errp);
233aa5c2 66
a589569f 67NetworkAddressFamily inet_netfamily(int family);
d247d25f 68
62473511 69int unix_listen(const char *path, Error **errp);
7fc4e63e 70int unix_connect(const char *path, Error **errp);
d247d25f 71
18bf1c94 72char *socket_uri(SocketAddress *addr);
bd269ebc 73SocketAddress *socket_parse(const char *str, Error **errp);
b2587932 74int socket_connect(SocketAddress *addr, Error **errp);
e5b6353c 75int socket_listen(SocketAddress *addr, int num, Error **errp);
74b6ce43 76void socket_listen_cleanup(int fd, Error **errp);
bd269ebc 77int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp);
101f9cbc 78
d247d25f 79/* Old, ipv4 only bits. Don't use for new code. */
30e4226b
LV
80int convert_host_port(struct sockaddr_in *saddr, const char *host,
81 const char *port, Error **errp);
bcd4dfd6
MZ
82int parse_host_port(struct sockaddr_in *saddr, const char *str,
83 Error **errp);
0706a4dc 84int socket_init(void);
6ca957f0 85
559607ea
DB
86/**
87 * socket_sockaddr_to_address:
88 * @sa: socket address struct
89 * @salen: size of @sa struct
90 * @errp: pointer to uninitialized error object
91 *
92 * Get the string representation of the socket
93 * address. A pointer to the allocated address information
94 * struct will be returned, which the caller is required to
bd269ebc 95 * release with a call qapi_free_SocketAddress() when no
559607ea
DB
96 * longer required.
97 *
98 * Returns: the socket address struct, or NULL on error
99 */
bd269ebc 100SocketAddress *
559607ea
DB
101socket_sockaddr_to_address(struct sockaddr_storage *sa,
102 socklen_t salen,
103 Error **errp);
104
17c55dec
DB
105/**
106 * socket_local_address:
107 * @fd: the socket file handle
108 * @errp: pointer to uninitialized error object
109 *
110 * Get the string representation of the local socket
111 * address. A pointer to the allocated address information
112 * struct will be returned, which the caller is required to
bd269ebc 113 * release with a call qapi_free_SocketAddress() when no
17c55dec
DB
114 * longer required.
115 *
116 * Returns: the socket address struct, or NULL on error
117 */
bd269ebc 118SocketAddress *socket_local_address(int fd, Error **errp);
17c55dec
DB
119
120/**
121 * socket_remote_address:
122 * @fd: the socket file handle
123 * @errp: pointer to uninitialized error object
124 *
125 * Get the string representation of the remote socket
126 * address. A pointer to the allocated address information
127 * struct will be returned, which the caller is required to
bd269ebc 128 * release with a call qapi_free_SocketAddress() when no
17c55dec
DB
129 * longer required.
130 *
131 * Returns: the socket address struct, or NULL on error
132 */
bd269ebc 133SocketAddress *socket_remote_address(int fd, Error **errp);
17c55dec 134
bd269ebc
MA
135/**
136 * socket_address_flatten:
137 * @addr: the socket address to flatten
138 *
139 * Convert SocketAddressLegacy to SocketAddress. Caller is responsible
140 * for freeing with qapi_free_SocketAddress().
141 *
142 * Returns: the argument converted to SocketAddress.
143 */
144SocketAddress *socket_address_flatten(SocketAddressLegacy *addr);
145
c5423704
VSO
146/**
147 * socket_address_parse_named_fd:
148 *
149 * Modify @addr, replacing a named fd by its corresponding number.
150 * Needed for callers that plan to pass @addr to a context where the
151 * current monitor is not available.
152 *
153 * Return 0 on success.
154 */
155int socket_address_parse_named_fd(SocketAddress *addr, Error **errp);
121d0712 156#endif /* QEMU_SOCKETS_H */