[Prev][Next][Index][Thread]

ioctl problem



Hello,

I am using oskit + Vmware to boot the kernels. I have been to test the
httpproxy kernel correctly.

I tried a small program to get all the addresses on a machine (the
freebsd get_myaddress.c). But the program exits after the first ioctl
call. I would be happy if anyone could tell me if there is anything wrong
in the following code.


Thank you
Sarat

//-----------------------------------------------------------


void get_myaddress(addr)
        struct sockaddr_in *addr;
{
        int s;
        char buf[BUFSIZ];
        struct ifconf ifc;
        struct ifreq ifreq, *ifr, *end;

        if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
          perror("get_myaddress: socket");
	  exit(1);
        }
        ifc.ifc_len = sizeof (buf);
        ifc.ifc_buf = buf;

        if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) {
          perror("get_myaddress: ioctl (get interface configuration)");
	  exit(1);//---> program exits here
        }
  //---------------------------


        ifr = ifc.ifc_req;
        end = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);

        while (ifr < end) {
        ifreq = *ifr;
        if (ioctl(s, SIOCGIFFLAGS, (char *)&ifreq) < 0) {
        perror("get_myaddress: ioctl");
        exit(1);
        }
        if ((ifreq.ifr_flags & IFF_UP) &&
        ifr->ifr_addr.sa_family == AF_INET) {
        *addr = *((struct sockaddr_in *)&ifr->ifr_addr);
        addr->sin_port = htons(PMAPPORT);
        break;
        }
        if (ifr->ifr_addr.sa_len)
        ifr = (struct ifreq *) ((caddr_t) ifr +
        ifr->ifr_addr.sa_len -
        sizeof(struct sockaddr));
        ifr++;
        }
        (void) close(s);
        printf("Here\n");
}