1 /* headers to use the BSD sockets */
8 int inet_aton(const char *cp, struct in_addr *ia);
12 #include "qapi/qapi-types-sockets.h"
15 bool fd_is_socket(int fd);
16 int qemu_socket(int domain, int type, int protocol);
21 * @domain: specifies a communication domain, such as PF_UNIX
22 * @type: specifies the socket type.
23 * @protocol: specifies a particular protocol to be used with the socket
24 * @sv: an array to store the pair of socket created
26 * Creates an unnamed pair of connected sockets in the specified domain,
27 * of the specified type, and using the optionally specified protocol.
28 * And automatically set the close-on-exec flags on the returned sockets
30 * Return 0 on success.
32 int qemu_socketpair(int domain, int type, int protocol, int sv[2]);
35 int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
36 int socket_set_cork(int fd, int v);
37 int socket_set_nodelay(int fd);
38 void qemu_socket_set_block(int fd);
39 int qemu_socket_try_set_nonblock(int fd);
40 void qemu_socket_set_nonblock(int fd);
41 int socket_set_fast_reuse(int fd);
44 /* Windows has different names for the same constants with the same values */
50 int inet_ai_family_from_address(InetSocketAddress *addr,
52 int inet_parse(InetSocketAddress *addr, const char *str, Error **errp);
53 int inet_connect(const char *str, Error **errp);
54 int inet_connect_saddr(InetSocketAddress *saddr, Error **errp);
56 NetworkAddressFamily inet_netfamily(int family);
58 int unix_listen(const char *path, Error **errp);
59 int unix_connect(const char *path, Error **errp);
61 SocketAddress *socket_parse(const char *str, Error **errp);
62 int socket_connect(SocketAddress *addr, Error **errp);
63 int socket_listen(SocketAddress *addr, int num, Error **errp);
64 void socket_listen_cleanup(int fd, Error **errp);
65 int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp);
67 /* Old, ipv4 only bits. Don't use for new code. */
68 int parse_host_port(struct sockaddr_in *saddr, const char *str,
70 int socket_init(void);
73 * socket_sockaddr_to_address:
74 * @sa: socket address struct
75 * @salen: size of @sa struct
76 * @errp: pointer to uninitialized error object
78 * Get the string representation of the socket
79 * address. A pointer to the allocated address information
80 * struct will be returned, which the caller is required to
81 * release with a call qapi_free_SocketAddress() when no
84 * Returns: the socket address struct, or NULL on error
87 socket_sockaddr_to_address(struct sockaddr_storage *sa,
92 * socket_local_address:
93 * @fd: the socket file handle
94 * @errp: pointer to uninitialized error object
96 * Get the string representation of the local socket
97 * address. A pointer to the allocated address information
98 * struct will be returned, which the caller is required to
99 * release with a call qapi_free_SocketAddress() when no
102 * Returns: the socket address struct, or NULL on error
104 SocketAddress *socket_local_address(int fd, Error **errp);
107 * socket_remote_address:
108 * @fd: the socket file handle
109 * @errp: pointer to uninitialized error object
111 * Get the string representation of the remote socket
112 * address. A pointer to the allocated address information
113 * struct will be returned, which the caller is required to
114 * release with a call qapi_free_SocketAddress() when no
117 * Returns: the socket address struct, or NULL on error
119 SocketAddress *socket_remote_address(int fd, Error **errp);
122 * socket_address_flatten:
123 * @addr: the socket address to flatten
125 * Convert SocketAddressLegacy to SocketAddress. Caller is responsible
126 * for freeing with qapi_free_SocketAddress().
128 * Returns: the argument converted to SocketAddress.
130 SocketAddress *socket_address_flatten(SocketAddressLegacy *addr);
133 * socket_address_parse_named_fd:
135 * Modify @addr, replacing a named fd by its corresponding number.
136 * Needed for callers that plan to pass @addr to a context where the
137 * current monitor is not available.
139 * Return 0 on success.
141 int socket_address_parse_named_fd(SocketAddress *addr, Error **errp);
143 #endif /* QEMU_SOCKETS_H */