// :vi sw=4 ts=4 noet:
/*
==================================================================================
- Copyright (c) 2019-2020 Nokia
- Copyright (c) 2018-2020 AT&T Intellectual Property.
+ Copyright (c) 2019-2021 Nokia
+ Copyright (c) 2018-2021 AT&T Intellectual Property.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
char const* sp;
int n; // num moved
- if( dest == NULL && src == NULL ) {
+ if( dest == NULL || src == NULL ) {
return -1;
}
*(tok++) = 0;
}
- hent = gethostbyname( dname );
+ hent = gethostbyname( dname ); // valgrind will complain that this leaks, but we cannot free it!
if( hent == NULL || hent->h_addr_list == NULL ) {
//rmr_vlog( RMR_VL_WARN, "h2ip: dns lookup failed for: %s\n", dname );
free( dname );
struct ifaddrs *ele; // pointer into the list
char octs[NI_MAXHOST+1];
char wbuf[NI_MAXHOST+128];
- char* fmt;
+ char* fmt = NULL; // address format (v4 or v6)
char* envp; // at the environment var if there
char* target_if = NULL; // target interface supplied by ENV_BIND_IF
char* tok;
getifaddrs( &ifs );
for( ele = ifs; ele; ele = ele->ifa_next ) {
memset( octs, 0, sizeof( octs ) );
+ if( DEBUG ) rmr_vlog( RMR_VL_DEBUG, "checking interface: %s\n", ele->ifa_name );
if( ele && strcmp( ele->ifa_name, "lo" ) && // do NOT capture the loopback interface address
(target_if == NULL || strcmp( ele->ifa_name, target_if ) == 0 ) ) { // no target, or matches ENV_BIND_IF target
if( ele->ifa_addr->sa_family == AF_INET6 ) {
getnameinfo( ele->ifa_addr, sizeof( struct sockaddr_in6 ), octs, NI_MAXHOST, NULL, 0, NI_NUMERICHOST );
fmt = "[%s]:%s";
+ } else {
+ if( DEBUG ) rmr_vlog( RMR_VL_DEBUG, "unrecognised IF family (not v4 or v6)\n" );
+ continue;
}
}
- if( *octs ) {
+ if( *octs && fmt != NULL ) { // possible that we didn't recognise the format (v4 or v6), don't try if we didn't
if( (tok = strchr( octs, '%' )) != NULL ) { // for unknown reasons some ip6 addrs have %if-name appended; truncate
*tok = 0;
}
l->addrs[l->naddrs] = strdup( wbuf );
l->naddrs++;
}
+ } else {
+ if( DEBUG ) rmr_vlog( RMR_VL_DEBUG, "unrecognised or no octets octs=%x fmt=%p\n", *octs, fmt );
}
+ } else {
+ if( DEBUG ) rmr_vlog( RMR_VL_DEBUG, "no ip address for interface: %s\n", ele->ifa_name );
}
}
}