Annotation of sys/compat/svr4/svr4_sockio.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: svr4_sockio.c,v 1.10 2006/03/05 21:48:56 miod Exp $ */
2: /* $NetBSD: svr4_sockio.c,v 1.10 1996/05/03 17:09:15 christos Exp $ */
3:
4: /*
5: * Copyright (c) 1995 Christos Zoulas
6: * All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. The name of the author may not be used to endorse or promote products
17: * derived from this software without specific prior written permission
18: *
19: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29: */
30:
31: #include <sys/param.h>
32: #include <sys/proc.h>
33: #include <sys/systm.h>
34: #include <sys/file.h>
35: #include <sys/filedesc.h>
36: #include <sys/ioctl.h>
37: #include <sys/termios.h>
38: #include <sys/tty.h>
39: #include <sys/socket.h>
40: #include <sys/mount.h>
41: #include <net/if.h>
42: #include <sys/malloc.h>
43:
44: #include <sys/syscallargs.h>
45:
46: #include <compat/svr4/svr4_types.h>
47: #include <compat/svr4/svr4_util.h>
48: #include <compat/svr4/svr4_signal.h>
49: #include <compat/svr4/svr4_syscallargs.h>
50: #include <compat/svr4/svr4_stropts.h>
51: #include <compat/svr4/svr4_ioctl.h>
52: #include <compat/svr4/svr4_sockio.h>
53:
54: static int bsd_to_svr4_flags(int);
55:
56: #define bsd_to_svr4_flag(a) \
57: if (bf & __CONCAT(I,a)) sf |= __CONCAT(SVR4_I,a)
58:
59: static int
60: bsd_to_svr4_flags(bf)
61: int bf;
62: {
63: int sf = 0;
64: bsd_to_svr4_flag(FF_UP);
65: bsd_to_svr4_flag(FF_BROADCAST);
66: bsd_to_svr4_flag(FF_DEBUG);
67: bsd_to_svr4_flag(FF_LOOPBACK);
68: bsd_to_svr4_flag(FF_POINTOPOINT);
69: bsd_to_svr4_flag(FF_NOTRAILERS);
70: bsd_to_svr4_flag(FF_RUNNING);
71: bsd_to_svr4_flag(FF_NOARP);
72: bsd_to_svr4_flag(FF_PROMISC);
73: bsd_to_svr4_flag(FF_ALLMULTI);
74: bsd_to_svr4_flag(FF_MULTICAST);
75: return sf;
76: }
77:
78: int
79: svr4_sock_ioctl(fp, p, retval, fd, cmd, data)
80: struct file *fp;
81: struct proc *p;
82: register_t *retval;
83: int fd;
84: u_long cmd;
85: caddr_t data;
86: {
87: int error;
88: int (*ctl)(struct file *, u_long, caddr_t, struct proc *) =
89: fp->f_ops->fo_ioctl;
90:
91: *retval = 0;
92:
93: switch (cmd) {
94: case SVR4_SIOCGIFNUM:
95: {
96: struct ifnet *ifp;
97: struct ifaddr *ifa;
98: int ifnum = 0;
99:
100: /*
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?
110: */
111:
112: TAILQ_FOREACH(ifp, &ifnet, if_list)
113: if (TAILQ_EMPTY(&ifp->if_addrlist))
114: ifnum++;
115: else
116: TAILQ_FOREACH(ifa, &ifp->if_addrlist,
117: ifa_list)
118: ifnum++;
119:
120:
121: DPRINTF(("SIOCGIFNUM %d\n", ifnum));
122: return copyout(&ifnum, data, sizeof(ifnum));
123: }
124:
125: case SVR4_SIOCGIFFLAGS:
126: {
127: struct ifreq br;
128: struct svr4_ifreq sr;
129:
130: if ((error = copyin(data, &sr, sizeof(sr))) != 0)
131: return error;
132:
133: (void) strlcpy(br.ifr_name, sr.svr4_ifr_name,
134: sizeof(br.ifr_name));
135:
136: if ((error = (*ctl)(fp, SIOCGIFFLAGS,
137: (caddr_t) &br, p)) != 0) {
138: DPRINTF(("SIOCGIFFLAGS %s: error %d\n",
139: sr.svr4_ifr_name, error));
140: return error;
141: }
142:
143: sr.svr4_ifr_flags = bsd_to_svr4_flags(br.ifr_flags);
144: DPRINTF(("SIOCGIFFLAGS %s = %x\n",
145: sr.svr4_ifr_name, sr.svr4_ifr_flags));
146: return copyout(&sr, data, sizeof(sr));
147: }
148:
149: case SVR4_SIOCGIFCONF:
150: {
151: struct svr4_ifconf sc;
152:
153: if ((error = copyin(data, &sc, sizeof(sc))) != 0)
154: return error;
155:
156: DPRINTF(("ifreq %d svr4_ifreq %d ifc_len %d\n",
157: sizeof(struct ifreq), sizeof(struct svr4_ifreq),
158: sc.svr4_ifc_len));
159:
160: if ((error = (*ctl)(fp, OSIOCGIFCONF,
161: (caddr_t) &sc, p)) != 0)
162: return error;
163:
164: DPRINTF(("SIOCGIFCONF\n"));
165: return 0;
166: }
167:
168:
169: default:
170: DPRINTF(("Unknown svr4 sockio %lx\n", cmd));
171: return 0; /* ENOSYS really */
172: }
173: }
CVSweb