X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Frmr%2Fcommon%2Fsrc%2Ftools_static.c;h=2d2cc229716d772b1ac52e53eaeb89e439c76a7a;hb=a68562a02028434a87149d5996b291e83d33be51;hp=a69db35e116c1c482224dfea8fc692ee3e468d9e;hpb=fcea3951d44de0cc55d33c5e114487abe79d3406;p=ric-plt%2Flib%2Frmr.git diff --git a/src/rmr/common/src/tools_static.c b/src/rmr/common/src/tools_static.c index a69db35..2d2cc22 100644 --- a/src/rmr/common/src/tools_static.c +++ b/src/rmr/common/src/tools_static.c @@ -1,8 +1,8 @@ // :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. @@ -80,7 +80,7 @@ static inline int zt_buf_fill( char* dest, char const* src, int len ) { char const* sp; int n; // num moved - if( dest == NULL && src == NULL ) { + if( dest == NULL || src == NULL ) { return -1; } @@ -187,7 +187,7 @@ static char* uta_h2ip( char const* hname ) { *(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 ); @@ -334,7 +334,7 @@ static if_addrs_t* mk_ip_list( char* port ) { 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; @@ -365,6 +365,7 @@ static if_addrs_t* mk_ip_list( char* port ) { 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 @@ -376,10 +377,13 @@ static if_addrs_t* mk_ip_list( char* port ) { 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; } @@ -390,7 +394,11 @@ static if_addrs_t* mk_ip_list( char* port ) { 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 ); } } }