Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / compat / svr4_32 / svr4_32_sockio.c
blobea7b312909448adb9a46f3fda8347d92cf26c972
1 /* $NetBSD: svr4_32_sockio.c,v 1.20 2008/03/21 21:54:59 ad Exp $ */
3 /*-
4 * Copyright (c) 1995, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: svr4_32_sockio.c,v 1.20 2008/03/21 21:54:59 ad Exp $");
35 #include <sys/param.h>
36 #include <sys/proc.h>
37 #include <sys/systm.h>
38 #include <sys/file.h>
39 #include <sys/filedesc.h>
40 #include <sys/ioctl.h>
41 #include <sys/termios.h>
42 #include <sys/tty.h>
43 #include <sys/socket.h>
44 #include <sys/mount.h>
45 #include <net/if.h>
46 #include <sys/malloc.h>
48 #include <sys/syscallargs.h>
50 #include <compat/sys/socket.h>
51 #include <compat/sys/sockio.h>
53 #include <compat/svr4_32/svr4_32_types.h>
54 #include <compat/svr4_32/svr4_32_util.h>
55 #include <compat/svr4_32/svr4_32_signal.h>
56 #include <compat/svr4_32/svr4_32_lwp.h>
57 #include <compat/svr4_32/svr4_32_ucontext.h>
58 #include <compat/svr4_32/svr4_32_syscallargs.h>
59 #include <compat/svr4_32/svr4_32_stropts.h>
60 #include <compat/svr4_32/svr4_32_ioctl.h>
61 #include <compat/svr4_32/svr4_32_sockio.h>
63 static int bsd_to_svr4_flags(int);
65 #define bsd_to_svr4_flag(a) \
66 if (bf & __CONCAT(I,a)) sf |= __CONCAT(SVR4_I,a)
68 static int
69 bsd_to_svr4_flags(int bf)
71 int sf = 0;
72 bsd_to_svr4_flag(FF_UP);
73 bsd_to_svr4_flag(FF_BROADCAST);
74 bsd_to_svr4_flag(FF_DEBUG);
75 bsd_to_svr4_flag(FF_LOOPBACK);
76 bsd_to_svr4_flag(FF_POINTOPOINT);
77 bsd_to_svr4_flag(FF_NOTRAILERS);
78 bsd_to_svr4_flag(FF_RUNNING);
79 bsd_to_svr4_flag(FF_NOARP);
80 bsd_to_svr4_flag(FF_PROMISC);
81 bsd_to_svr4_flag(FF_ALLMULTI);
82 bsd_to_svr4_flag(FF_MULTICAST);
83 return sf;
86 int
87 svr4_32_sock_ioctl(file_t *fp, struct lwp *l, register_t *retval, int fd, u_long cmd, void *data)
89 int error;
90 int (*ctl)(file_t *, u_long, void *) = fp->f_ops->fo_ioctl;
92 *retval = 0;
94 switch (cmd) {
95 case SVR4_SIOCGIFNUM:
97 struct ifnet *ifp;
98 int ifnum = 0;
101 * This does not return the number of physical
102 * interfaces (if_index), but the number of interfaces
103 * + addresses like ifconf() does, because this number
104 * is used by code that will call SVR4_SIOCGIFCONF to
105 * find the space needed for SVR4_SIOCGIFCONF. So we
106 * count the number of ifreq entries that the next
107 * SVR4_SIOCGIFCONF will return. Maybe a more correct
108 * fix is to make SVR4_SIOCGIFCONF return only one
109 * entry per physical interface?
112 IFNET_FOREACH(ifp)
113 ifnum += svr4_count_ifnum(ifp)
115 DPRINTF(("SIOCGIFNUM %d\n", ifnum));
116 return copyout(&ifnum, data, sizeof(ifnum));
119 case SVR4_32_SIOCGIFFLAGS:
121 struct oifreq br;
122 struct svr4_32_ifreq sr;
124 if ((error = copyin(data, &sr, sizeof(sr))) != 0)
125 return error;
127 (void) strncpy(br.ifr_name, sr.svr4_ifr_name,
128 sizeof(br.ifr_name));
130 if ((error = (*ctl)(fp, SIOCGIFFLAGS, &br)) != 0) {
131 DPRINTF(("SIOCGIFFLAGS %s: error %d\n",
132 sr.svr4_ifr_name, error));
133 return error;
136 sr.svr4_ifr_flags = bsd_to_svr4_flags(br.ifr_flags);
137 DPRINTF(("SIOCGIFFLAGS %s = %x\n",
138 sr.svr4_ifr_name, sr.svr4_ifr_flags));
139 return copyout(&sr, data, sizeof(sr));
142 case SVR4_32_SIOCGIFCONF:
144 struct svr4_32_ifconf sc;
145 struct oifconf ifc;
147 if ((error = copyin(data, &sc, sizeof(sc))) != 0)
148 return error;
150 DPRINTF(("ifreq %ld svr4_32_ifreq %ld ifc_len %d\n",
151 (unsigned long)sizeof(struct oifreq),
152 (unsigned long)sizeof(struct svr4_32_ifreq),
153 sc.svr4_32_ifc_len));
155 ifc.ifc_len = sc.svr4_32_ifc_len;
156 ifc.ifc_buf = NETBSD32PTR64(sc.ifc_ifcu.ifcu_buf);
158 if ((error = (*ctl)(fp, OOSIOCGIFCONF, &ifc)) != 0)
159 return error;
161 DPRINTF(("SIOCGIFCONF\n"));
162 return 0;
166 default:
167 DPRINTF(("Unknown svr4_32 sockio %lx\n", cmd));
168 return 0; /* ENOSYS really */