From 3a484991535187a1a301eb5df2053a88bc87e2fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 30 Nov 2018 15:17:25 +0100 Subject: shared/socket-util: do not print empty CID That's just ugly. --- src/basic/socket-util.c | 12 ++++++------ src/test/test-socket-util.c | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c index a156566511..d94bac4287 100644 --- a/src/basic/socket-util.c +++ b/src/basic/socket-util.c @@ -672,12 +672,12 @@ int sockaddr_pretty(const struct sockaddr *_sa, socklen_t salen, bool translate_ break; case AF_VSOCK: - if (include_port) - r = asprintf(&p, - "vsock:%u:%u", - sa->vm.svm_cid, - sa->vm.svm_port); - else + if (include_port) { + if (sa->vm.svm_cid == VMADDR_CID_ANY) + r = asprintf(&p, "vsock::%u", sa->vm.svm_port); + else + r = asprintf(&p, "vsock:%u:%u", sa->vm.svm_cid, sa->vm.svm_port); + } else r = asprintf(&p, "vsock:%u", sa->vm.svm_cid); if (r < 0) return -ENOMEM; diff --git a/src/test/test-socket-util.c b/src/test/test-socket-util.c index 24dd701808..687caf83be 100644 --- a/src/test/test-socket-util.c +++ b/src/test/test-socket-util.c @@ -98,7 +98,7 @@ static void test_socket_address_parse(void) { test_socket_address_parse_one("@abstract", 0, AF_UNIX, NULL); test_socket_address_parse_one("vsock:2:1234", 0, AF_VSOCK, NULL); - test_socket_address_parse_one("vsock::1234", 0, AF_VSOCK, "vsock:4294967295:1234"); + test_socket_address_parse_one("vsock::1234", 0, AF_VSOCK, NULL); test_socket_address_parse_one("vsock:2:1234x", -EINVAL, 0, NULL); test_socket_address_parse_one("vsock:2x:1234", -EINVAL, 0, NULL); test_socket_address_parse_one("vsock:2", -EINVAL, 0, NULL); -- cgit v1.2.1