1 /* $NetBSD: uipc_syscalls_40.c,v 1.5 2007/12/05 01:03:30 dyoung Exp $ */
3 /* written by Pavel Cahyna, 2006. Public domain. */
6 __KERNEL_RCSID(0, "$NetBSD: uipc_syscalls_40.c,v 1.5 2007/12/05 01:03:30 dyoung Exp $");
9 * System call interface to the socket abstraction.
12 #include <sys/param.h>
13 #include <sys/kernel.h>
15 #include <sys/sysctl.h>
16 #include <sys/mount.h>
17 #include <sys/syscallargs.h>
18 #include <sys/errno.h>
22 #include <compat/sys/socket.h>
23 #include <compat/sys/sockio.h>
27 * Return interface configuration
28 * of system. List may be used
29 * in later ioctl's (above) to get
34 compat_ifconf(u_long cmd
, void *data
)
36 struct oifconf
*ifc
= data
;
39 struct oifreq ifr
, *ifrp
;
41 const int sz
= (int)sizeof(ifr
);
43 if ((ifrp
= ifc
->ifc_req
) == NULL
)
48 (void)strncpy(ifr
.ifr_name
, ifp
->if_xname
,
49 sizeof(ifr
.ifr_name
));
50 if (ifr
.ifr_name
[sizeof(ifr
.ifr_name
) - 1] != '\0')
52 if (IFADDR_EMPTY(ifp
)) {
53 memset(&ifr
.ifr_addr
, 0, sizeof(ifr
.ifr_addr
));
55 error
= copyout(&ifr
, ifrp
, sz
);
64 IFADDR_FOREACH(ifa
, ifp
) {
65 struct sockaddr
*sa
= ifa
->ifa_addr
;
67 if (cmd
== OOSIOCGIFCONF
) {
68 struct osockaddr
*osa
=
69 (struct osockaddr
*)&ifr
.ifr_addr
;
71 * If it does not fit, we don't bother with it
73 if (sa
->sa_len
> sizeof(*osa
))
75 memcpy(&ifr
.ifr_addr
, sa
, sa
->sa_len
);
76 osa
->sa_family
= sa
->sa_family
;
78 error
= copyout(&ifr
, ifrp
, sz
);
83 if (sa
->sa_len
<= sizeof(*sa
)) {
84 memcpy(&ifr
.ifr_addr
, sa
, sa
->sa_len
);
86 error
= copyout(&ifr
, ifrp
, sz
);
90 space
-= sa
->sa_len
- sizeof(*sa
);
92 error
= copyout(&ifr
, ifrp
,
93 sizeof(ifr
.ifr_name
));
99 ifrp
= (struct oifreq
*)
101 (char *)&ifrp
->ifr_addr
);
110 ifc
->ifc_len
-= space
;
112 ifc
->ifc_len
= -space
;