|
|
倒腾了两天,总算是搞掂了
代码:
/********************************* begin ********************************/
#include <stdio.h>
#include <sys/types.h>
#include <strings.h>
#include <sys/stream.h>
#include <sys/stropts.h>
#include <sys/macstat.h>
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。当然,这只是我的估计,想法未必正确,如果有高手知道其中的原因还望不吝赐教。
| aly 回复于:2004-04-09 07:58:46
| linux下面不能用吗?
测试通不过啊
| | blueflame 回复于:2004-04-09 09:17:16
| 呵呵,不行,这个MDI是SCO的
其他系统的你可以参阅gadfly写的那篇
http://www.chinaunix.net/jh/23/85716.html
BTW: Linux不是开源的嘛,你想要的话只接找到它的相应实现源码不就行咯
| | hs_49 回复于:2004-04-09 15:55:21
| 谁知道在SCO下用recvfrom函数如何接收到IP头这层数据(发送端也用原始套接字UDP协议)
例如:
int sendtcp(void)
{
1)sock=socket(AF_NET, SOCK_RAW, IPPROTO_UDP)
2)填充IP
3)sendto(sock)//发送数据
}
int recvtcp(void)
{
1)sock=socket(AF_NET,SOCK_RAW,IPPROTO_UDP)
2)??
3)recvfrom(sock)//接收数据
}
我的程序只能收到数据这层但接收不到IP头及UDP头
请问如何才能够收到这层?
(WINDOW中的可以利用socketioctl(sock,RCV_ALL,&VAL)函数来设置可以收到所有数据)
但SCOUNIX下就不知道如何设置了??????
谢谢各位朋友!
| |
|