socket(): Address family not supported by protocol?
问题:
在X86平台,在PPC平台,以下程序运行正常,在ARM9平台下编译都通过了,但是一运行出现如下错误
socket(): Address family not supported by protocol
尝试了更改内核驱动,加载模块,还是没找到问题所在!
感觉还是哪里协议栈的问题请大侠指点!
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <netinet/tcp.h>
#include <linux/sockios.h>
#include <net/if.h>
#include <net/route.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
typedef struct sockaddr SA;
int main()
{
int sockfd;
struct sockaddr_ll sll;
struct ifreq ifr;
sockfd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if(sockfd < 0)
{
perror("socket()");
return -1;
}
memset(&sll, 0, sizeof(sll));
strcpy(ifr.ifr_name, "eth0");
ioctl(sockfd, SIOCGIFINDEX, &ifr);
sll.sll_family = AF_PACKET;
sll.sll_ifindex = ifr.ifr_ifindex;
sll.sll_protocol = htons(ETH_P_ALL);
if(bind(sockfd, (SA *)&sll, sizeof(sll)) < 0)
{
perror("bind()");
return -1;
}
return sockfd;
}