Sync usage with man page.
[netbsd-mini2440.git] / sys / rump / librump / rumpuser / rumpuser_net.c
blob10472074889f31a390c837d0cb9d17482c55a5a5
1 /* $NetBSD: rumpuser_net.c,v 1.6 2009/01/26 12:08:39 pooka Exp $ */
3 /*
4 * Copyright (c) 2008 Antti Kantee. 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.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
28 #include <sys/cdefs.h>
29 #if !defined(lint)
30 __RCSID("$NetBSD: rumpuser_net.c,v 1.6 2009/01/26 12:08:39 pooka Exp $");
31 #endif /* !lint */
33 #include <sys/types.h>
34 #include <sys/socket.h>
36 #include <errno.h>
38 #include <rump/rumpuser.h>
40 #include "rumpuser_int.h"
42 int
43 rumpuser_net_socket(int domain, int type, int proto, int *error)
46 DOCALL_KLOCK(int, (socket(domain, type, proto)));
49 int
50 rumpuser_net_sendmsg(int s, const struct msghdr *msg, int flags, int *error)
53 DOCALL_KLOCK(ssize_t, (sendmsg(s, msg, flags)));
56 int
57 rumpuser_net_recvmsg(int s, struct msghdr *msg, int flags, int *error)
60 DOCALL_KLOCK(ssize_t, (recvmsg(s, msg, flags)));
63 int
64 rumpuser_net_connect(int s, const struct sockaddr *name, int len, int *error)
67 DOCALL_KLOCK(int, (connect(s, name, (socklen_t)len)));
70 int
71 rumpuser_net_bind(int s, const struct sockaddr *name, int len, int *error)
74 DOCALL_KLOCK(int, (bind(s, name, (socklen_t)len)));
77 int
78 rumpuser_net_accept(int s, struct sockaddr *name, int *lenp, int *error)
81 DOCALL_KLOCK(int, (accept(s, name, (socklen_t *)lenp)));
84 int
85 rumpuser_net_listen(int s, int backlog, int *error)
88 DOCALL_KLOCK(int, (listen(s, backlog)));
91 int
92 rumpuser_net_getname(int s, struct sockaddr *so, int *lenp,
93 enum rumpuser_getnametype which, int *error)
95 socklen_t slen = *lenp;
96 int rv;
98 if (which == RUMPUSER_SOCKNAME)
99 rv = getsockname(s, so, &slen);
100 else
101 rv = getpeername(s, so, &slen);
103 *lenp = slen;
104 if (rv == -1)
105 *error = errno;
106 else
107 *error = 0;
109 return rv;
113 rumpuser_net_setsockopt(int s, int level, int name,
114 const void *data, int dlen, int *error)
116 socklen_t slen = dlen;
117 int rv;
119 rv = setsockopt(s, level, name, data, slen);
120 if (rv == -1)
121 *error = errno;
122 else
123 *error = 0;
124 return rv;