Skip to content

Commit 7887650

Browse files
committed
nvme-print: fix traddr transformation for ave discovery log
inet_ntop wants the network address structure as input not converted string. Fixes: 1571543 ("nvme: add ave-discovery-log command") Signed-off-by: Daniel Wagner <[email protected]>
1 parent da2f1b1 commit 7887650

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

nvme-print-json.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5632,16 +5632,22 @@ static void json_host_discovery_log(struct nvme_host_discover_log *log)
56325632

56335633
static void obj_add_traddr(struct json_object *o, const char *k, __u8 adrfam, __u8 *traddr)
56345634
{
5635-
int af = AF_INET;
5636-
socklen_t size = INET_ADDRSTRLEN;
56375635
char dst[INET6_ADDRSTRLEN];
5636+
socklen_t size;
5637+
int af;
56385638

5639-
if (adrfam == NVMF_ADDR_FAMILY_IP6) {
5639+
if (adrfam == NVMF_ADDR_FAMILY_IP4) {
5640+
af = AF_INET;
5641+
size = INET_ADDRSTRLEN;
5642+
} else if (adrfam == NVMF_ADDR_FAMILY_IP6) {
56405643
af = AF_INET6;
56415644
size = INET6_ADDRSTRLEN;
5645+
} else {
5646+
obj_add_str(o, k, "<invalid>");
5647+
return;
56425648
}
56435649

5644-
if (inet_ntop(af, libnvmf_adrfam_str(adrfam), dst, size))
5650+
if (inet_ntop(af, traddr, dst, size))
56455651
obj_add_str(o, k, dst);
56465652
}
56475653

nvme-print-stdout.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6642,16 +6642,22 @@ static void stdout_host_discovery_log(struct nvme_host_discover_log *log)
66426642

66436643
static void print_traddr(char *field, __u8 adrfam, __u8 *traddr)
66446644
{
6645-
int af = AF_INET;
6646-
socklen_t size = INET_ADDRSTRLEN;
66476645
char dst[INET6_ADDRSTRLEN];
6646+
socklen_t size
6647+
int af;
66486648

6649-
if (adrfam == NVMF_ADDR_FAMILY_IP6) {
6649+
if (adrfam == NVMF_ADDR_FAMILY_IP4) {
6650+
af = AF_INET;
6651+
size = INET_ADDRSTRLEN;
6652+
} else if (adrfam == NVMF_ADDR_FAMILY_IP6) {
66506653
af = AF_INET6;
66516654
size = INET6_ADDRSTRLEN;
6655+
} else {
6656+
printf("%s: <invalid>\n", field);
6657+
return;
66526658
}
66536659

6654-
if (inet_ntop(af, libnvmf_adrfam_str(adrfam), dst, size))
6660+
if (inet_ntop(af, traddr, dst, size))
66556661
printf("%s: %s\n", field, dst);
66566662
}
66576663

0 commit comments

Comments
 (0)