This source file includes following definitions.
- hpux_sys_netioctl
- socksetsize
- hpux_sys_setsockopt2
- hpux_sys_setsockopt
- hpux_sys_getsockopt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/kernel.h>
49 #include <sys/time.h>
50 #include <sys/errno.h>
51 #include <sys/proc.h>
52 #include <sys/file.h>
53 #include <sys/filedesc.h>
54 #include <sys/mbuf.h>
55 #include <sys/mount.h>
56 #include <sys/socket.h>
57 #include <sys/socketvar.h>
58 #include <sys/uio.h>
59 #include <sys/ktrace.h>
60 #include <sys/syscallargs.h>
61
62 #include <compat/hpux/hpux.h>
63 #include <compat/hpux/hpux_util.h>
64 #include <compat/hpux/m68k/hpux_syscallargs.h>
65
66 struct hpux_sys_getsockopt_args {
67 syscallarg(int) s;
68 syscallarg(int) level;
69 syscallarg(int) name;
70 syscallarg(caddr_t) val;
71 syscallarg(int *) avalsize;
72 };
73
74 int hpux_sys_setsockopt2(struct proc *, void *, register_t *);
75 int hpux_sys_getsockopt(struct proc *, void *, register_t *);
76
77 void socksetsize(int, struct mbuf *);
78
79
80 #define MINBSDIPCCODE 0x3EE
81 #define NUMBSDIPC 32
82
83
84
85
86
87
88 struct hpuxtobsdipc {
89 int (*rout)(struct proc *, void *, register_t *);
90 int nargs;
91 } hpuxtobsdipc[NUMBSDIPC] = {
92 { sys_socket, 3 },
93 { sys_listen, 2 },
94 { sys_bind, 3 },
95 { compat_43_sys_accept, 3 },
96 { sys_connect, 3 },
97 { compat_43_sys_recv, 4 },
98 { compat_43_sys_send, 4 },
99 { sys_shutdown, 2 },
100 { compat_43_sys_getsockname, 3 },
101 { hpux_sys_setsockopt2, 5 },
102 { sys_sendto, 6 },
103 { compat_43_sys_recvfrom, 6 },
104 { compat_43_sys_getpeername, 3 },
105 { NULL, 0 },
106 { NULL, 0 },
107 { NULL, 0 },
108 { NULL, 0 },
109 { NULL, 0 },
110 { NULL, 0 },
111 { NULL, 0 },
112 { NULL, 0 },
113 { NULL, 0 },
114 { NULL, 0 },
115 { NULL, 0 },
116 { NULL, 0 },
117 { NULL, 0 },
118 { NULL, 0 },
119 { NULL, 0 },
120 { NULL, 0 },
121 { hpux_sys_getsockopt, 5 },
122 { NULL, 0 },
123 { NULL, 0 },
124 };
125
126
127
128
129
130 int
131 hpux_sys_netioctl(p, v, retval)
132 struct proc *p;
133 void *v;
134 register_t *retval;
135 {
136 struct hpux_sys_netioctl_args *uap = v;
137 int *args, i;
138 int code;
139 int error;
140
141 args = SCARG(uap, args);
142 code = SCARG(uap, call) - MINBSDIPCCODE;
143 if (code < 0 || code >= NUMBSDIPC || hpuxtobsdipc[code].rout == NULL)
144 return (EINVAL);
145 if ((i = hpuxtobsdipc[code].nargs * sizeof (int)) &&
146 (error = copyin((caddr_t)args, (caddr_t)uap, (u_int)i))) {
147 #ifdef KTRACE
148 if (KTRPOINT(p, KTR_SYSCALL))
149 ktrsyscall(p, code + MINBSDIPCCODE,
150 hpuxtobsdipc[code].nargs,
151 (register_t *)uap);
152 #endif
153 return (error);
154 }
155 #ifdef KTRACE
156 if (KTRPOINT(p, KTR_SYSCALL))
157 ktrsyscall(p, code + MINBSDIPCCODE,
158 hpuxtobsdipc[code].nargs,
159 (register_t *)uap);
160 #endif
161 return ((*hpuxtobsdipc[code].rout)(p, uap, retval));
162 }
163
164 void
165 socksetsize(size, m)
166 int size;
167 struct mbuf *m;
168 {
169 int tmp;
170
171 if (size < sizeof(int)) {
172 switch(size) {
173 case 1:
174 tmp = (int) *mtod(m, char *);
175 break;
176 case 2:
177 tmp = (int) *mtod(m, short *);
178 break;
179 case 3:
180 default:
181 tmp = (((int) *mtod(m, int *)) >> 8) & 0xffffff;
182 break;
183 }
184 *mtod(m, int *) = tmp;
185 m->m_len = sizeof(int);
186 } else {
187 m->m_len = size;
188 }
189 }
190
191
192 int
193 hpux_sys_setsockopt2(p, v, retval)
194 struct proc *p;
195 void *v;
196 register_t *retval;
197 {
198 struct hpux_sys_setsockopt_args *uap = v;
199 struct file *fp;
200 struct mbuf *m = NULL;
201 int tmp, error;
202
203 if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)))
204 return (error);
205 if (SCARG(uap, valsize) > MLEN) {
206 error = EINVAL;
207 goto bad;
208 }
209 if (SCARG(uap, val)) {
210 m = m_get(M_WAIT, MT_SOOPTS);
211 if ((error = copyin(SCARG(uap, val), mtod(m, caddr_t),
212 (u_int)SCARG(uap, valsize)))) {
213 (void) m_free(m);
214 goto bad;
215 }
216 if (SCARG(uap, name) == SO_LINGER) {
217 tmp = *mtod(m, int *);
218 mtod(m, struct linger *)->l_onoff = 1;
219 mtod(m, struct linger *)->l_linger = tmp;
220 m->m_len = sizeof(struct linger);
221 } else
222 socksetsize(SCARG(uap, valsize), m);
223 } else if (SCARG(uap, name) == ~SO_LINGER) {
224 m = m_get(M_WAIT, MT_SOOPTS);
225 SCARG(uap, name) = SO_LINGER;
226 mtod(m, struct linger *)->l_onoff = 0;
227 m->m_len = sizeof(struct linger);
228 }
229 error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
230 SCARG(uap, name), m);
231 bad:
232 FRELE(fp);
233 return (error);
234 }
235
236
237 int
238 hpux_sys_setsockopt(p, v, retval)
239 struct proc *p;
240 void *v;
241 register_t *retval;
242 {
243 struct hpux_sys_setsockopt_args *uap = v;
244 struct file *fp;
245 struct mbuf *m = NULL;
246 int error;
247
248 if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)))
249 return (error);
250 if (SCARG(uap, valsize) > MLEN) {
251 error = EINVAL;
252 goto bad;
253 }
254 if (SCARG(uap, val)) {
255 m = m_get(M_WAIT, MT_SOOPTS);
256 if ((error = copyin(SCARG(uap, val), mtod(m, caddr_t),
257 (u_int)SCARG(uap, valsize)))) {
258 m_free(m);
259 goto bad;
260 }
261 socksetsize(SCARG(uap, valsize), m);
262 }
263 error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
264 SCARG(uap, name), m);
265 bad:
266 FRELE(fp);
267 return (error);
268 }
269
270 int
271 hpux_sys_getsockopt(p, v, retval)
272 struct proc *p;
273 void *v;
274 register_t *retval;
275 {
276 struct hpux_sys_getsockopt_args *uap = v;
277 struct file *fp;
278 struct mbuf *m = NULL;
279 int valsize, error;
280
281 if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)))
282 return (error);
283 if (SCARG(uap, val)) {
284 if ((error = copyin((caddr_t)SCARG(uap, avalsize),
285 (caddr_t)&valsize, sizeof (valsize)))) {
286 goto bad;
287 }
288 } else
289 valsize = 0;
290 if ((error = sogetopt((struct socket *)fp->f_data, SCARG(uap, level),
291 SCARG(uap, name), &m)))
292 goto bad;
293 if (SCARG(uap, val) && valsize && m != NULL) {
294 if (SCARG(uap, name) == SO_LINGER) {
295 if (mtod(m, struct linger *)->l_onoff)
296 *mtod(m, int *) = mtod(m, struct linger *)->l_linger;
297 else
298 *mtod(m, int *) = 0;
299 m->m_len = sizeof(int);
300 }
301 if (valsize > m->m_len)
302 valsize = m->m_len;
303 error = copyout(mtod(m, caddr_t), SCARG(uap, val),
304 (u_int)valsize);
305 if (error == 0)
306 error = copyout((caddr_t)&valsize,
307 (caddr_t)SCARG(uap, avalsize), sizeof (valsize));
308 }
309 bad:
310 FRELE(fp);
311 if (m != NULL)
312 m_free(m);
313 return (error);
314 }