获取mac地址并以十六进制格式加冒号分隔显示

     unsigned char* getMacAddr()
{
    char output[wifi_length] = {0};
    int rec_size = 0;
    int rec_num = 0;
    unsigned char w_wifi[wifi_length];
    unsigned char* macAddr;
    int ret, length = 0, i = 0;
    char value[13] = {0};
            nvram_fd = NVM_GetFileDesc(AP_CFG_RDEB_FILE_WIFI_LID, &rec_size, &rec_num, ISREAD);
            printf("rec_size=%d,rec_num=%d\n",rec_size,rec_num);
            if(1 != rec_num)
            {
                printf("error:unexpected record num %d\n",rec_num);
                //sprintf(cmd->result, "%s", return_err);
                return NULL;
            }
            if(sizeof(WIFI_CFG_PARAM_STRUCT) != rec_size)
            {
                printf("error:unexpected record size %d\n",rec_size);
                //sprintf(cmd->result, "%s", return_err);
                return NULL;
            }
            memset(&g_wifi_nvram,0,rec_num*rec_size);
            ret = read(nvram_fd.iFileDesc, &g_wifi_nvram, rec_num*rec_size);
            if(-1 == ret||rec_num*rec_size != ret)
            {
                printf("error:read wifi mac addr fail!/n");
                //sprintf(cmd->result, "%s", return_err);
                return NULL;
            }
            printf("read wifi addr:%02x%02x%02x%02x%02x%02x\n",
                    g_wifi_nvram.aucMacAddress[0], g_wifi_nvram.aucMacAddress[1], g_wifi_nvram.aucMacAddress[2], g_wifi_nvram.aucMacAddress[3], g_wifi_nvram.aucMacAddress[4],
            g_wifi_nvram.aucMacAddress[5]);
            NVM_CloseFileDesc(nvram_fd);
              macAddr = g_wifi_nvram.aucMacAddress;
        printf("read wifi addr: %02x\n",macAddr);      
        return macAddr;
}  

   unsigned char* macAddr;

    char macAddr2[100]={0};
    //memset(macAddr2, 0, sizeof(char) * 100);
    macAddr = getMacAddr();
    if(macAddr!=NULL)
    {
        sprintf(macAddr2,"Mac address:%02x :%02x:%02x:%02x:%02x:%02x", macAddr[0],macAddr[1],macAddr[2],macAddr[3],macAddr[4],macAddr[5]);    
        wifi_items[3].name =macAddr2;
    }

你可能感兴趣的:(获取mac地址并以十六进制格式加冒号分隔显示)