diff options
author | Alyssa Ross <hi@alyssa.is> | 2021-03-19 02:56:43 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2021-03-21 14:30:17 +0000 |
commit | db81fcb1d2484601b7f16fd4f3e0be6ceb7357f6 (patch) | |
tree | 148f766c0e2899aa16022c6670bbeff64e616e0c /vsock.c | |
parent | e718a97b27a6661fbcf10ea27ed1f097b598dc3c (diff) | |
download | ucspi-vsock-db81fcb1d2484601b7f16fd4f3e0be6ceb7357f6.tar ucspi-vsock-db81fcb1d2484601b7f16fd4f3e0be6ceb7357f6.tar.gz ucspi-vsock-db81fcb1d2484601b7f16fd4f3e0be6ceb7357f6.tar.bz2 ucspi-vsock-db81fcb1d2484601b7f16fd4f3e0be6ceb7357f6.tar.lz ucspi-vsock-db81fcb1d2484601b7f16fd4f3e0be6ceb7357f6.tar.xz ucspi-vsock-db81fcb1d2484601b7f16fd4f3e0be6ceb7357f6.tar.zst ucspi-vsock-db81fcb1d2484601b7f16fd4f3e0be6ceb7357f6.zip |
vsock: get cid and port instead of just cid
We can get both in the same system call, so we might as well, rather than having two different functions that make the system call twice. Message-Id: <20210319025648.17925-1-hi@alyssa.is> Reviewed-by: Cole Helbling <cole.e.helbling@outlook.com>
Diffstat (limited to 'vsock.c')
-rw-r--r-- | vsock.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/vsock.c b/vsock.c index e6a173c..99945c3 100644 --- a/vsock.c +++ b/vsock.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-or-later -// SPDX-FileCopyrightText: 2020 Alyssa Ross <hi@alyssa.is> +// SPDX-FileCopyrightText: 2020-2021 Alyssa Ross <hi@alyssa.is> #define _GNU_SOURCE @@ -62,7 +62,7 @@ int vsock_open(uint32_t cid, uint32_t port) return fd; } -int vsock_get_port(int fd, uint32_t *port) +int vsock_get_cid_and_port(int fd, uint32_t *cid, uint32_t *port) { struct sockaddr_vm addr; socklen_t addrlen = sizeof addr; @@ -70,7 +70,10 @@ int vsock_get_port(int fd, uint32_t *port) if (getsockname(fd, (struct sockaddr *)&addr, &addrlen) == -1) return -1; - *port = addr.svm_port; + if (cid) + *cid = addr.svm_cid; + if (port) + *port = addr.svm_port; return 0; } |