Michael VanLoon <[EMAIL PROTECTED]> writes:

> Thanks that's just exactly the information I was looking for. :-)
> 
> I'm slow grunging through the code and man pages that take this apart.
> 
> As far as UNPv1 I assume you're referring to Stevens' "Unix Network
> Programming"? If I'm not mistaken he doesn't go much below the
> socket level. A quick glance through didn't reveal anything of this
> nature.

See UNIX Network Programming 2ed, Vol.1, pp434-435 for SIOCGIFCONF
explanation. But nowadays getifaddrs(3) is easier:

/* hacked from netbsd ifconfig.c */

#include <sys/types.h>
#include <sys/socket.h>
#include <ifaddrs.h>
#include <stdio.h>
#include <net/if_dl.h>

int main (void) {

  struct ifaddrs *ifap, *ifaphead;
  int rtnerr;
  const struct sockaddr_dl *sdl;
  caddr_t ap;
  int alen;

  rtnerr = getifaddrs(&ifaphead);
  if (rtnerr) {
    perror(NULL);
    return 1;
  }

  for (ifap = ifaphead; ifap; ifap = ifap->ifa_next) {

    if (ifap->ifa_addr->sa_family == AF_LINK) {
      sdl = (const struct sockaddr_dl *) ifap->ifa_addr;
      ap = ((caddr_t)((sdl)->sdl_data + (sdl)->sdl_nlen));
      alen = sdl->sdl_alen;
      if (ap && alen > 0) {
        int i;

        printf ("%s:", ifap->ifa_name);
        for (i = 0; i < alen; i++, ap++)
          printf("%c%02x", i > 0 ? ':' : ' ', 0xff&*ap);
        putchar('\n');
      }
    }
  }
  putchar('\n');

  freeifaddrs(ifaphead);
  return 0;
}


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

Reply via email to