views:

73

answers:

2

Hello,

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: Things I've tried -

  1. Making sure I'm running as root

  2. Compiling under linux 2.6.27.7-9-pae and an intel machine, under which it works fine (gcc 4.4.1)

  3. 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

+2  A: 

Do you have CONFIG_PACKET defined in your kernel config? That's required for AF_PACKET.

JayM
why, no... and in an older device running a different version of linux it is defined. I'll give it a try and keep you posted. Thanks!
Oren Shklarsky
That solved it.Thank you.
Oren Shklarsky
A: 

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():");
    }
DRL