|
|
1.1 root 1: /*
2: * Copyright (c) 1988 University of Utah.
3: * Copyright (c) 1990 The Regents of the University of California.
4: * All rights reserved.
5: *
6: * This code is derived from software contributed to Berkeley by
7: * the Systems Programming Group of the University of Utah Computer
8: * Science Department.
9: *
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.
18: * 3. All advertising materials mentioning features or use of this software
19: * must display the following acknowledgement:
20: * This product includes software developed by the University of
21: * California, Berkeley and its contributors.
22: * 4. Neither the name of the University nor the names of its contributors
23: * may be used to endorse or promote products derived from this software
24: * without specific prior written permission.
25: *
26: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36: * SUCH DAMAGE.
37: *
38: * from: Utah $Hdr: hpux_net.c 1.33 89/08/23$
39: *
1.1.1.2 ! root 40: * from: @(#)hpux_net.c 7.7 (Berkeley) 2/13/91
! 41: * hpux_net.c,v 1.2 1993/05/22 07:58:05 cgd Exp
1.1 root 42: */
43:
44: /*
45: * Network related HP-UX compatibility routines
46: */
47:
48: #ifdef HPUXCOMPAT
49:
50: #include "sys/param.h"
51: #include "sys/systm.h"
52: #include "sys/kernel.h"
53: #include "sys/time.h"
54: #include "sys/errno.h"
55: #include "sys/proc.h"
56: #include "sys/file.h"
57: #include "sys/mbuf.h"
58: #include "sys/socket.h"
59: #include "sys/socketvar.h"
60: #include "sys/uio.h"
61: #include "sys/ktrace.h"
62: #include "hpux.h"
63:
64: #define MINBSDIPCCODE 0x3EE
65: #define NUMBSDIPC 32
66:
67: /*
68: * HPUX netioctl() to BSD syscall map.
69: * Indexed by callno - MINBSDIPCCODE
70: */
71: extern int socket(), listen(), bind(), oaccept(), connect(), orecv();
72: extern int osend(), shutdown(), ogetsockname(), sendto();
73: extern int orecvfrom(), ogetpeername();
74: int hpuxgetsockopt(), hpuxsetsockopt();
75:
76: struct hpuxtobsdipc {
77: int (*rout)();
78: int nargs;
79: } hpuxtobsdipc[NUMBSDIPC] = {
80: socket, 3, /* 3ee */ listen, 2, /* 3ef */
81: bind, 3, /* 3f0 */ oaccept, 3, /* 3f1 */
82: connect, 3, /* 3f2 */ orecv, 4, /* 3f3 */
83: osend, 4, /* 3f4 */ shutdown, 2, /* 3f5 */
84: ogetsockname, 3, /* 3f6 */ hpuxsetsockopt, 5, /* 3f7 */
85: sendto, 6, /* 3f8 */ orecvfrom, 6, /* 3f9 */
86: ogetpeername, 3, /* 3fa */ NULL, 0, /* 3fb */
87: NULL, 0, /* 3fc */ NULL, 0, /* 3fd */
88: NULL, 0, /* 3fe */ NULL, 0, /* 3ff */
89: NULL, 0, /* 400 */ NULL, 0, /* 401 */
90: NULL, 0, /* 402 */ NULL, 0, /* 403 */
91: NULL, 0, /* 404 */ NULL, 0, /* 405 */
92: NULL, 0, /* 406 */ NULL, 0, /* 407 */
93: NULL, 0, /* 408 */ NULL, 0, /* 409 */
94: NULL, 0, /* 40a */ hpuxgetsockopt, 5, /* 40b */
95: NULL, 0, /* 40c */ NULL, 0, /* 40d */
96: };
97:
98: /*
99: * Single system call entry to BSD style IPC.
100: * Gleened from disassembled libbsdipc.a syscall entries.
101: */
102: hpuxnetioctl(p, uap, retval)
103: struct proc *p;
104: struct args {
105: int call;
106: int *args;
107: } *uap;
108: int *retval;
109: {
110: int *args, i;
111: register int code;
112: int error;
113:
114: args = uap->args;
115: code = uap->call - MINBSDIPCCODE;
116: if (code < 0 || code >= NUMBSDIPC || hpuxtobsdipc[code].rout == NULL)
117: return (EINVAL);
118: if ((i = hpuxtobsdipc[code].nargs * sizeof (int)) &&
119: (error = copyin((caddr_t)args, (caddr_t)uap, (u_int)i))) {
120: #ifdef KTRACE
121: if (KTRPOINT(p, KTR_SYSCALL))
122: ktrsyscall(p->p_tracep, code + MINBSDIPCCODE,
123: hpuxtobsdipc[code].nargs);
124: #endif
125: return (error);
126: }
127: #ifdef KTRACE
128: if (KTRPOINT(p, KTR_SYSCALL))
129: ktrsyscall(p->p_tracep, code + MINBSDIPCCODE,
130: hpuxtobsdipc[code].nargs);
131: #endif
132: return ((*hpuxtobsdipc[code].rout)(p, uap, retval));
133: }
134:
135: hpuxsetsockopt(p, uap, retval)
136: struct proc *p;
137: struct args {
138: int s;
139: int level;
140: int name;
141: caddr_t val;
142: int valsize;
143: } *uap;
144: int *retval;
145: {
146: struct file *fp;
147: struct mbuf *m = NULL;
148: int tmp, error;
149:
150: if (error = getsock(p->p_fd, uap->s, &fp))
151: return (error);
152: if (uap->valsize > MLEN)
153: return (EINVAL);
154: if (uap->val) {
155: m = m_get(M_WAIT, MT_SOOPTS);
156: if (m == NULL)
157: return (ENOBUFS);
158: if (error = copyin(uap->val, mtod(m, caddr_t),
159: (u_int)uap->valsize)) {
160: (void) m_free(m);
161: return (error);
162: }
163: if (uap->name == SO_LINGER) {
164: tmp = *mtod(m, int *);
165: mtod(m, struct linger *)->l_onoff = 1;
166: mtod(m, struct linger *)->l_linger = tmp;
167: m->m_len = sizeof(struct linger);
168: } else
169: m->m_len = uap->valsize;
170: } else if (uap->name == ~SO_LINGER) {
171: m = m_get(M_WAIT, MT_SOOPTS);
172: if (m) {
173: uap->name = SO_LINGER;
174: mtod(m, struct linger *)->l_onoff = 0;
175: m->m_len = sizeof(struct linger);
176: }
177: }
178: return (sosetopt((struct socket *)fp->f_data, uap->level,
179: uap->name, m));
180: }
181:
182: hpuxgetsockopt(p, uap, retval)
183: struct proc *p;
184: struct args {
185: int s;
186: int level;
187: int name;
188: caddr_t val;
189: int *avalsize;
190: } *uap;
191: int *retval;
192: {
193: struct file *fp;
194: struct mbuf *m = NULL;
195: int valsize, error;
196:
197: if (error = getsock(p->p_fd, uap->s, &fp))
198: return (error);
199: if (uap->val) {
200: if (error = copyin((caddr_t)uap->avalsize, (caddr_t)&valsize,
201: sizeof (valsize)))
202: return (error);
203: } else
204: valsize = 0;
205: if (error = sogetopt((struct socket *)fp->f_data, uap->level,
206: uap->name, &m))
207: goto bad;
208: if (uap->val && valsize && m != NULL) {
209: if (uap->name == SO_LINGER) {
210: if (mtod(m, struct linger *)->l_onoff)
211: *mtod(m, int *) = mtod(m, struct linger *)->l_linger;
212: else
213: *mtod(m, int *) = 0;
214: m->m_len = sizeof(int);
215: }
216: if (valsize > m->m_len)
217: valsize = m->m_len;
218: error = copyout(mtod(m, caddr_t), uap->val, (u_int)valsize);
219: if (error == 0)
220: error = copyout((caddr_t)&valsize,
221: (caddr_t)uap->avalsize, sizeof (valsize));
222: }
223: bad:
224: if (m != NULL)
225: (void) m_free(m);
226: return (error);
227: }
228: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.