1/*	$NetBSD: rumpuser_net.c,v 1.1 2010/02/26 18:54:20 pooka Exp $	*/
2
3/*
4 * Copyright (c) 2008 Antti Kantee.  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 *
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.
26 */
27
28#include <sys/cdefs.h>
29#if !defined(lint)
30__RCSID("$NetBSD: rumpuser_net.c,v 1.1 2010/02/26 18:54:20 pooka Exp $");
31#endif /* !lint */
32
33#include <sys/types.h>
34#include <sys/socket.h>
35
36#include <errno.h>
37
38#include <rump/rumpuser.h>
39
40#include "rumpuser_int.h"
41
42int
43rumpuser_net_socket(int domain, int type, int proto, int *error)
44{
45
46	DOCALL_KLOCK(int, (socket(domain, type, proto)));
47}
48
49int
50rumpuser_net_sendmsg(int s, const struct msghdr *msg, int flags, int *error)
51{
52
53	DOCALL_KLOCK(ssize_t, (sendmsg(s, msg, flags)));
54}
55
56int
57rumpuser_net_recvmsg(int s, struct msghdr *msg, int flags, int *error)
58{
59
60	DOCALL_KLOCK(ssize_t, (recvmsg(s, msg, flags)));
61}
62
63int
64rumpuser_net_connect(int s, const struct sockaddr *name, int len, int *error)
65{
66
67	DOCALL_KLOCK(int, (connect(s, name, (socklen_t)len)));
68}
69
70int
71rumpuser_net_bind(int s, const struct sockaddr *name, int len, int *error)
72{
73
74	DOCALL_KLOCK(int, (bind(s, name, (socklen_t)len)));
75}
76
77int
78rumpuser_net_accept(int s, struct sockaddr *name, int *lenp, int *error)
79{
80
81	DOCALL_KLOCK(int, (accept(s, name, (socklen_t *)lenp)));
82}
83
84int
85rumpuser_net_listen(int s, int backlog, int *error)
86{
87
88	DOCALL_KLOCK(int, (listen(s, backlog)));
89}
90
91int
92rumpuser_net_getname(int s, struct sockaddr *so, int *lenp,
93	enum rumpuser_getnametype which, int *error)
94{
95	socklen_t slen = *lenp;
96	int rv;
97
98	if (which == RUMPUSER_SOCKNAME)
99		rv = getsockname(s, so, &slen);
100	else
101		rv = getpeername(s, so, &slen);
102
103	*lenp = slen;
104	if (rv == -1)
105		seterror(errno);
106	else
107		seterror(0);
108
109	return rv;
110}
111
112int
113rumpuser_net_setsockopt(int s, int level, int name,
114	const void *data, int dlen, int *error)
115{
116	socklen_t slen = dlen;
117	int rv;
118
119	rv = setsockopt(s, level, name, data, slen);
120	if (rv == -1)
121		seterror(errno);
122	else
123		seterror(0);
124	return rv;
125}
126