-/* $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
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:
(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:
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;