Extract common code into subroutine svr4_count_ifnum().
Don't open-code queue(3) macros (x = ifnet.tqh_first; y = x.if_list.tqe_next). Instead, use the macros themselves. Use IFNET_FOREACH() and IFADDR_FOREACH().
This commit is contained in:
parent
cabaa89d1f
commit
5a740a2a51
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: svr4_sockio.c,v 1.31 2007/12/04 18:40:24 dsl Exp $ */
|
||||
/* $NetBSD: svr4_sockio.c,v 1.32 2007/12/05 01:10:47 dyoung Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1995 The NetBSD Foundation, Inc.
|
||||
@ -37,7 +37,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: svr4_sockio.c,v 1.31 2007/12/04 18:40:24 dsl Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: svr4_sockio.c,v 1.32 2007/12/05 01:10:47 dyoung Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/proc.h>
|
||||
@ -91,6 +91,18 @@ bsd_to_svr4_flags(bf)
|
||||
return sf;
|
||||
}
|
||||
|
||||
int
|
||||
svr4_count_ifnum(struct ifnet *ifp)
|
||||
{
|
||||
struct ifaddr *ifa;
|
||||
int ifnum = 0;
|
||||
|
||||
IFADDR_FOREACH(ifa, ifp)
|
||||
ifnum++;
|
||||
|
||||
return MAX(1, ifnum);
|
||||
}
|
||||
|
||||
int
|
||||
svr4_sock_ioctl(struct file *fp, struct lwp *l, register_t *retval,
|
||||
int fd, u_long cmd, void *data)
|
||||
@ -105,7 +117,6 @@ svr4_sock_ioctl(struct file *fp, struct lwp *l, register_t *retval,
|
||||
case SVR4_SIOCGLIFNUM:
|
||||
{
|
||||
struct ifnet *ifp;
|
||||
struct ifaddr *ifa;
|
||||
struct svr4_lifnum lifnum;
|
||||
|
||||
error = copyin(data, &lifnum, sizeof(lifnum));
|
||||
@ -114,14 +125,8 @@ svr4_sock_ioctl(struct file *fp, struct lwp *l, register_t *retval,
|
||||
|
||||
lifnum.lifn_count = 0;
|
||||
/* XXX: We don't pay attention to family or flags */
|
||||
for (ifp = ifnet.tqh_first;
|
||||
ifp != 0; ifp = ifp->if_list.tqe_next)
|
||||
if ((ifa = ifp->if_addrlist.tqh_first) == NULL)
|
||||
lifnum.lifn_count++;
|
||||
else
|
||||
for (;ifa != NULL;
|
||||
ifa = ifa->ifa_list.tqe_next)
|
||||
lifnum.lifn_count++;
|
||||
IFNET_FOREACH(ifp)
|
||||
lifnum.lifn_count += svr4_count_ifnum(ifp);
|
||||
|
||||
DPRINTF(("SIOCGLIFNUM [family=%d,flags=%d,count=%d]\n",
|
||||
lifnum.lifn_family, lifnum.lifn_flags,
|
||||
@ -132,7 +137,6 @@ svr4_sock_ioctl(struct file *fp, struct lwp *l, register_t *retval,
|
||||
case SVR4_SIOCGIFNUM:
|
||||
{
|
||||
struct ifnet *ifp;
|
||||
struct ifaddr *ifa;
|
||||
int ifnum = 0;
|
||||
|
||||
/*
|
||||
@ -147,15 +151,8 @@ svr4_sock_ioctl(struct file *fp, struct lwp *l, register_t *retval,
|
||||
* 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++;
|
||||
|
||||
IFNET_FOREACH(ifp)
|
||||
ifnum += svr4_count_ifnum(ifp);
|
||||
|
||||
DPRINTF(("SIOCGIFNUM %d\n", ifnum));
|
||||
return copyout(&ifnum, data, sizeof(ifnum));
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: svr4_sockio.h,v 1.7 2007/03/04 06:01:33 christos Exp $ */
|
||||
/* $NetBSD: svr4_sockio.h,v 1.8 2007/12/05 01:10:47 dyoung Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1995 The NetBSD Foundation, Inc.
|
||||
@ -195,4 +195,8 @@ struct svr4_ifconf {
|
||||
#define SVR4_SIOCGLIFFLAGS SVR4_IOWR('i', 117, struct svr4_lifreq)
|
||||
#define SVR4_SIOCGLIFNUM SVR4_IOWR('i', 130, struct svr4_lifnum)
|
||||
|
||||
#ifdef _KERNEL
|
||||
int svr4_count_ifnum(struct ifnet *);
|
||||
#endif /* _KERNEL */
|
||||
|
||||
#endif /* !_SVR4_SOCKIO_H_ */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: svr4_32_sockio.c,v 1.17 2007/12/04 18:40:26 dsl Exp $ */
|
||||
/* $NetBSD: svr4_32_sockio.c,v 1.18 2007/12/05 01:10:47 dyoung Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1995 The NetBSD Foundation, Inc.
|
||||
@ -37,7 +37,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: svr4_32_sockio.c,v 1.17 2007/12/04 18:40:26 dsl Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: svr4_32_sockio.c,v 1.18 2007/12/05 01:10:47 dyoung Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/proc.h>
|
||||
@ -110,7 +110,6 @@ svr4_32_sock_ioctl(fp, l, retval, fd, cmd, data)
|
||||
case SVR4_SIOCGIFNUM:
|
||||
{
|
||||
struct ifnet *ifp;
|
||||
struct ifaddr *ifa;
|
||||
int ifnum = 0;
|
||||
|
||||
/*
|
||||
@ -125,15 +124,8 @@ svr4_32_sock_ioctl(fp, l, retval, fd, cmd, data)
|
||||
* 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++;
|
||||
|
||||
IFNET_FOREACH(ifp)
|
||||
ifnum += svr4_count_ifnum(ifp)
|
||||
|
||||
DPRINTF(("SIOCGIFNUM %d\n", ifnum));
|
||||
return copyout(&ifnum, data, sizeof(ifnum));
|
||||
|
Loading…
Reference in New Issue
Block a user