aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/qemu-sockets.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 0d6cd1f4ef..ef3588942b 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -1151,3 +1151,39 @@ void qapi_copy_SocketAddress(SocketAddress **p_dest,
qmp_input_visitor_cleanup(qiv);
qobject_decref(obj);
}
+
+char *socket_address_to_string(struct SocketAddress *addr, Error **errp)
+{
+ char *buf;
+ InetSocketAddress *inet;
+ char host_port[INET6_ADDRSTRLEN + 5 + 4];
+
+ switch (addr->type) {
+ case SOCKET_ADDRESS_KIND_INET:
+ inet = addr->u.inet.data;
+ if (strchr(inet->host, ':') == NULL) {
+ snprintf(host_port, sizeof(host_port), "%s:%s", inet->host,
+ inet->port);
+ buf = g_strdup(host_port);
+ } else {
+ snprintf(host_port, sizeof(host_port), "[%s]:%s", inet->host,
+ inet->port);
+ buf = g_strdup(host_port);
+ }
+ break;
+
+ case SOCKET_ADDRESS_KIND_UNIX:
+ buf = g_strdup(addr->u.q_unix.data->path);
+ break;
+
+ case SOCKET_ADDRESS_KIND_FD:
+ buf = g_strdup(addr->u.fd.data->str);
+ break;
+
+ default:
+ error_setg(errp, "socket family %d unsupported",
+ addr->type);
+ return NULL;
+ }
+ return buf;
+}