From: deraadt Date: Thu, 2 May 1996 13:06:53 +0000 (+0000) Subject: - don't use if_index to get the number of interfaces in SIOCGIFNUM; compute X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=df691e24692c6fa4c75ce61271fa62a4ed8dbb82;p=openbsd - don't use if_index to get the number of interfaces in SIOCGIFNUM; compute the actual number. - forgot to copyout the result in SIOGCIFFLAGS. --- diff --git a/sys/compat/svr4/svr4_sockio.c b/sys/compat/svr4/svr4_sockio.c index 68fb6406ea3..21a74af1c72 100644 --- a/sys/compat/svr4/svr4_sockio.c +++ b/sys/compat/svr4/svr4_sockio.c @@ -1,5 +1,5 @@ -/* $OpenBSD: svr4_sockio.c,v 1.4 1996/04/21 22:18:26 deraadt Exp $ */ -/* $NetBSD: svr4_sockio.c,v 1.8 1996/04/11 12:54:44 christos Exp $ */ +/* $OpenBSD: svr4_sockio.c,v 1.5 1996/05/02 13:06:53 deraadt Exp $ */ +/* $NetBSD: svr4_sockio.c,v 1.9 1996/04/22 01:17:33 christos Exp $ */ /* * Copyright (c) 1995 Christos Zoulas @@ -94,10 +94,34 @@ svr4_sock_ioctl(fp, p, retval, fd, cmd, data) switch (cmd) { case SVR4_SIOCGIFNUM: { - extern int if_index; - - DPRINTF(("SIOCGIFNUM %d\n", if_index)); - return copyout(&if_index, data, sizeof(if_index)); + struct ifnet *ifp; + struct ifaddr *ifa; + int ifnum = 0; + + /* + * This does not return the number of physical + * interfaces (if_index), but the number of interfaces + * + addresses like ifconf() does, because this number + * is used by code that will call SVR4_SIOCGIFCONF to + * find the space needed for SVR4_SIOCGIFCONF. So we + * count the number of ifreq entries that the next + * SVR4_SIOCGIFCONF will return. Maybe a more correct + * fix is to make SVR4_SIOCGIFCONF return only one + * entry per physical interface? + */ + + for (ifp = ifnet.tqh_first; + ifp != 0; ifp = ifp->if_list.tqe_next) + if ((ifa = ifp->if_addrlist.tqh_first) == NULL) + ifnum++; + else + for (;ifa != NULL; + ifa = ifa->ifa_list.tqe_next) + ifnum++; + + + DPRINTF(("SIOCGIFNUM %d\n", ifnum)); + return copyout(&ifnum, data, sizeof(ifnum)); } case SVR4_SIOCGIFFLAGS: @@ -110,13 +134,16 @@ svr4_sock_ioctl(fp, p, retval, fd, cmd, data) (void) strcpy(br.ifr_name, sr.svr4_ifr_name); if ((error = (*ctl)(fp, SIOCGIFFLAGS, - (caddr_t) &br, p)) != 0) + (caddr_t) &br, p)) != 0) { + DPRINTF(("SIOCGIFFLAGS %s: error %d\n", + sr.svr4_ifr_name, error)); return error; + } sr.svr4_ifr_flags = bsd_to_svr4_flags(br.ifr_flags); - DPRINTF(("SIOCGIFFLAGS %s = %d\n", + DPRINTF(("SIOCGIFFLAGS %s = %x\n", sr.svr4_ifr_name, sr.svr4_ifr_flags)); - return 0; + return copyout(&sr, data, sizeof(sr)); } case SVR4_SIOCGIFCONF: @@ -126,6 +153,10 @@ svr4_sock_ioctl(fp, p, retval, fd, cmd, data) if ((error = copyin(data, &sc, sizeof(sc))) != 0) return error; + DPRINTF(("ifreq %d svr4_ifreq %d ifc_len %d\n", + sizeof(struct ifreq), sizeof(struct svr4_ifreq), + sc.svr4_ifc_len)); + if ((error = (*ctl)(fp, OSIOCGIFCONF, (caddr_t) &sc, p)) != 0) return error;