src/main/src/netsrvmgrUtiles.cpp
/**
 * @fn netSrvMgrUtiles::getMacAddress_IfName(const char *ifName_in, char *macAddress_out)
 * @brief This function gets the MAC address of the AspectRatio against the id specified, only if
 * the id passed is valid.
 *
 * @param[in] ifName_in Indicates the interface name which the mac address is required.
 * @param[out] macAddress_out Indicates the mac address of ifname_in interface name.
 *
 * @return Returns true if successfully gets the mac address of interface provided or else false.
 */
@fn netSrvMgrUtiles::getMacAddress_IfName(const char *ifName_in, char *macAddress_out)
@brief This function gets the MAC address of the AspectRatio against the id specified, only if
the id passed is valid.

@param[in] ifName_in Indicates the interface name which the mac address is required.
@param[out] macAddress_out Indicates the mac address of ifname_in interface name.

@return Returns true if successfully gets the mac address of interface provided or else false.
@fn netSrvMgrUtiles :: getMacAddress_IfName ( const char * ifName_in char * macAddress_out ) @brief This function gets the MAC address of the AspectRatio against the id specified only if the id passed is valid . @param [ in ] ifName_in Indicates the interface name which the mac address is required . @param [ out ] macAddress_out Indicates the mac address of ifname_in interface name . @return Returns true if successfully gets the mac address of interface provided or else false .
bool netSrvMgrUtiles::getMacAddress_IfName(const char *ifName_in, char macAddress_out[MAC_ADDR_BUFF_LEN])
{
    struct ifreq ifr;
    int sd;
    unsigned char *mac = NULL;
    bool ret = false;
    RDK_LOG(RDK_LOG_TRACE1, LOG_NMGR,"[%s:%d]Enter\n", __FUNCTION__, __LINE__);
    if(NULL == ifName_in)
    {
        RDK_LOG(RDK_LOG_TRACE1, LOG_NMGR,"[%s:%d] Failed, due to NULL for interface name (\'ifName_in\') .\n", __FUNCTION__, __LINE__);
        return ret;
    }
    sd = socket(AF_INET, SOCK_DGRAM, 0);
    if (sd > 0) {
        ifr.ifr_addr.sa_family = AF_INET;
        strncpy(ifr.ifr_name, ifName_in, IFNAMSIZ-1);
        if (0 == ioctl(sd, SIOCGIFHWADDR, &ifr)) {
            mac = (unsigned char *) ifr.ifr_hwaddr.sa_data;
            if(mac) {
                snprintf( macAddress_out, MAC_ADDR_BUFF_LEN, "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
                RDK_LOG(RDK_LOG_DEBUG,LOG_NMGR,"[%s:%d]The Mac address is \'%s\' (for provided interface %s).\n", __FUNCTION__, __LINE__, macAddress_out, ifName_in );
                ret = true;
            }
        }
        else {
            RDK_LOG(RDK_LOG_ERROR,LOG_NMGR,"[%s:%d] Failed in ioctl() with  \'%s\'..\n", __FUNCTION__, __LINE__, strerror (errno) );
        }
        close(sd);
    }
    else {
        RDK_LOG(RDK_LOG_ERROR,LOG_NMGR,"[%s:%d] Failed to create socket() with \'%s\' return as \'%d\'.\n", __FUNCTION__, __LINE__, sd, strerror (errno) );
    }
    RDK_LOG(RDK_LOG_TRACE1, LOG_NMGR,"[%s:%d]Exit\n", __FUNCTION__, __LINE__);
    return ret;
}
bool netSrvMgrUtiles :: getMacAddress_IfName ( const char * ifName_in , char macAddress_out [ MAC_ADDR_BUFF_LEN ] ) { struct ifreq ifr ; int sd ; unsigned char * mac = NULL ; bool ret = false ; RDK_LOG ( RDK_LOG_TRACE1 , LOG_NMGR , " \n " , __FUNCTION__ , __LINE__ ) ; if ( NULL == ifName_in ) { RDK_LOG ( RDK_LOG_TRACE1 , LOG_NMGR , " \' \' \n " , __FUNCTION__ , __LINE__ ) ; return ret ; } sd = socket ( AF_INET , SOCK_DGRAM , 0 ) ; if ( sd > 0 ) { ifr . ifr_addr . sa_family = AF_INET ; strncpy ( ifr . ifr_name , ifName_in , IFNAMSIZ - 1 ) ; if ( 0 == ioctl ( sd , SIOCGIFHWADDR , & ifr ) ) { mac = ( unsigned char * ) ifr . ifr_hwaddr . sa_data ; if ( mac ) { snprintf ( macAddress_out , MAC_ADDR_BUFF_LEN , " " , mac [ 0 ] , mac [ 1 ] , mac [ 2 ] , mac [ 3 ] , mac [ 4 ] , mac [ 5 ] ) ; RDK_LOG ( RDK_LOG_DEBUG , LOG_NMGR , " \' \' \n " , __FUNCTION__ , __LINE__ , macAddress_out , ifName_in ) ; ret = true ; } } else { RDK_LOG ( RDK_LOG_ERROR , LOG_NMGR , " \' \' \n " , __FUNCTION__ , __LINE__ , strerror ( errno ) ) ; } close ( sd ) ; } else { RDK_LOG ( RDK_LOG_ERROR , LOG_NMGR , " \' \' \' \' \n " , __FUNCTION__ , __LINE__ , sd , strerror ( errno ) ) ; } RDK_LOG ( RDK_LOG_TRACE1 , LOG_NMGR , " \n " , __FUNCTION__ , __LINE__ ) ; return ret ; }
@fn netSrvMgrUtiles::getMacAddress_IfName(const char *ifName_in, char *macAddress_out)
 @brief This function gets the MAC address of the AspectRatio against the id specified, only if
 the id passed is valid.
@fn netSrvMgrUtiles :: getMacAddress_IfName ( const char * ifName_in char * macAddress_out ) @brief This function gets the MAC address of the AspectRatio against the id specified only if the id passed is valid .