I'm using FriendlyARM with linux 2.6.29 and compiling with ARM-Linux GCC 4.3.2
When trying to open a socket with PF_PACKET it fails with errno 97, Address family not supported by protocol.
This is an example program that illustrates the problem -
#include <stdio.h>
#include <sys/socket.h>
#include <netpacket/packet.h>
#include <net/ethernet.h>
//#include <linux/if_packet.h>
//#include <linux/if_ether.h>
#include <errno.h>
int main() {
int sockfd = socket(PF_PACKET, SOCK_RAW, htons(ETHER_TYPE));
if (sockfd < 0)
perror("Can't open socket");
}
Any ideas why this is happening?
Thanks in advance
Oren
edit: Thing开发者_如何转开发s I've tried -
Making sure I'm running as root
Compiling under linux 2.6.27.7-9-pae and an intel machine, under which it works fine (gcc 4.4.1)
The post below suggests that it has something to do with the linux version but based on the above I think it might be something else. link text
Do you have CONFIG_PACKET defined in your kernel config? That's required for AF_PACKET.
If you can do without the link layer you can try with PF_INET:
if((isock = socket(PF_INET, SOCK_RAW, htons(ETH_P_IP))) == -1){
perror("socket():");
}
Again with this the kernel handles the Link layer.
Or with SOCK_DGRAM:
if((rsock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) == -1){
perror("socket():");
}
精彩评论