关于代码移植
#include <sys/types.h>
#include <sys/mii.h>
#include <string.h>
#include <stdlib.h>
#include <sys/sockio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if_arp.h>
#include <netinet/if_ether.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <errno.h>
#include <net/if.h>
#include <unistd.h>
#include <stropts.h>
typedef unsigned short u16;
//#include <net/if.h>
//#include "sys/socket.h"
//#include "linux/if_packet.h"
//#include "linux/if_ether.h"
//#include <linux/in.h>
//#include "linux/sockios.h"
//#include <linux/hdreg.h>
int main(unsigned int argc, unsigned char *argv[])
{
int sock_fd;
int if_index;
struct sockaddr if_hwaddr;
struct sockaddr_ll addr;
struct ifreq ifr;
struct mii_ioctl_data *data;
unsigned char *pPortName = "bge0";
unsigned int regid = 1;
if (NULL == pPortName)
{
printf("the pPortName is null.n");
return -1;
}
/*建立一个socket连接*/
sock_fd = socket(PF_PACKET, SOCK_RAW, PACKET_HOST);
if (sock_fd < 0)
{
printf("Can not create a packet socket.n");
return -1;
}
memset(&ifr, 0, sizeof(ifr));
strcpy (ifr.ifr_name, pPortName);
/*获取网口的phy id*/
if (ioctl(sock_fd, SIOCGMIIPHY, &ifr) != 0)
{
close(sock_fd);
printf("Can not get the mii phy id of the port.n");
return -1;
}
data = if_mii(&ifr);
/*获取网口的phy reg的值*/
data->reg_num = regid;
if (ioctl(sock_fd, SIOCGMIIREG, &ifr) != 0)
{
close(sock_fd);
printf("Can not get the mii phy reg 0 val.n");
return -1;
}
close(sock_fd);
printf("Socket id[%d], value[0x%x]n", regid, data->val_out);
return 0;
}
这段代码是测试网线有没有插好
现在要移植到solaris上,可是头文件都找不到...
那位高人帮忙解决一下~
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论