X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Frmr%2Fsi%2Fsrc%2Fsi95%2Fsiaddress.c;h=e77ab4f618781280188ab43cf84930b2b369b8d4;hb=0a58458afe875798f0ac3f367bd05e4ba523e115;hp=86f54df39d0b934816ded564d2830818eda6c4bd;hpb=ec88d3c0563eeb6ae5f73427edb0b3c4d7acf299;p=ric-plt%2Flib%2Frmr.git diff --git a/src/rmr/si/src/si95/siaddress.c b/src/rmr/si/src/si95/siaddress.c index 86f54df..e77ab4f 100644 --- a/src/rmr/si/src/si95/siaddress.c +++ b/src/rmr/si/src/si95/siaddress.c @@ -86,7 +86,8 @@ extern int SIgenaddr( char *target, int proto, int family, int socktype, struct if( *dstr == '[' ) { // strip [ and ] from v6 and point pstring if port there dstr++; pstr = strchr( dstr, ']' ); - if( *pstr != ']' ) { + if( !pstr || *pstr != ']' ) { + free( fptr ); return -1; } @@ -108,15 +109,16 @@ extern int SIgenaddr( char *target, int proto, int family, int socktype, struct memset( &hint, 0, sizeof( hint ) ); hint.ai_family = family; // AF_INET AF_INET6... let this be 0 to select best based on addr hint.ai_socktype = socktype; // SOCK_DGRAM SOCK_STREAM - hint.ai_protocol = proto; // IPPORTO_TCP IPPROTO_UDP + hint.ai_protocol = proto; // IPPROTO_TCP IPPROTO_UDP hint.ai_flags = ga_flags; if( DEBUG ) - fprintf( stderr, "[DBUG] siaddress: calling getaddrinfo flags=%x proto=%d family=%d target=%s host=%s port=%s\n", - ga_flags, proto, family, target, dstr, pstr ); + rmr_vlog( RMR_VL_DEBUG, "siaddress: calling getaddrinfo flags=%x sockty=%d proto=%d family=%d target=%s host=%s port=%s\n", + ga_flags, socktype, proto, family, target, dstr, pstr ); if( (error = getaddrinfo( dstr, pstr, &hint, &list )) ) { - fprintf( stderr, "error from getaddrinfo: target=%s host=%s port=%s(port): error=(%d) %s\n", target, dstr, pstr, error, gai_strerror( error ) ); + fprintf( stderr, "sigenaddr: error from getaddrinfo: target=%s host=%s port=%s(port): error=(%d) %s\n", + target, dstr, pstr, error, gai_strerror( error ) ); } else { *rap = (struct sockaddr *) malloc( list->ai_addrlen ); // alloc a buffer and give address to caller memcpy( *rap, list->ai_addr, list->ai_addrlen ); @@ -126,7 +128,7 @@ extern int SIgenaddr( char *target, int proto, int family, int socktype, struct freeaddrinfo( list ); // ditch system allocated memory } - free( dstr ); + free( fptr ); return rlen; } @@ -139,7 +141,9 @@ extern int SIgenaddr( char *target, int proto, int family, int socktype, struct */ extern int SIaddress( void *src, void **dest, int type ) { struct sockaddr_in *addr; // pointer to the address + struct sockaddr_in6 *addr6; // ip6 has a different layout unsigned char *num; // pointer at the address number + uint8_t* byte; // pointer at the ipv6 address byte values char wbuf[256]; // work buffer int i; int rlen = 0; // return len - len of address struct or string @@ -147,14 +151,16 @@ extern int SIaddress( void *src, void **dest, int type ) { switch( type ) { case AC_TODOT: // convert from a struct to human readable "dotted decimal" addr = (struct sockaddr_in *) src; - num = (char *) &addr->sin_addr.s_addr; // point at the long if( addr->sin_family == AF_INET6 ) { - sprintf( wbuf, "[%u:%u:%u:%u:%u:%u]:%d", - *(num+0), *(num+1), *(num+2), - *(num+3), *(num+4), *(num+5) , - (int) ntohs( addr->sin_port ) ); + addr6 = (struct sockaddr_in6 *) src; // really an ip6 struct + byte = (uint8_t *) &addr6->sin6_addr; + sprintf( wbuf, "[%u:%u:%u:%u:%u:%u]:%d", + *(byte+0), *(byte+1), *(byte+2), + *(byte+3), *(byte+4), *(byte+5) , + (int) ntohs( addr6->sin6_port ) ); } else { + num = (char *) &addr->sin_addr.s_addr; // point at the long sprintf( wbuf, "%u.%u.%u.%u;%d", *(num+0), *(num+1), *(num+2), *(num+3), (int) ntohs(addr->sin_port) ); } @@ -162,13 +168,12 @@ extern int SIaddress( void *src, void **dest, int type ) { rlen = strlen( *dest ); break; - case AC_TOADDR6: // from hostname;port string to address for send etc - return SIgenaddr( src, PF_INET6, IPPROTO_TCP, SOCK_STREAM, (struct sockaddr **) dest ); - break; + case AC_TOADDR6: // from hostname:port string to address for send etc + return SIgenaddr( src, IPPROTO_TCP, AF_INET6, SOCK_STREAM, (struct sockaddr **) dest ); case AC_TOADDR: // from dotted decimal to address struct ip4 - return SIgenaddr( src, PF_INET, IPPROTO_TCP, SOCK_STREAM, (struct sockaddr **) dest ); - break; + //return SIgenaddr( src, AF_INET, IPPROTO_TCP, SOCK_STREAM, (struct sockaddr **) dest ); + return SIgenaddr( src, IPPROTO_TCP, AF_INET, SOCK_STREAM, (struct sockaddr **) dest ); } return rlen;