Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Sep 2000 11:36:24 +0000 (/etc/localtime)
From:      Tobias Anderberg <tobias.anderberg@axis.com>
To:        freebsd-hackers@FreeBSD.ORG
Subject:   FreeBSD 
Message-ID:  <Pine.LNX.4.21.0009281127300.21011-100000@pctobiasa.axis.se>

next in thread | raw e-mail | index | archive | help
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 majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.LNX.4.21.0009281127300.21011-100000>