linux嵌入式设备获取mac地址

2019-07-12 16:06发布

#include int main() { unsigned char mac[6]; char *strmac = "01:02:03:0a:0b:ef"; sscanf(strmac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]); printf("mac: %hhx:%hhx:%hhx:%hhx:%hhx:%hhx ", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); return 0; } 注意:不可用%02x,要用%hhx