获得mac你需要root权限,除非你修改/dev/hme的权限。
源程序如下
/****************** cut here ******************/
#include
#include
#include
main()
{
int fd;
int flag=0;
unsigned char buf[32];
struct strbuf sb;
struct pollfd fds[1];
sb.maxlen=sizeof(buf);
sb.buf=(char *)buf;
fd=open("/dev/hme", O_RDWR);
if (fd<0)
{
perror("Error";
return(1);
}
fds[0].fd=fd;
fds[0].events=POLLRDNORM ¦POLLRDBAND ¦POLLIN ¦POLLPRI;
memset(buf, 0, sizeof(buf));
sb.len=8;
buf[3]=0x0B;
putmsg(fd, &sb, NULL, 0);
poll(fds, 1, 60000);
getmsg(fd, &sb, NULL, &flag);
memset(buf, 0, sizeof(buf));
sb.len=8;
buf[3]=0x31;
buf[7]=0x02;
putmsg(fd, &sb, NULL, 0);
poll(fds, 1, 60000);
getmsg(fd, &sb, NULL, &flag);
close(fd);
printf("%02X:%02X:%02X:%02X:%02X:%02X\n",
buf[12], buf[13], buf[14],
buf[15], buf[16], buf[17]);
return(0);
}
阅读(527) | 评论(0) | 转发(0) |