当前位置: 技术问答>linux和unix
请问在UNIX取MAC地址的问题,TRU64
来源: 互联网 发布时间:2015-09-02
本文导语: #define ETH_NAME "eth0" GetLocalAddress(char* szIPAddr) { int sock; struct sockaddr_in sin; struct sockaddr sa; struct ifreq ifr; unsigned char mac[6]; ...
#define ETH_NAME "eth0"
GetLocalAddress(char* szIPAddr)
{
int sock;
struct sockaddr_in sin;
struct sockaddr sa;
struct ifreq ifr;
unsigned char mac[6];
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock == -1)
{
perror("Error: get local IP socket fail!");
return false;
}
strncpy(ifr.ifr_name, ETH_NAME, IFNAMSIZ);
ifr.ifr_name[IFNAMSIZ - 1] = 0;
if (ioctl(sock, SIOCGIFADDR, &ifr)
GetLocalAddress(char* szIPAddr)
{
int sock;
struct sockaddr_in sin;
struct sockaddr sa;
struct ifreq ifr;
unsigned char mac[6];
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock == -1)
{
perror("Error: get local IP socket fail!");
return false;
}
strncpy(ifr.ifr_name, ETH_NAME, IFNAMSIZ);
ifr.ifr_name[IFNAMSIZ - 1] = 0;
if (ioctl(sock, SIOCGIFADDR, &ifr)