feat(socket): log resolved ip addresses if portal is a hostname
Signed-off-by: Peter Lieven <pl@dlhnet.de>
This commit is contained in:
15
lib/socket.c
15
lib/socket.c
@@ -306,6 +306,7 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal,
|
|||||||
struct addrinfo *ai = NULL;
|
struct addrinfo *ai = NULL;
|
||||||
union socket_address sa;
|
union socket_address sa;
|
||||||
int socksize;
|
int socksize;
|
||||||
|
bool portal_is_ip;
|
||||||
|
|
||||||
ISCSI_LOG(iscsi, 2, "connecting to portal %s",portal);
|
ISCSI_LOG(iscsi, 2, "connecting to portal %s",portal);
|
||||||
|
|
||||||
@@ -352,6 +353,10 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal,
|
|||||||
*str = 0;
|
*str = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* check if we got an ip address or hostname for portal */
|
||||||
|
portal_is_ip = inet_pton(AF_INET, host, &sa) == 1 ||
|
||||||
|
inet_pton(AF_INET6, host, &sa) == 1;
|
||||||
|
|
||||||
/* is it a hostname ? */
|
/* is it a hostname ? */
|
||||||
if (getaddrinfo(host, NULL, NULL, &ai) != 0) {
|
if (getaddrinfo(host, NULL, NULL, &ai) != 0) {
|
||||||
iscsi_free(iscsi, addr);
|
iscsi_free(iscsi, addr);
|
||||||
@@ -371,6 +376,11 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal,
|
|||||||
#ifdef HAVE_SOCK_SIN_LEN
|
#ifdef HAVE_SOCK_SIN_LEN
|
||||||
sa.sin.sin_len = socksize;
|
sa.sin.sin_len = socksize;
|
||||||
#endif
|
#endif
|
||||||
|
if (!portal_is_ip) {
|
||||||
|
char ip[INET_ADDRSTRLEN];
|
||||||
|
inet_ntop(AF_INET, &sa.sin.sin_addr, ip, sizeof(ip));
|
||||||
|
ISCSI_LOG(iscsi, 2, "portal resolved to ipv4 address %s", ip);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#ifdef HAVE_SOCKADDR_IN6
|
#ifdef HAVE_SOCKADDR_IN6
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
@@ -381,6 +391,11 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal,
|
|||||||
#ifdef HAVE_SOCK_SIN_LEN
|
#ifdef HAVE_SOCK_SIN_LEN
|
||||||
sa.sin6.sin6_len = socksize;
|
sa.sin6.sin6_len = socksize;
|
||||||
#endif
|
#endif
|
||||||
|
if (!portal_is_ip) {
|
||||||
|
char ip[INET6_ADDRSTRLEN];
|
||||||
|
inet_ntop(AF_INET6, &sa.sin6.sin6_addr, ip, sizeof(ip));
|
||||||
|
ISCSI_LOG(iscsi, 2, "portal resolved to ipv6 address %s", ip);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user