Commit 193002f9 authored by Jim Harris's avatar Jim Harris Committed by Tomasz Zawadzki
Browse files

util: allow NULL laddr/paddr for spdk_net_getaddr



If users only want to get certain fields, allow them to pass
NULL for addresses they do not care about.

Signed-off-by: default avatarJim Harris <jim.harris@samsung.com>
Change-Id: I74108b987846fbd4c6699d28c86b3b2c6a7e2933
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/24145


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
parent 9abdcd99
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -53,10 +53,10 @@ bool spdk_net_is_loopback(int fd);
 * Get local and peer addresses of the given fd.
 *
 * \param fd file descriptor to get address.
 * \param laddr A pointer to the buffer to hold the local address.
 * \param laddr A pointer (may be NULL) to the buffer to hold the local address.
 * \param llen Length of the buffer 'laddr'.
 * \param lport A pointer (may be NULL) to the buffer to hold the local port info.
 * \param paddr A pointer to the buffer to hold the peer address.
 * \param paddr A pointer (may be NULL) to the buffer to hold the peer address.
 * \param plen Length of the buffer 'paddr'.
 * \param pport A pointer (may be NULL) to the buffer to hold the peer port info.
 *
+12 −8
Original line number Diff line number Diff line
@@ -147,11 +147,13 @@ spdk_net_getaddr(int fd, char *laddr, int llen, uint16_t *lport,
		return -1;
	}

	if (laddr) {
		rc = spdk_net_get_address_string((struct sockaddr *)&sa, laddr, llen);
		if (rc != 0) {
			SPDK_ERRLOG("spdk_net_get_address_string() failed (errno=%d)\n", rc);
			return -1;
		}
	}

	if (lport) {
		if (sa.ss_family == AF_INET) {
@@ -180,11 +182,13 @@ spdk_net_getaddr(int fd, char *laddr, int llen, uint16_t *lport,
		return -1;
	}

	if (paddr) {
		rc = spdk_net_get_address_string((struct sockaddr *)&sa, paddr, plen);
		if (rc != 0) {
			SPDK_ERRLOG("spdk_net_get_address_string() failed (errno=%d)\n", rc);
			return -1;
		}
	}

	if (pport) {
		if (sa.ss_family == AF_INET) {