Add a test case to virnetsockettest.
---
src/libvirt_remote.syms | 1 +
src/rpc/virnetsocket.c | 10 ++++++++++
src/rpc/virnetsocket.h | 1 +
tests/virnetsockettest.c | 10 ++++++++++
4 files changed, 22 insertions(+)
diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms
index 1a88fff..f3cf65d 100644
--- a/src/libvirt_remote.syms
+++ b/src/libvirt_remote.syms
@@ -227,6 +227,7 @@ virNetSocketPreExecRestart;
virNetSocketRead;
virNetSocketRecvFD;
virNetSocketRemoteAddrString;
+virNetSocketRemoteAddrStringURI;
virNetSocketRemoveIOCallback;
virNetSocketSendFD;
virNetSocketSetBlocking;
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index d909b94..f10b62b 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -87,6 +87,7 @@ struct _virNetSocket {
virSocketAddr remoteAddr;
char *localAddrStr;
char *remoteAddrStr;
+ char *remoteAddrStrURI;
#if WITH_GNUTLS
virNetTLSSessionPtr tlsSession;
@@ -269,6 +270,10 @@ static virNetSocketPtr virNetSocketNew(virSocketAddrPtr localAddr,
!(sock->remoteAddrStr = virSocketAddrFormatFull(remoteAddr, true,
";")))
goto error;
+ if (remoteAddr &&
+ !(sock->remoteAddrStrURI = virSocketAddrFormatFull(remoteAddr, true, NULL)))
+ goto error;
+
sock->client = isClient;
PROBE(RPC_SOCKET_NEW,
@@ -1204,6 +1209,7 @@ void virNetSocketDispose(void *obj)
VIR_FREE(sock->localAddrStr);
VIR_FREE(sock->remoteAddrStr);
+ VIR_FREE(sock->remoteAddrStrURI);
}
@@ -1465,6 +1471,10 @@ const char *virNetSocketRemoteAddrString(virNetSocketPtr sock)
return sock->remoteAddrStr;
}
+const char *virNetSocketRemoteAddrStringURI(virNetSocketPtr sock)
+{
+ return sock->remoteAddrStrURI;
+}
#if WITH_GNUTLS
static ssize_t virNetSocketTLSSessionWrite(const char *buf,
diff --git a/src/rpc/virnetsocket.h b/src/rpc/virnetsocket.h
index 5de3d92..25ca14e 100644
--- a/src/rpc/virnetsocket.h
+++ b/src/rpc/virnetsocket.h
@@ -150,6 +150,7 @@ bool virNetSocketHasPendingData(virNetSocketPtr sock);
const char *virNetSocketLocalAddrString(virNetSocketPtr sock);
const char *virNetSocketRemoteAddrString(virNetSocketPtr sock);
+const char *virNetSocketRemoteAddrStringURI(virNetSocketPtr sock);
int virNetSocketListen(virNetSocketPtr sock, int backlog);
int virNetSocketAccept(virNetSocketPtr sock,
diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c
index 9df90a9..8cd8ede 100644
--- a/tests/virnetsockettest.c
+++ b/tests/virnetsockettest.c
@@ -275,6 +275,11 @@ static int testSocketUNIXAddrs(const void *data ATTRIBUTE_UNUSED)
goto cleanup;
}
+ if (STRNEQ(virNetSocketRemoteAddrStringURI(csock), "127.0.0.1:0")) {
+ VIR_DEBUG("Unexpected remote address");
+ goto cleanup;
+ }
+
if (virNetSocketAccept(lsock, &ssock) < 0) {
VIR_DEBUG("Unexpected client socket missing");
@@ -292,6 +297,11 @@ static int testSocketUNIXAddrs(const void *data ATTRIBUTE_UNUSED)
goto cleanup;
}
+ if (STRNEQ(virNetSocketRemoteAddrStringURI(ssock), "127.0.0.1:0")) {
+ VIR_DEBUG("Unexpected remote address");
+ goto cleanup;
+ }
+
ret = 0;
--
2.7.3