X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Frmr%2Fcommon%2Fsrc%2Ftools_static.c;h=df49dd848722ec2aac5e67dc3f122e1f422392b8;hb=6af063ee12dc292b7d37459199e2a51285030217;hp=3aa5c439e12b2ab826a24d9cf84cc3ddf7ca4c1c;hpb=750cbee6b224532fc10971c04df556ce4bceb832;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 3aa5c43..df49dd8 100644 --- a/src/rmr/common/src/tools_static.c +++ b/src/rmr/common/src/tools_static.c @@ -29,6 +29,9 @@ uta_link2 -- establish a nanomsg connection to a host + uta_dump_env -- dump the environment variables to stdout that are + of importance to RMR. + Author: E. Scott Daniels Date: 30 November 2018 */ @@ -88,9 +91,9 @@ static int uta_tokenise( char* buf, char** tokens, int max, char sep ) { Given a buffer of 'sep' separated tokens, and a list of things, return up to max tokens with any tokens that matched things in the list. Toks is the user supplied array of char* which we will - fill in (up to max) with pointers to tokens from buf. This - damages buf, so the caller must dup the string if it must be - preserved for later, original, use. The pointers returned in + fill in (up to max) with pointers to tokens from buf. This + damages buf, so the caller must dup the string if it must be + preserved for later, original, use. The pointers returned in toks will reference portions of bufs. Returns the number of tokens referenced by toks. @@ -102,7 +105,7 @@ static int uta_rmip_tokenise( char* buf, if_addrs_t* iplist, char** toks, int ma int i; int j; - + all_toks = malloc( sizeof( char * ) * max ); // refernce to all tokens; we'll prune pcount = ntoks = uta_tokenise( buf, all_toks, max, sep ); // split them up j = 0; @@ -150,7 +153,7 @@ static char* uta_h2ip( char const* hname ) { hent = gethostbyname( dname ); if( hent == NULL || hent->h_addr_list == NULL ) { - //fprintf( stderr, "[WRN] h2ip: dns lookup failed for: %s\n", dname ); + //rmr_vlog( RMR_VL_WARN, "h2ip: dns lookup failed for: %s\n", dname ); free( dname ); return NULL; } @@ -284,7 +287,7 @@ static int uta_has_str( char const* buf, char const* str, char sep, int max ) { to the list so that we don't pick up entries from the rtable that are for other processes listening on different interfaces. - The ENV_BIN_IF environment variable may be either an IP address (v6 must be in + The ENV_BIN_IF environment variable may be either an IP address (v6 must be in square braces), or an interface name (e.g. eth0). */ if_addrs_t* mk_ip_list( char* port ) { @@ -314,7 +317,7 @@ if_addrs_t* mk_ip_list( char* port ) { snprintf( wbuf, sizeof( wbuf ), "%s:%s", envp, port ); // smash port onto the addr as is l->addrs[l->naddrs] = strdup( wbuf ); l->naddrs++; - if( DEBUG ) fprintf( stderr, "[INFO] rmr: using only specific bind interface when searching specific RT entries: %s\n", wbuf ); + if( DEBUG ) rmr_vlog( RMR_VL_INFO, "rmr: using only specific bind interface when searching specific RT entries: %s\n", wbuf ); return l; } @@ -327,13 +330,15 @@ if_addrs_t* mk_ip_list( char* port ) { 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_INET ) { - getnameinfo( ele->ifa_addr, sizeof( struct sockaddr_in ), octs, NI_MAXHOST, NULL, 0, NI_NUMERICHOST ); - fmt = "%s:%s"; - } else { - 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"; + if( ele->ifa_addr != NULL ) { // possible for some interfaces to not have an address + if( ele->ifa_addr->sa_family == AF_INET ) { + getnameinfo( ele->ifa_addr, sizeof( struct sockaddr_in ), octs, NI_MAXHOST, NULL, 0, NI_NUMERICHOST ); + fmt = "%s:%s"; + } else { + 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"; + } } } @@ -342,7 +347,7 @@ if_addrs_t* mk_ip_list( char* port ) { *tok = 0; } if( l->naddrs < 128 ) { - if( DEBUG ) fprintf( stderr, "[DBUG] capture address: %s: %s\n", ele->ifa_name, octs ); + if( DEBUG ) rmr_vlog( RMR_VL_DEBUG, "capture address: %s: %s\n", ele->ifa_name, octs ); snprintf( wbuf, sizeof( wbuf ), fmt, octs, port ); // smash port onto the addr l->addrs[l->naddrs] = strdup( wbuf ); @@ -458,4 +463,37 @@ static char* get_default_ip( if_addrs_t* iplist ) { return NULL; } +/* + Write all environment variables that we consider to be important to stderr. +*/ +static void uta_dump_env( ) { + char* token; + char* elist[] = { + ENV_BIND_IF, + ENV_RTG_PORT, + ENV_RTG_ADDR, + ENV_SEED_RT, + ENV_SEED_MEMAP, + ENV_RTG_RAW, + ENV_VERBOSE_FILE, + ENV_NAME_ONLY, + ENV_WARNINGS, + ENV_SRC_ID, + ENV_LOG_HR, + ENV_LOG_VLEVEL, + ENV_CTL_PORT, + ENV_RTREQ_FREA + }; + int i; + + for( i = 0; i < sizeof( elist ) / sizeof( char *); i ++ ) { + token = getenv( elist[i] ); + if( token != NULL ) { + rmr_vlog( RMR_VL_INFO, "dump_env: %s = '%s'\n", elist[i], token ); + } else { + rmr_vlog( RMR_VL_INFO, "dump_env: %s = \n", elist[i] ); + } + } +} + #endif