Sync usage with man page.
[netbsd-mini2440.git] / sys / compat / osf1 / osf1_socket.c
blob57acb9167b0f1d6127b0be9d8062b5f389325a5c
1 /* $NetBSD: osf1_socket.c,v 1.18 2007/12/08 18:36:22 dsl Exp $ */
3 /*
4 * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved.
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. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Christopher G. Demetriou
17 * for the NetBSD Project.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * Copyright (c) 1994, 1995 Carnegie-Mellon University.
35 * All rights reserved.
37 * Author: Chris G. Demetriou
39 * Permission to use, copy, modify and distribute this software and
40 * its documentation is hereby granted, provided that both the copyright
41 * notice and this permission notice appear in all copies of the
42 * software, derivative works or modified versions, and any portions
43 * thereof, and that both notices appear in supporting documentation.
45 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
46 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
47 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
49 * Carnegie Mellon requests users of this software to return to
51 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
52 * School of Computer Science
53 * Carnegie Mellon University
54 * Pittsburgh PA 15213-3890
56 * any improvements or extensions that they make and grant Carnegie the
57 * rights to redistribute these changes.
60 #include <sys/cdefs.h>
61 __KERNEL_RCSID(0, "$NetBSD: osf1_socket.c,v 1.18 2007/12/08 18:36:22 dsl Exp $");
63 #include <sys/param.h>
64 #include <sys/systm.h>
65 #include <sys/namei.h>
66 #include <sys/proc.h>
67 #include <sys/file.h>
68 #include <sys/malloc.h>
69 #include <sys/mount.h>
70 #include <sys/syscallargs.h>
71 #include <sys/socket.h>
72 #include <sys/socketvar.h>
73 #include <sys/exec.h>
75 #include <compat/osf1/osf1.h>
76 #include <compat/osf1/osf1_syscallargs.h>
77 #include <compat/common/compat_util.h>
78 #include <compat/osf1/osf1_cvt.h>
80 int
81 osf1_sys_recvmsg_xopen(struct lwp *l, const struct osf1_sys_recvmsg_xopen_args *uap, register_t *retval)
84 /* XXX */
85 return (EINVAL);
88 int
89 osf1_sys_sendmsg_xopen(struct lwp *l, const struct osf1_sys_sendmsg_xopen_args *uap, register_t *retval)
91 struct osf1_msghdr_xopen osf_msghdr;
92 struct osf1_iovec_xopen osf_iovec, *osf_iovec_ptr;
93 struct msghdr bsd_msghdr;
94 struct iovec *bsd_iovec;
95 unsigned long leftovers;
96 int flags;
97 unsigned int i, iov_len;
98 int error;
101 * translate msghdr structure
103 if ((error = copyin(SCARG(uap, msg), &osf_msghdr,
104 sizeof osf_msghdr)) != 0)
105 return (error);
107 error = osf1_cvt_msghdr_xopen_to_native(&osf_msghdr, &bsd_msghdr);
108 if (error != 0)
109 return (error);
112 * translate flags
114 flags = emul_flags_translate(osf1_sendrecv_msg_flags_xtab,
115 SCARG(uap, flags), &leftovers);
116 if (leftovers != 0)
118 printf("sendmsg flags leftover: 0x%lx\n", leftovers);
119 return (EINVAL);
122 iov_len = bsd_msghdr.msg_iovlen;
123 if (iov_len > IOV_MAX)
124 return EMSGSIZE;
125 bsd_iovec = malloc(iov_len * sizeof (struct iovec), M_IOV, M_WAITOK);
126 bsd_msghdr.msg_iov = bsd_iovec;
128 osf_iovec_ptr = osf_msghdr.msg_iov;
129 for (i = 0; i < iov_len; i++) {
130 error = copyin(&osf_iovec_ptr[i], &osf_iovec, sizeof osf_iovec);
131 if (error != 0) {
132 free(bsd_iovec, M_TEMP);
133 return (error);
135 bsd_iovec[i].iov_base = osf_iovec.iov_base;
136 bsd_iovec[i].iov_len = osf_iovec.iov_len;
139 error = do_sys_sendmsg(l, SCARG(uap, s), &bsd_msghdr, flags, retval);
140 free(bsd_iovec, M_TEMP);
141 return error;
145 osf1_sys_sendto(struct lwp *l, const struct osf1_sys_sendto_args *uap, register_t *retval)
147 struct sys_sendto_args a;
148 unsigned long leftovers;
150 SCARG(&a, s) = SCARG(uap, s);
151 SCARG(&a, buf) = SCARG(uap, buf);
152 SCARG(&a, len) = SCARG(uap, len);
153 SCARG(&a, to) = SCARG(uap, to);
154 SCARG(&a, tolen) = SCARG(uap, tolen);
156 /* translate flags */
157 SCARG(&a, flags) = emul_flags_translate(osf1_sendrecv_msg_flags_xtab,
158 SCARG(uap, flags), &leftovers);
159 if (leftovers != 0)
160 return (EINVAL);
162 return sys_sendto(l, &a, retval);
166 osf1_sys_socket(struct lwp *l, const struct osf1_sys_socket_args *uap, register_t *retval)
168 struct compat_30_sys_socket_args a;
170 /* XXX TRANSLATE */
172 if (SCARG(uap, domain) > AF_LINK)
173 return (EINVAL); /* XXX After AF_LINK, divergence. */
175 SCARG(&a, domain) = SCARG(uap, domain);
176 SCARG(&a, type) = SCARG(uap, type);
177 SCARG(&a, protocol) = SCARG(uap, protocol);
179 return compat_30_sys_socket(l, &a, retval);
183 osf1_sys_socketpair(struct lwp *l, const struct osf1_sys_socketpair_args *uap, register_t *retval)
185 struct sys_socketpair_args a;
187 /* XXX TRANSLATE */
189 if (SCARG(uap, domain) > AF_LINK)
190 return (EINVAL); /* XXX After AF_LINK, divergence. */
192 SCARG(&a, domain) = SCARG(uap, domain);
193 SCARG(&a, type) = SCARG(uap, type);
194 SCARG(&a, protocol) = SCARG(uap, protocol);
195 SCARG(&a, rsv) = SCARG(uap, rsv);
197 return sys_socketpair(l, &a, retval);