首页 > 代码库 > 获取 Mac 地址 (VC)

获取 Mac 地址 (VC)

 1 int getMAC(char * mac)      2 {      3     NCB ncb;      4     LANA_ENUM lana_enum; 5     UCHAR uRetCode; 6     memset(&ncb, 0, sizeof(ncb)); 7     memset(&lana_enum, 0, sizeof(lana_enum)); 8     ncb.ncb_command = NCBENUM; 9     ncb.ncb_buffer = (unsigned char *)&lana_enum;10     ncb.ncb_length = sizeof(LANA_ENUM);11     uRetCode = Netbios(&ncb);12     if(uRetCode != NRC_GOODRET)     13         return uRetCode;     14     for(int lana=0; lana<lana_enum.length; lana++)     15     {16         ncb.ncb_command = NCBRESET;17         ncb.ncb_lana_num = lana_enum.lana[lana];18         uRetCode = Netbios(&ncb);19         if(uRetCode == NRC_GOODRET)20             break; 21     } 22     if(uRetCode != NRC_GOODRET)23         return uRetCode;     24     memset(&ncb, 0, sizeof(ncb));25     ncb.ncb_command = NCBASTAT;26     ncb.ncb_lana_num = lana_enum.lana[0];27     strcpy((char*)ncb.ncb_callname, "*");28     ncb.ncb_buffer = (unsigned char *)&Adapter;29     ncb.ncb_length = sizeof(Adapter);30     uRetCode = Netbios(&ncb);31     if(uRetCode != NRC_GOODRET)32         return uRetCode;33     sprintf(mac,"%02X-%02X-%02X-%02X-%02X-%02X",34         Adapter.adapt.adapter_address[0],35         Adapter.adapt.adapter_address[1],36         Adapter.adapt.adapter_address[2],37         Adapter.adapt.adapter_address[3],38         Adapter.adapt.adapter_address[4],39         Adapter.adapt.adapter_address[5]);40     return 0;   41 } 

 

获取 Mac 地址 (VC)