X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Frmr%2Fcommon%2Fsrc%2Fmbuf_api.c;fp=src%2Frmr%2Fcommon%2Fsrc%2Fmbuf_api.c;h=6d9042a1500b1b87c30dcdc107c7423c5bde49d3;hb=68d09fa5028e47e763c44c30647da31e77eda64a;hp=65979deeff0bce0c84a03d47520de949587129b9;hpb=b5f659837dd6c01bffde1f2f449328b42b47ccf5;p=ric-plt%2Flib%2Frmr.git diff --git a/src/rmr/common/src/mbuf_api.c b/src/rmr/common/src/mbuf_api.c index 65979de..6d9042a 100644 --- a/src/rmr/common/src/mbuf_api.c +++ b/src/rmr/common/src/mbuf_api.c @@ -347,3 +347,33 @@ extern unsigned char* rmr_get_src( rmr_mbuf_t* msg, unsigned char* dest ) { return dest; } + +/* + Returns the string with the IP address as reported by the sender. This is + the IP address that the sender has sussed off of one of the interfaces + and cannot be guarenteed to be the acutal IP address which was used to + establish the connection. The caller must provide a buffer of at least + 64 bytes; the string will be nil terminated. A pointer to the user's buffer + is returned on success, nil on failure. +*/ +extern unsigned char* rmr_get_srcip( rmr_mbuf_t* msg, unsigned char* dest ) { + uta_mhdr_t* hdr = NULL; + char* rstr = NULL; + + errno = EINVAL; + + if( dest != NULL && msg != NULL ) { + hdr = msg->header; + if( HDR_VERSION( msg->header ) > 2 ) { // src ip was not present in hdr until ver 3 + errno = 0; + strcpy( dest, hdr->srcip ); + rstr = dest; + } else { + errno = 0; + strcpy( dest, hdr->src ); // reutrn the name:port for old messages + rstr = dest; + } + } + + return rstr; +}