src/services/route/src/routeSrvMgr.cpp
/**
 * @brief This function is used to get the IP address based on IPv6 or IPv4 is enabled.
 *
 * @param[in] ifname Name of the network interface.
 * @param[out] ipAddressBuffer Character buffer to hold the IP address.
 * @param[in] ipv6Enabled Flag to check whether IPV6 is enabled
 *
 * @return Returns an integer value '1' if successfully gets the IP address else returns '0'.
 * @ingroup
 */
@brief This function is used to get the IP address based on IPv6 or IPv4 is enabled.
@param[in] ifname Name of the network interface.
@param[out] ipAddressBuffer Character buffer to hold the IP address.
@param[in] ipv6Enabled Flag to check whether IPV6 is enabled

@return Returns an integer value '1' if successfully gets the IP address else returns '0'.
@ingroup
@brief This function is used to get the IP address based on IPv6 or IPv4 is enabled . @param [ in ] ifname Name of the network interface . @param [ out ] ipAddressBuffer Character buffer to hold the IP address . @param [ in ] ipv6Enabled Flag to check whether IPV6 is enabled @return Returns an integer value ' 1 ' if successfully gets the IP address else returns ' 0 ' . @ingroup
int RouteNetworkMgr::getipaddress(char* ifname, char* ipAddressBuffer, gboolean ipv6Enabled)
{
    struct ifaddrs * ifAddrStruct=NULL;
    struct ifaddrs * ifa=NULL;
    void * tmpAddrPtr=NULL;
    RDK_LOG( RDK_LOG_TRACE1, LOG_NMGR, "[%s:%s:%d] Enter\n", MODULE_NAME,__FUNCTION__, __LINE__ );
    getifaddrs(&ifAddrStruct);
    int found=0;
    for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) {
        if (ifa->ifa_addr == NULL) continue;
        if (ipv6Enabled == TRUE)
        {   
            if ((strcmp(ifa->ifa_name,ifname)==0) && (ifa ->ifa_addr->sa_family==AF_INET6))
            {
                tmpAddrPtr=&((struct sockaddr_in6  *)ifa->ifa_addr)->sin6_addr;
                inet_ntop(AF_INET6, tmpAddrPtr, ipAddressBuffer, INET6_ADDRSTRLEN);
                if (IN6_IS_ADDR_LINKLOCAL(tmpAddrPtr))
                {
                    found = 1;
                    break;
                }
            }
        }
        else {
            if (ifa ->ifa_addr->sa_family==AF_INET) { 
                tmpAddrPtr=&((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
                inet_ntop(AF_INET, tmpAddrPtr, ipAddressBuffer, INET_ADDRSTRLEN);
                if (strcmp(ifa->ifa_name,ifname)==0)
                {
                    found = 1;
                    break;
                }
            }
        }
    }
    if (ifAddrStruct!=NULL) freeifaddrs(ifAddrStruct);
    RDK_LOG( RDK_LOG_TRACE1, LOG_NMGR, "[%s:%s:%d] Exit\n", MODULE_NAME,__FUNCTION__, __LINE__ );
    return found;
}
int RouteNetworkMgr :: getipaddress ( char * ifname , char * ipAddressBuffer , gboolean ipv6Enabled ) { struct ifaddrs * ifAddrStruct = NULL ; struct ifaddrs * ifa = NULL ; void * tmpAddrPtr = NULL ; RDK_LOG ( RDK_LOG_TRACE1 , LOG_NMGR , " \n " , MODULE_NAME , __FUNCTION__ , __LINE__ ) ; getifaddrs ( & ifAddrStruct ) ; int found = 0 ; for ( ifa = ifAddrStruct ; ifa != NULL ; ifa = ifa -> ifa_next ) { if ( ifa -> ifa_addr == NULL ) continue ; if ( ipv6Enabled == TRUE ) { if ( ( strcmp ( ifa -> ifa_name , ifname ) == 0 ) && ( ifa -> ifa_addr -> sa_family == AF_INET6 ) ) { tmpAddrPtr = & ( ( struct sockaddr_in6 * ) ifa -> ifa_addr ) -> sin6_addr ; inet_ntop ( AF_INET6 , tmpAddrPtr , ipAddressBuffer , INET6_ADDRSTRLEN ) ; if ( IN6_IS_ADDR_LINKLOCAL ( tmpAddrPtr ) ) { found = 1 ; break ; } } } else { if ( ifa -> ifa_addr -> sa_family == AF_INET ) { tmpAddrPtr = & ( ( struct sockaddr_in * ) ifa -> ifa_addr ) -> sin_addr ; inet_ntop ( AF_INET , tmpAddrPtr , ipAddressBuffer , INET_ADDRSTRLEN ) ; if ( strcmp ( ifa -> ifa_name , ifname ) == 0 ) { found = 1 ; break ; } } } } if ( ifAddrStruct != NULL ) freeifaddrs ( ifAddrStruct ) ; RDK_LOG ( RDK_LOG_TRACE1 , LOG_NMGR , " \n " , MODULE_NAME , __FUNCTION__ , __LINE__ ) ; return found ; }
@brief This function is used to get the IP address based on IPv6 or IPv4 is enabled.
@brief This function is used to get the IP address based on IPv6 or IPv4 is enabled .
//char addressBuffer[INET_ADDRSTRLEN] = NULL; // check it is IP6 // is a valid IP6 Address //if (strcmp(ifa->ifa_name,"eth0")==0trcmp0(g_strstrip(devConf->mocaMacIf),ifname) == 0) // check it is IP4 // is a valid IP4 Address //if (strcmp(ifa->ifa_name,"eth0")==0)