当前位置: 技术问答>linux和unix
代码移植问题
来源: 互联网 发布时间:2016-09-09
本文导语: #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include #include "sys/socket.h" #include "linux/if_packet.h" #include "linux/if_ether.h" #include ...
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//#include
#include "sys/socket.h"
#include "linux/if_packet.h"
#include "linux/if_ether.h"
#include "linux/if.h"
#include
typedef unsigned short u16;
#include "linux/mii.h"
#include "linux/sockios.h"
#include
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 = "eth7";
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 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;
}
这个代码是linux上用于测试网络断连的,现在要移植到solaris上.
但是有很多变量和头文件都找不到,比如PF_PACKET,SIOCGMIIREG,SIOCGMIIPHY,,linux/if_packet.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//#include
#include "sys/socket.h"
#include "linux/if_packet.h"
#include "linux/if_ether.h"
#include "linux/if.h"
#include
typedef unsigned short u16;
#include "linux/mii.h"
#include "linux/sockios.h"
#include
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 = "eth7";
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 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;
}
这个代码是linux上用于测试网络断连的,现在要移植到solaris上.
但是有很多变量和头文件都找不到,比如PF_PACKET,SIOCGMIIREG,SIOCGMIIPHY,,linux/if_packet.h"
|
这个你得下一个solaris的编程文档看看,相应的API以及头文件就可以了!