Hi!

(first time poster warning...)

I'm porting an Linux application to FreeBSD, and I've stumbled across
the dreaded SOCK_PACKET and SIOCGIFHWADDR. From what I understand, the
FreeBSD equivaliant of SOCK_PACKET is to use BPF? Do I have to use
that for the SIOCG.. call aswell?

Any hints would be appreciated!

/tobba

The two functions in question:

int
InitSendSocket(char *device_name)
{
  if ((sock_fd = socket(AF_INET, SOCK_PACKET, htons(ETH_P_ALL))) < 0) {
    perror("Socket call failed:");
    exit(-1);
  }

  fcntl(sock_fd, F_SETFL, O_NDELAY);

  sock_addr.sa_family = AF_INET;
  strcpy(sock_addr.sa_data, device_name);

  return sock_fd;
}

void
GetLocalEthAddr()
{
  int fd;
  struct ifreq ifr;

  if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
    perror("socket");
    exit(1);
  }

  strcpy(ifr.ifr_name, device);
  if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
    perror("ioctl");
    exit(1);
  }

  memcpy(eth_addr_local, ifr.ifr_hwaddr.sa_data, 6);
  if (db1) printf("Ethernet adress for device %s is
        %2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x\n", 
        device,
        eth_addr_local[0],
        eth_addr_local[1],
        eth_addr_local[2],
        eth_addr_local[3],
        eth_addr_local[4],
        eth_addr_local[5]);
  shutdown(fd, 2);
}




To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to