代码移植问题
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/mman.h>
#include <stdarg.h>
#include <pthread.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <malloc.h>
#include <string.h>
#include <assert.h>
//#include <net/if.h>
#include "sys/socket.h"
#include "linux/if_packet.h"
#include "linux/if_ether.h"
#include "linux/if.h"
#include <linux/in.h>
typedef unsigned short u16;
#include "linux/mii.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 = "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 < 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;
}
这个代码是linux上用于测试网络断连的,现在要移植到solaris上.
但是有很多变量和头文件都找不到,比如PF_PACKET,SIOCGMIIREG,SIOCGMIIPHY,<linux/hdreg.h>,linux/if_packet.h"
[解决办法]
这个你得下一个solaris的编程文档看看,相应的API以及头文件就可以了!