From: "Steven Rostedt (Google)" <rostedt@xxxxxxxxxxx> In order to retrieve just the remote cid that the agent proxy will need to do, make the parameters to get_vsocket_params() optional, where a NULL can be passed in and it will only update the non-NULL parameters. Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx> --- tracecmd/trace-vsock.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/tracecmd/trace-vsock.c b/tracecmd/trace-vsock.c index 39294e7a2a3c..3bad9efad39a 100644 --- a/tracecmd/trace-vsock.c +++ b/tracecmd/trace-vsock.c @@ -76,20 +76,24 @@ int get_vsocket_params(int fd, unsigned int *lcid, unsigned int *rcid) struct sockaddr_vm addr; socklen_t addr_len = sizeof(addr); - memset(&addr, 0, sizeof(addr)); - if (getsockname(fd, (struct sockaddr *)&addr, &addr_len)) - return -1; - if (addr.svm_family != AF_VSOCK) - return -1; - *lcid = addr.svm_cid; - - memset(&addr, 0, sizeof(addr)); - addr_len = sizeof(addr); - if (getpeername(fd, (struct sockaddr *)&addr, &addr_len)) - return -1; - if (addr.svm_family != AF_VSOCK) - return -1; - *rcid = addr.svm_cid; + if (lcid) { + memset(&addr, 0, sizeof(addr)); + if (getsockname(fd, (struct sockaddr *)&addr, &addr_len)) + return -1; + if (addr.svm_family != AF_VSOCK) + return -1; + *lcid = addr.svm_cid; + } + + if (rcid) { + memset(&addr, 0, sizeof(addr)); + addr_len = sizeof(addr); + if (getpeername(fd, (struct sockaddr *)&addr, &addr_len)) + return -1; + if (addr.svm_family != AF_VSOCK) + return -1; + *rcid = addr.svm_cid; + } return 0; } -- 2.35.1