From 17c55decec2a516cf7f290ec8a5f4f207531e8b4 Mon Sep 17 00:00:00 2001 From: Daniel P. Berrange Date: Fri, 1 May 2015 17:36:20 +0100 Subject: sockets: add helpers for creating SocketAddress from a socket Add two helper methods that, given a socket file descriptor, can return a populated SocketAddress struct containing either the local or remote address information. Signed-off-by: Daniel P. Berrange --- include/qemu/sockets.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'include') diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index c174b5cbdd..3ea7cc9f03 100644 --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -88,4 +88,34 @@ int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp); int parse_host_port(struct sockaddr_in *saddr, const char *str); int socket_init(void); +/** + * socket_local_address: + * @fd: the socket file handle + * @errp: pointer to uninitialized error object + * + * Get the string representation of the local socket + * address. A pointer to the allocated address information + * struct will be returned, which the caller is required to + * release with a call qapi_free_SocketAddress when no + * longer required. + * + * Returns: the socket address struct, or NULL on error + */ +SocketAddress *socket_local_address(int fd, Error **errp); + +/** + * socket_remote_address: + * @fd: the socket file handle + * @errp: pointer to uninitialized error object + * + * Get the string representation of the remote socket + * address. A pointer to the allocated address information + * struct will be returned, which the caller is required to + * release with a call qapi_free_SocketAddress when no + * longer required. + * + * Returns: the socket address struct, or NULL on error + */ +SocketAddress *socket_remote_address(int fd, Error **errp); + #endif /* QEMU_SOCKET_H */ -- cgit v1.2.3-55-g7522