if_nameindex() returns NULL on error, if it returns NULL, we just print the error info and return NULL.
Signed-off-by: Wenchao Hao <haowenc...@huawei.com> Signed-off-by: Zhiqiang Liu <liuzhiqian...@huawei.com> Signed-off-by: Wu Bo <wub...@huawei.com> --- usr/iscsi_net_util.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/usr/iscsi_net_util.c b/usr/iscsi_net_util.c index c38456f..10e6fa6 100644 --- a/usr/iscsi_net_util.c +++ b/usr/iscsi_net_util.c @@ -206,6 +206,12 @@ static char *find_vlan_dev(char *netdev, int vlan_id) { } ifni = if_nameindex(); + if (!ifni) { + log_error("Failed to find netdev:%s", strerror(errno)); + close(sockfd); + return NULL; + } + for (i = 0; ifni[i].if_index && ifni[i].if_name; i++) { strlcpy(vlan_hwaddr.ifr_name, ifni[i].if_name, IFNAMSIZ); ioctl(sockfd, SIOCGIFHWADDR, &vlan_hwaddr); -- 2.27.0 -- You received this message because you are subscribed to the Google Groups "open-iscsi" group. To unsubscribe from this group and stop receiving emails from it, send an email to open-iscsi+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/open-iscsi/20201207015410.48488-7-haowenchao%40huawei.com.