Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

SIOCGIFCONF ioctl family problems under compat netbsd32



Hi,

There was recently a report that SIOCGIFCONF ioctl doesn't work on
amd64 under compat linux32.

A quick look showed that netbsd32 SIOCGIFCONFs requests were
outdated. The attached patch update them to match the natives ones;
but some problems remains.

Here is a small testcase, i use to exercise SIOCGIFCONF, OSIOCGIFCONF,
and OOSIOCGIFCONF under compat netbsd32.

- OOSIOCGIFCONF, used by compat linux32 seems to work fine.
- OSIOCGIFCONF, used by NetBSD/i386 4.0 binary produce garbage.
- SIOCGIFCONF, use by NetBSD/i386 -current binary seems to work too.

I'm currently looking for fixing the remaining problem for
OSIOCGIFCONF, but got no more clues ...

Any help will be appreciated.
Thanks.

-- 
Nicolas Joly

Biological Software and Databanks.
Institut Pasteur, Paris.
Index: sys/compat/netbsd32/netbsd32_ioctl.c
===================================================================
RCS file: /cvsroot/src/sys/compat/netbsd32/netbsd32_ioctl.c,v
retrieving revision 1.39
diff -u -p -r1.39 netbsd32_ioctl.c
--- sys/compat/netbsd32/netbsd32_ioctl.c        29 May 2008 14:51:26 -0000      
1.39
+++ sys/compat/netbsd32/netbsd32_ioctl.c        23 Jun 2008 08:40:54 -0000
@@ -490,6 +490,8 @@ printf("netbsd32_ioctl(%d, %x, %x): %s g
                IOCTL_STRUCT_CONV_TO(SIOCPHASE2, ifreq);
 #endif
 
+       case OOSIOCGIFCONF32:
+               IOCTL_STRUCT_CONV_TO(OOSIOCGIFCONF, ifconf);
        case OSIOCGIFCONF32:
                IOCTL_STRUCT_CONV_TO(OSIOCGIFCONF, ifconf);
        case SIOCGIFCONF32:
Index: sys/compat/netbsd32/netbsd32_ioctl.h
===================================================================
RCS file: /cvsroot/src/sys/compat/netbsd32/netbsd32_ioctl.h,v
retrieving revision 1.23
diff -u -p -r1.23 netbsd32_ioctl.h
--- sys/compat/netbsd32/netbsd32_ioctl.h        22 Jun 2008 22:40:15 -0000      
1.23
+++ sys/compat/netbsd32/netbsd32_ioctl.h        23 Jun 2008 08:40:54 -0000
@@ -220,8 +220,9 @@ struct      netbsd32_ifconf {
 };
 #if 1
 /* from <sys/sockio.h> */
-#define        OSIOCGIFCONF32  _IOWR('i', 20, struct netbsd32_ifconf)  /* get 
ifnet list */
-#define        SIOCGIFCONF32   _IOWR('i', 36, struct netbsd32_ifconf)  /* get 
ifnet list */
+#define        OOSIOCGIFCONF32 _IOWR('i', 20, struct netbsd32_ifconf)  /* get 
ifnet list */
+#define        OSIOCGIFCONF32  _IOWR('i', 36, struct netbsd32_ifconf)  /* get 
ifnet list */
+#define        SIOCGIFCONF32   _IOWR('i', 38, struct netbsd32_ifconf)  /* get 
ifnet list */
 #endif
 
 /* from <net/if.h> */
#include <arpa/inet.h>
#include <net/if.h>

#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>

#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main() {
  char *buf;
  int res, fd;
  size_t len;
  struct ifconf cnf;
  size_t l;
  struct ifreq *cur;
  struct sockaddr *adr;

  fd = socket(AF_INET, SOCK_DGRAM, 0);
  if (fd == -1)
    err(1, "socket failed");

  len = 20 * sizeof(struct ifreq);
  buf = malloc(len);
  if (buf == NULL)
    err(1, "malloc failed");

  cnf.ifc_buf = buf;
  cnf.ifc_len = len;
  res = ioctl(fd, SIOCGIFCONF, &cnf);
  if (res == -1)
    err(1, "ioctl failed");
  if (cnf.ifc_len == len)
    errx(1, "ioctl data overflow");
  if ((cnf.ifc_len % sizeof(struct ifreq)) != 0)
    errx(1, "ioctl bogus size");

  cur = cnf.ifc_req; l = cnf.ifc_len;
  while (l) {
    adr = (struct sockaddr *)&cur->ifr_addr;
    printf("%s %d\n", cur->ifr_name, (int)adr->sa_family);
    cur++; l -= sizeof(struct ifreq); }

  free(buf);

  res = close(fd);
  if (res == -1)
    err(1, "close failed");

  return 0; }



Home | Main Index | Thread Index | Old Index