Deleted Added
full compact
svr4_sockio.c (108172) svr4_sockio.c (116174)
1/*
2 * Copyright (c) 1998 Mark Newton
3 * Copyright (c) 1995 Christos Zoulas
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1/*
2 * Copyright (c) 1998 Mark Newton
3 * Copyright (c) 1995 Christos Zoulas
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $FreeBSD: head/sys/compat/svr4/svr4_sockio.c 108172 2002-12-22 05:35:03Z hsu $
29 */
30
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/sys/compat/svr4/svr4_sockio.c 116174 2003-06-10 21:44:29Z obrien $");
31
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/sockio.h>
37#include <sys/socket.h>
38#include <net/if.h>
39
40
41#include <compat/svr4/svr4.h>
42#include <compat/svr4/svr4_util.h>
43#include <compat/svr4/svr4_ioctl.h>
44#include <compat/svr4/svr4_sockio.h>
45
46static int bsd_to_svr4_flags(int);
47
48#define bsd_to_svr4_flag(a) \
49 if (bf & __CONCAT(I,a)) sf |= __CONCAT(SVR4_I,a)
50
51static int
52bsd_to_svr4_flags(bf)
53 int bf;
54{
55 int sf = 0;
56 bsd_to_svr4_flag(FF_UP);
57 bsd_to_svr4_flag(FF_BROADCAST);
58 bsd_to_svr4_flag(FF_DEBUG);
59 bsd_to_svr4_flag(FF_LOOPBACK);
60 bsd_to_svr4_flag(FF_POINTOPOINT);
61#if defined(IFF_NOTRAILERS)
62 bsd_to_svr4_flag(FF_NOTRAILERS);
63#endif
64 bsd_to_svr4_flag(FF_RUNNING);
65 bsd_to_svr4_flag(FF_NOARP);
66 bsd_to_svr4_flag(FF_PROMISC);
67 bsd_to_svr4_flag(FF_ALLMULTI);
68 bsd_to_svr4_flag(FF_MULTICAST);
69 return sf;
70}
71
72int
73svr4_sock_ioctl(fp, td, retval, fd, cmd, data)
74 struct file *fp;
75 struct thread *td;
76 register_t *retval;
77 int fd;
78 u_long cmd;
79 caddr_t data;
80{
81 int error;
82
83 *retval = 0;
84
85 switch (cmd) {
86 case SVR4_SIOCGIFNUM:
87 {
88 struct ifnet *ifp;
89 struct ifaddr *ifa;
90 int ifnum = 0;
91
92 /*
93 * This does not return the number of physical
94 * interfaces (if_index), but the number of interfaces
95 * + addresses like ifconf() does, because this number
96 * is used by code that will call SVR4_SIOCGIFCONF to
97 * find the space needed for SVR4_SIOCGIFCONF. So we
98 * count the number of ifreq entries that the next
99 * SVR4_SIOCGIFCONF will return. Maybe a more correct
100 * fix is to make SVR4_SIOCGIFCONF return only one
101 * entry per physical interface?
102 */
103 IFNET_RLOCK();
104 TAILQ_FOREACH(ifp, &ifnet, if_link)
105 if (TAILQ_FIRST(&ifp->if_addrhead) == NULL)
106 ifnum++;
107 else
108 TAILQ_FOREACH(ifa, &ifp->if_addrhead,
109 ifa_link)
110 ifnum++;
111 IFNET_RUNLOCK();
112 DPRINTF(("SIOCGIFNUM %d\n", ifnum));
113 return copyout(&ifnum, data, sizeof(ifnum));
114 }
115
116 case SVR4_SIOCGIFFLAGS:
117 {
118 struct ifreq br;
119 struct svr4_ifreq sr;
120
121 if ((error = copyin(data, &sr, sizeof(sr))) != 0)
122 return error;
123
124 (void) strlcpy(br.ifr_name, sr.svr4_ifr_name,
125 sizeof(br.ifr_name));
126 if ((error = fo_ioctl(fp, SIOCGIFFLAGS,
127 (caddr_t) &br, td->td_ucred,
128 td)) != 0) {
129 DPRINTF(("SIOCGIFFLAGS (%s) %s: error %d\n",
130 br.ifr_name, sr.svr4_ifr_name, error));
131 return error;
132 }
133
134 sr.svr4_ifr_flags = bsd_to_svr4_flags(br.ifr_flags);
135 DPRINTF(("SIOCGIFFLAGS %s = %x\n",
136 sr.svr4_ifr_name, sr.svr4_ifr_flags));
137 return copyout(&sr, data, sizeof(sr));
138 }
139
140 case SVR4_SIOCGIFCONF:
141 {
142 struct svr4_ifconf sc;
143
144 if ((error = copyin(data, &sc, sizeof(sc))) != 0)
145 return error;
146
147 DPRINTF(("ifreq %d svr4_ifreq %d ifc_len %d\n",
148 sizeof(struct ifreq), sizeof(struct svr4_ifreq),
149 sc.svr4_ifc_len));
150
151 if ((error = fo_ioctl(fp, OSIOCGIFCONF,
152 (caddr_t) &sc, td->td_ucred,
153 td)) != 0)
154 return error;
155
156 DPRINTF(("SIOCGIFCONF\n"));
157 return 0;
158 }
159
160
161 default:
162 DPRINTF(("Unknown svr4 sockio %lx\n", cmd));
163 return 0; /* ENOSYS really */
164 }
165}
32#include <sys/param.h>
33#include <sys/proc.h>
34#include <sys/systm.h>
35#include <sys/file.h>
36#include <sys/filedesc.h>
37#include <sys/sockio.h>
38#include <sys/socket.h>
39#include <net/if.h>
40
41
42#include <compat/svr4/svr4.h>
43#include <compat/svr4/svr4_util.h>
44#include <compat/svr4/svr4_ioctl.h>
45#include <compat/svr4/svr4_sockio.h>
46
47static int bsd_to_svr4_flags(int);
48
49#define bsd_to_svr4_flag(a) \
50 if (bf & __CONCAT(I,a)) sf |= __CONCAT(SVR4_I,a)
51
52static int
53bsd_to_svr4_flags(bf)
54 int bf;
55{
56 int sf = 0;
57 bsd_to_svr4_flag(FF_UP);
58 bsd_to_svr4_flag(FF_BROADCAST);
59 bsd_to_svr4_flag(FF_DEBUG);
60 bsd_to_svr4_flag(FF_LOOPBACK);
61 bsd_to_svr4_flag(FF_POINTOPOINT);
62#if defined(IFF_NOTRAILERS)
63 bsd_to_svr4_flag(FF_NOTRAILERS);
64#endif
65 bsd_to_svr4_flag(FF_RUNNING);
66 bsd_to_svr4_flag(FF_NOARP);
67 bsd_to_svr4_flag(FF_PROMISC);
68 bsd_to_svr4_flag(FF_ALLMULTI);
69 bsd_to_svr4_flag(FF_MULTICAST);
70 return sf;
71}
72
73int
74svr4_sock_ioctl(fp, td, retval, fd, cmd, data)
75 struct file *fp;
76 struct thread *td;
77 register_t *retval;
78 int fd;
79 u_long cmd;
80 caddr_t data;
81{
82 int error;
83
84 *retval = 0;
85
86 switch (cmd) {
87 case SVR4_SIOCGIFNUM:
88 {
89 struct ifnet *ifp;
90 struct ifaddr *ifa;
91 int ifnum = 0;
92
93 /*
94 * This does not return the number of physical
95 * interfaces (if_index), but the number of interfaces
96 * + addresses like ifconf() does, because this number
97 * is used by code that will call SVR4_SIOCGIFCONF to
98 * find the space needed for SVR4_SIOCGIFCONF. So we
99 * count the number of ifreq entries that the next
100 * SVR4_SIOCGIFCONF will return. Maybe a more correct
101 * fix is to make SVR4_SIOCGIFCONF return only one
102 * entry per physical interface?
103 */
104 IFNET_RLOCK();
105 TAILQ_FOREACH(ifp, &ifnet, if_link)
106 if (TAILQ_FIRST(&ifp->if_addrhead) == NULL)
107 ifnum++;
108 else
109 TAILQ_FOREACH(ifa, &ifp->if_addrhead,
110 ifa_link)
111 ifnum++;
112 IFNET_RUNLOCK();
113 DPRINTF(("SIOCGIFNUM %d\n", ifnum));
114 return copyout(&ifnum, data, sizeof(ifnum));
115 }
116
117 case SVR4_SIOCGIFFLAGS:
118 {
119 struct ifreq br;
120 struct svr4_ifreq sr;
121
122 if ((error = copyin(data, &sr, sizeof(sr))) != 0)
123 return error;
124
125 (void) strlcpy(br.ifr_name, sr.svr4_ifr_name,
126 sizeof(br.ifr_name));
127 if ((error = fo_ioctl(fp, SIOCGIFFLAGS,
128 (caddr_t) &br, td->td_ucred,
129 td)) != 0) {
130 DPRINTF(("SIOCGIFFLAGS (%s) %s: error %d\n",
131 br.ifr_name, sr.svr4_ifr_name, error));
132 return error;
133 }
134
135 sr.svr4_ifr_flags = bsd_to_svr4_flags(br.ifr_flags);
136 DPRINTF(("SIOCGIFFLAGS %s = %x\n",
137 sr.svr4_ifr_name, sr.svr4_ifr_flags));
138 return copyout(&sr, data, sizeof(sr));
139 }
140
141 case SVR4_SIOCGIFCONF:
142 {
143 struct svr4_ifconf sc;
144
145 if ((error = copyin(data, &sc, sizeof(sc))) != 0)
146 return error;
147
148 DPRINTF(("ifreq %d svr4_ifreq %d ifc_len %d\n",
149 sizeof(struct ifreq), sizeof(struct svr4_ifreq),
150 sc.svr4_ifc_len));
151
152 if ((error = fo_ioctl(fp, OSIOCGIFCONF,
153 (caddr_t) &sc, td->td_ucred,
154 td)) != 0)
155 return error;
156
157 DPRINTF(("SIOCGIFCONF\n"));
158 return 0;
159 }
160
161
162 default:
163 DPRINTF(("Unknown svr4 sockio %lx\n", cmd));
164 return 0; /* ENOSYS really */
165 }
166}