No empty .Rs/.Re
[netbsd-mini2440.git] / sys / compat / common / uipc_syscalls_40.c
blob58a4cb5d0fe9601420b6486d0293c472d57727fb
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. */
5 #include <sys/cdefs.h>
6 __KERNEL_RCSID(0, "$NetBSD: uipc_syscalls_40.c,v 1.5 2007/12/05 01:03:30 dyoung Exp $");
8 /*
9 * System call interface to the socket abstraction.
12 #include <sys/param.h>
13 #include <sys/kernel.h>
14 #include <sys/msg.h>
15 #include <sys/sysctl.h>
16 #include <sys/mount.h>
17 #include <sys/syscallargs.h>
18 #include <sys/errno.h>
20 #include <net/if.h>
22 #include <compat/sys/socket.h>
23 #include <compat/sys/sockio.h>
25 #ifdef COMPAT_OIFREQ
27 * Return interface configuration
28 * of system. List may be used
29 * in later ioctl's (above) to get
30 * other information.
32 /*ARGSUSED*/
33 int
34 compat_ifconf(u_long cmd, void *data)
36 struct oifconf *ifc = data;
37 struct ifnet *ifp;
38 struct ifaddr *ifa;
39 struct oifreq ifr, *ifrp;
40 int space, error = 0;
41 const int sz = (int)sizeof(ifr);
43 if ((ifrp = ifc->ifc_req) == NULL)
44 space = 0;
45 else
46 space = ifc->ifc_len;
47 IFNET_FOREACH(ifp) {
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')
51 return ENAMETOOLONG;
52 if (IFADDR_EMPTY(ifp)) {
53 memset(&ifr.ifr_addr, 0, sizeof(ifr.ifr_addr));
54 if (space >= sz) {
55 error = copyout(&ifr, ifrp, sz);
56 if (error != 0)
57 return (error);
58 ifrp++;
60 space -= sizeof(ifr);
61 continue;
64 IFADDR_FOREACH(ifa, ifp) {
65 struct sockaddr *sa = ifa->ifa_addr;
66 #ifdef COMPAT_OSOCK
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))
74 continue;
75 memcpy(&ifr.ifr_addr, sa, sa->sa_len);
76 osa->sa_family = sa->sa_family;
77 if (space >= sz) {
78 error = copyout(&ifr, ifrp, sz);
79 ifrp++;
81 } else
82 #endif
83 if (sa->sa_len <= sizeof(*sa)) {
84 memcpy(&ifr.ifr_addr, sa, sa->sa_len);
85 if (space >= sz) {
86 error = copyout(&ifr, ifrp, sz);
87 ifrp++;
89 } else {
90 space -= sa->sa_len - sizeof(*sa);
91 if (space >= sz) {
92 error = copyout(&ifr, ifrp,
93 sizeof(ifr.ifr_name));
94 if (error == 0) {
95 error = copyout(sa,
96 &ifrp->ifr_addr,
97 sa->sa_len);
99 ifrp = (struct oifreq *)
100 (sa->sa_len +
101 (char *)&ifrp->ifr_addr);
104 if (error != 0)
105 return (error);
106 space -= sz;
109 if (ifrp != NULL)
110 ifc->ifc_len -= space;
111 else
112 ifc->ifc_len = -space;
113 return (0);
115 #endif