sockets.h (3902B)
1/* headers to use the BSD sockets */ 2 3#ifndef QEMU_SOCKETS_H 4#define QEMU_SOCKETS_H 5 6#ifdef _WIN32 7 8int inet_aton(const char *cp, struct in_addr *ia); 9 10#endif /* !_WIN32 */ 11 12#include "qapi/qapi-types-sockets.h" 13 14/* misc helpers */ 15bool fd_is_socket(int fd); 16int qemu_socket(int domain, int type, int protocol); 17int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen); 18int socket_set_cork(int fd, int v); 19int socket_set_nodelay(int fd); 20void qemu_set_block(int fd); 21int qemu_try_set_nonblock(int fd); 22void qemu_set_nonblock(int fd); 23int socket_set_fast_reuse(int fd); 24 25#ifdef WIN32 26/* Windows has different names for the same constants with the same values */ 27#define SHUT_RD 0 28#define SHUT_WR 1 29#define SHUT_RDWR 2 30#endif 31 32int inet_ai_family_from_address(InetSocketAddress *addr, 33 Error **errp); 34int inet_parse(InetSocketAddress *addr, const char *str, Error **errp); 35int inet_connect(const char *str, Error **errp); 36int inet_connect_saddr(InetSocketAddress *saddr, Error **errp); 37 38NetworkAddressFamily inet_netfamily(int family); 39 40int unix_listen(const char *path, Error **errp); 41int unix_connect(const char *path, Error **errp); 42 43SocketAddress *socket_parse(const char *str, Error **errp); 44int socket_connect(SocketAddress *addr, Error **errp); 45int socket_listen(SocketAddress *addr, int num, Error **errp); 46void socket_listen_cleanup(int fd, Error **errp); 47int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp); 48 49/* Old, ipv4 only bits. Don't use for new code. */ 50int parse_host_port(struct sockaddr_in *saddr, const char *str, 51 Error **errp); 52int socket_init(void); 53 54/** 55 * socket_sockaddr_to_address: 56 * @sa: socket address struct 57 * @salen: size of @sa struct 58 * @errp: pointer to uninitialized error object 59 * 60 * Get the string representation of the socket 61 * address. A pointer to the allocated address information 62 * struct will be returned, which the caller is required to 63 * release with a call qapi_free_SocketAddress() when no 64 * longer required. 65 * 66 * Returns: the socket address struct, or NULL on error 67 */ 68SocketAddress * 69socket_sockaddr_to_address(struct sockaddr_storage *sa, 70 socklen_t salen, 71 Error **errp); 72 73/** 74 * socket_local_address: 75 * @fd: the socket file handle 76 * @errp: pointer to uninitialized error object 77 * 78 * Get the string representation of the local 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 82 * longer required. 83 * 84 * Returns: the socket address struct, or NULL on error 85 */ 86SocketAddress *socket_local_address(int fd, Error **errp); 87 88/** 89 * socket_remote_address: 90 * @fd: the socket file handle 91 * @errp: pointer to uninitialized error object 92 * 93 * Get the string representation of the remote socket 94 * address. A pointer to the allocated address information 95 * struct will be returned, which the caller is required to 96 * release with a call qapi_free_SocketAddress() when no 97 * longer required. 98 * 99 * Returns: the socket address struct, or NULL on error 100 */ 101SocketAddress *socket_remote_address(int fd, Error **errp); 102 103/** 104 * socket_address_flatten: 105 * @addr: the socket address to flatten 106 * 107 * Convert SocketAddressLegacy to SocketAddress. Caller is responsible 108 * for freeing with qapi_free_SocketAddress(). 109 * 110 * Returns: the argument converted to SocketAddress. 111 */ 112SocketAddress *socket_address_flatten(SocketAddressLegacy *addr); 113 114/** 115 * socket_address_parse_named_fd: 116 * 117 * Modify @addr, replacing a named fd by its corresponding number. 118 * Needed for callers that plan to pass @addr to a context where the 119 * current monitor is not available. 120 * 121 * Return 0 on success. 122 */ 123int socket_address_parse_named_fd(SocketAddress *addr, Error **errp); 124 125#endif /* QEMU_SOCKETS_H */