1165000Skientzle/*-
2165912Skientzle * Copyright (c) 2010 Isilon Systems, Inc.
3165000Skientzle * Copyright (c) 2010 iX Systems, Inc.
4165000Skientzle * Copyright (c) 2010 Panasas, Inc.
5165000Skientzle * All rights reserved.
6165000Skientzle *
7165000Skientzle * Redistribution and use in source and binary forms, with or without
8165000Skientzle * modification, are permitted provided that the following conditions
9165912Skientzle * are met:
10165000Skientzle * 1. Redistributions of source code must retain the above copyright
11165000Skientzle *    notice unmodified, this list of conditions, and the following
12165000Skientzle *    disclaimer.
13165000Skientzle * 2. Redistributions in binary form must reproduce the above copyright
14165000Skientzle *    notice, this list of conditions and the following disclaimer in the
15165000Skientzle *    documentation and/or other materials provided with the distribution.
16165000Skientzle *
17165000Skientzle * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18165000Skientzle * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19165000Skientzle * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20165000Skientzle * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21165000Skientzle * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22165000Skientzle * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23165000Skientzle * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24165000Skientzle * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25165000Skientzle * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26165000Skientzle * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27165000Skientzle */
28189431Skientzle
29165000Skientzle#ifndef	_LINUX_NET_H_
30165000Skientzle#define	_LINUX_NET_H_
31189427Skientzle
32165000Skientzle#include <sys/protosw.h>
33165000Skientzle#include <sys/socket.h>
34165000Skientzle#include <sys/socketvar.h>
35165000Skientzle
36165000Skientzlestatic inline int
37189429Skientzlesock_create_kern(int family, int type, int proto, struct socket **res)
38189429Skientzle{
39189429Skientzle	return -socreate(family, res, type, proto, curthread->td_ucred,
40189429Skientzle	    curthread);
41189429Skientzle}
42189429Skientzle
43165000Skientzlestatic inline int
44165000Skientzlesock_getname(struct socket *so, struct sockaddr *addr, int *sockaddr_len,
45191241Skientzle    int peer)
46191241Skientzle{
47191241Skientzle	struct sockaddr *nam;
48191241Skientzle	int error;
49191241Skientzle
50191241Skientzle	nam = NULL;
51191241Skientzle	if (peer) {
52191241Skientzle		if ((so->so_state & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0)
53165000Skientzle			return (-ENOTCONN);
54165000Skientzle
55176397Skientzle		error = (*so->so_proto->pr_usrreqs->pru_peeraddr)(so, &nam);
56168743Skientzle	} else
57168743Skientzle		error = (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, &nam);
58168743Skientzle	if (error)
59182954Skientzle		return (-error);
60165000Skientzle	*addr = *nam;
61168743Skientzle	*sockaddr_len = addr->sa_len;
62168743Skientzle
63165000Skientzle	free(nam, M_SONAME);
64165000Skientzle	return (0);
65165000Skientzle}
66165000Skientzle
67165000Skientzlestatic inline void
68165000Skientzlesock_release(struct socket *so)
69165000Skientzle{
70179321Skientzle	soclose(so);
71165000Skientzle}
72165000Skientzle
73177213Skientzle#endif	/* _LINUX_NET_H_ */
74182955Skientzle