Chinaunix首页 | 论坛 | 博客
  • 博客访问: 92240916
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类: C/C++

2008-04-16 17:08:05

作者:blueflame  出处:Unix爱好者家园unix-cd.com   
倒腾了两天,总算是搞掂了 

代码: 
/********************************* begin ********************************/ 

#include  
#include  
#include  
#include  
#include  
#include  

int main(int argc, char *argv[]) 

struct strioctl strioc; 
u_char ether_addr[6]; 
int s; 

if (argc != 2) { 
fprintf(stderr, "usage: %s deviceFile\n", argv[0]); 
exit (1); 


bzero(ether_addr, sizeof(ether_addr)); 

if ((s = open(argv[1], 0)) < 0) { 
perror(argv[1]); 
exit(1); 

strioc.ic_cmd = MACIOC_GETADDR; 
strioc.ic_timout = -1; 
strioc.ic_len = sizeof(ether_addr); 
strioc.ic_dp = (caddr_t) ether_addr; 
if (ioctl(s, I_STR, (char *)&strioc) < 0) { 
perror("I_STR: MACIOC_GETADDR"); 
exit(1); 


printf("%s is using address %02x:%02x:%02x:%02x:%02x:%02x\n"
argv[1], 
ether_addr[0], ether_addr[1], ether_addr[2], 
ether_addr[3], ether_addr[4], ether_addr[5] 
); 

exit(0); 


/********************************** end *********************************/ 

注: 
执行方式如(假设编译出的执行文件为getmac): 
./getmac /dev/net0 

MDI(MAC Driver Interface) 

MACIOC_GETADDR 
向MDI driver发出请求从而获取网卡当前MAC地址 (the current MAC address); 

MACIOC_GETRADDR 
向MDI driver发出请求从而获取网卡厂商MAC地址(the factory MAC address); 

此程序适用于SCO OpenServer和UnixWare,在OpenServer 5.06上测试通过。 

我在尝试使用MACIOC_GETRADDR时提示无效参数,我估计也许是与驱动中没有提供相应的实现有关,因为我在偶然看到的注释版权信息为 
/* 
* Copyright (C) The Santa Cruz Operation, 1993-1995. 
* This Module contains Proprietary Information of 
* The Santa Cruz Operation and should be treated 
* as Confidential. 
*/ 
的AT-2500TX驱动源码中,相应部分只包含了MACIOC_GETADDR的实现,而没有MACIOC_GETRADDR。当然,这只是我的估计,想法未必正确,如果有高手知道其中的原因还望不吝赐教。
阅读(195) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~