龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 操作系统 > LINUX系统 >

在SCO下编程获取网卡MAC地址

时间:2011-03-20 22:37来源:未知 作者:admin 点击:
分享到:
#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,

  #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。

精彩图集

赞助商链接