net.h revision 254734
1258945Sroberto/*-
2258945Sroberto * Copyright (c) 2010 Isilon Systems, Inc.
3258945Sroberto * Copyright (c) 2010 iX Systems, Inc.
4258945Sroberto * Copyright (c) 2010 Panasas, Inc.
5258945Sroberto * All rights reserved.
6258945Sroberto *
7258945Sroberto * Redistribution and use in source and binary forms, with or without
8258945Sroberto * modification, are permitted provided that the following conditions
9258945Sroberto * are met:
10280849Scy * 1. Redistributions of source code must retain the above copyright
11280849Scy *    notice unmodified, this list of conditions, and the following
12258945Sroberto *    disclaimer.
13258945Sroberto * 2. Redistributions in binary form must reproduce the above copyright
14258945Sroberto *    notice, this list of conditions and the following disclaimer in the
15258945Sroberto *    documentation and/or other materials provided with the distribution.
16258945Sroberto *
17258945Sroberto * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18258945Sroberto * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19258945Sroberto * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20258945Sroberto * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21258945Sroberto * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22280849Scy * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23280849Scy * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24280849Scy * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25280849Scy * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26258945Sroberto * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27258945Sroberto */
28258945Sroberto
29258945Sroberto#ifndef	_LINUX_NET_H_
30258945Sroberto#define	_LINUX_NET_H_
31258945Sroberto
32258945Sroberto#include <sys/protosw.h>
33258945Sroberto#include <sys/socket.h>
34258945Sroberto#include <sys/socketvar.h>
35258945Sroberto
36258945Srobertostatic inline int
37258945Srobertosock_create_kern(int family, int type, int proto, struct socket **res)
38285612Sdelphij{
39258945Sroberto	return -socreate(family, res, type, proto, curthread->td_ucred,
40258945Sroberto	    curthread);
41258945Sroberto}
42258945Sroberto
43258945Srobertostatic inline int
44258945Srobertosock_getname(struct socket *so, struct sockaddr *addr, int *sockaddr_len,
45258945Sroberto    int peer)
46258945Sroberto{
47258945Sroberto	struct sockaddr *nam;
48258945Sroberto	int error;
49258945Sroberto
50258945Sroberto	nam = NULL;
51258945Sroberto	if (peer) {
52258945Sroberto		if ((so->so_state & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0)
53280849Scy			return (-ENOTCONN);
54280849Scy
55258945Sroberto		error = (*so->so_proto->pr_usrreqs->pru_peeraddr)(so, &nam);
56258945Sroberto	} else
57258945Sroberto		error = (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, &nam);
58258945Sroberto	if (error)
59258945Sroberto		return (-error);
60280849Scy	*addr = *nam;
61258945Sroberto	*sockaddr_len = addr->sa_len;
62258945Sroberto
63258945Sroberto	free(nam, M_SONAME);
64280849Scy	return (0);
65258945Sroberto}
66258945Sroberto
67258945Srobertostatic inline void
68258945Srobertosock_release(struct socket *so)
69258945Sroberto{
70258945Sroberto	soclose(so);
71258945Sroberto}
72258945Sroberto
73258945Sroberto#endif	/* _LINUX_NET_H_ */
74258945Sroberto