From 58dc31f1a7dc6cd0f21bd51a34011ba366d36e53 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Thu, 21 Dec 2017 12:55:20 +0000 Subject: sockets: move fd_is_socket() into common sockets code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The fd_is_socket() helper method is useful in a few places, so put it in the common sockets code. Make the code more compact while moving it. Reviewed-by: Eric Blake Reviewed-by: Marc-André Lureau Signed-off-by: Daniel P. Berrange --- util/qemu-sockets.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'util') diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 7f13e8a338..fa79471647 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -91,6 +91,14 @@ NetworkAddressFamily inet_netfamily(int family) return NETWORK_ADDRESS_FAMILY_UNKNOWN; } +bool fd_is_socket(int fd) +{ + int optval; + socklen_t optlen = sizeof(optval); + return !qemu_getsockopt(fd, SOL_SOCKET, SO_TYPE, &optval, &optlen); +} + + /* * Matrix we're trying to apply * -- cgit v1.2.1