1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <sys/types.h>
30*0Sstevel@tonic-gate #include <sys/socket.h>
31*0Sstevel@tonic-gate #include <sys/stropts.h>
32*0Sstevel@tonic-gate #include <sys/stream.h>
33*0Sstevel@tonic-gate #include <sys/socketvar.h>
34*0Sstevel@tonic-gate #include <sys/sockio.h>
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate #include <errno.h>
37*0Sstevel@tonic-gate #include <stdlib.h>
38*0Sstevel@tonic-gate #include <unistd.h>
39*0Sstevel@tonic-gate #include <stropts.h>
40*0Sstevel@tonic-gate #include <stdio.h>
41*0Sstevel@tonic-gate #include <strings.h>
42*0Sstevel@tonic-gate #include <netinet/sctp.h>
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate #pragma weak bind = _bind
45*0Sstevel@tonic-gate #pragma weak listen = _listen
46*0Sstevel@tonic-gate #pragma weak accept = _accept
47*0Sstevel@tonic-gate #pragma weak connect = _connect
48*0Sstevel@tonic-gate #pragma weak shutdown = _shutdown
49*0Sstevel@tonic-gate #pragma weak recv = _recv
50*0Sstevel@tonic-gate #pragma weak recvfrom = _recvfrom
51*0Sstevel@tonic-gate #pragma weak recvmsg = _recvmsg
52*0Sstevel@tonic-gate #pragma weak send = _send
53*0Sstevel@tonic-gate #pragma weak sendmsg = _sendmsg
54*0Sstevel@tonic-gate #pragma weak sendto = _sendto
55*0Sstevel@tonic-gate #pragma weak getpeername = _getpeername
56*0Sstevel@tonic-gate #pragma weak getsockname = _getsockname
57*0Sstevel@tonic-gate #pragma weak getsockopt = _getsockopt
58*0Sstevel@tonic-gate #pragma weak setsockopt = _setsockopt
59*0Sstevel@tonic-gate 
60*0Sstevel@tonic-gate extern int _so_bind();
61*0Sstevel@tonic-gate extern int _so_listen();
62*0Sstevel@tonic-gate extern int _so_accept();
63*0Sstevel@tonic-gate extern int _so_connect();
64*0Sstevel@tonic-gate extern int _so_shutdown();
65*0Sstevel@tonic-gate extern int _so_recv();
66*0Sstevel@tonic-gate extern int _so_recvfrom();
67*0Sstevel@tonic-gate extern int _so_recvmsg();
68*0Sstevel@tonic-gate extern int _so_send();
69*0Sstevel@tonic-gate extern int _so_sendmsg();
70*0Sstevel@tonic-gate extern int _so_sendto();
71*0Sstevel@tonic-gate extern int _so_getpeername();
72*0Sstevel@tonic-gate extern int _so_getsockopt();
73*0Sstevel@tonic-gate extern int _so_setsockopt();
74*0Sstevel@tonic-gate extern int _so_setsockname();
75*0Sstevel@tonic-gate extern int _so_getsockname();
76*0Sstevel@tonic-gate 
77*0Sstevel@tonic-gate /*
78*0Sstevel@tonic-gate  * Note that regular sockets use SOV_SOCKBSD here to not allow a rebind of an
79*0Sstevel@tonic-gate  * already bound socket.
80*0Sstevel@tonic-gate  */
81*0Sstevel@tonic-gate int
82*0Sstevel@tonic-gate _bind(int sock, struct sockaddr *addr, int addrlen)
83*0Sstevel@tonic-gate {
84*0Sstevel@tonic-gate 	return (_so_bind(sock, addr, addrlen, SOV_SOCKBSD));
85*0Sstevel@tonic-gate }
86*0Sstevel@tonic-gate 
87*0Sstevel@tonic-gate int
88*0Sstevel@tonic-gate _listen(int sock, int backlog)
89*0Sstevel@tonic-gate {
90*0Sstevel@tonic-gate 	return (_so_listen(sock, backlog, SOV_DEFAULT));
91*0Sstevel@tonic-gate }
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate int
94*0Sstevel@tonic-gate _accept(int sock, struct sockaddr *addr, int *addrlen)
95*0Sstevel@tonic-gate {
96*0Sstevel@tonic-gate 	return (_so_accept(sock, addr, addrlen, SOV_DEFAULT));
97*0Sstevel@tonic-gate }
98*0Sstevel@tonic-gate 
99*0Sstevel@tonic-gate int
100*0Sstevel@tonic-gate _connect(int sock, struct sockaddr *addr, int addrlen)
101*0Sstevel@tonic-gate {
102*0Sstevel@tonic-gate 	return (_so_connect(sock, addr, addrlen, SOV_DEFAULT));
103*0Sstevel@tonic-gate }
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate int
106*0Sstevel@tonic-gate _shutdown(int sock, int how)
107*0Sstevel@tonic-gate {
108*0Sstevel@tonic-gate 	return (_so_shutdown(sock, how, SOV_DEFAULT));
109*0Sstevel@tonic-gate }
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate int
112*0Sstevel@tonic-gate _recv(int sock, char *buf, int len, int flags)
113*0Sstevel@tonic-gate {
114*0Sstevel@tonic-gate 	return (_so_recv(sock, buf, len, flags & ~MSG_XPG4_2));
115*0Sstevel@tonic-gate }
116*0Sstevel@tonic-gate 
117*0Sstevel@tonic-gate int
118*0Sstevel@tonic-gate _recvfrom(int sock, char *buf, int len, int flags,
119*0Sstevel@tonic-gate 	struct sockaddr *addr, int *addrlen)
120*0Sstevel@tonic-gate {
121*0Sstevel@tonic-gate 	return (_so_recvfrom(sock, buf, len, flags & ~MSG_XPG4_2,
122*0Sstevel@tonic-gate 		addr, addrlen));
123*0Sstevel@tonic-gate }
124*0Sstevel@tonic-gate 
125*0Sstevel@tonic-gate int
126*0Sstevel@tonic-gate _recvmsg(int sock, struct msghdr *msg, int flags)
127*0Sstevel@tonic-gate {
128*0Sstevel@tonic-gate 	return (_so_recvmsg(sock, msg, flags & ~MSG_XPG4_2));
129*0Sstevel@tonic-gate }
130*0Sstevel@tonic-gate 
131*0Sstevel@tonic-gate int
132*0Sstevel@tonic-gate _send(int sock, char *buf, int len, int flags)
133*0Sstevel@tonic-gate {
134*0Sstevel@tonic-gate 	return (_so_send(sock, buf, len, flags & ~MSG_XPG4_2));
135*0Sstevel@tonic-gate }
136*0Sstevel@tonic-gate 
137*0Sstevel@tonic-gate int
138*0Sstevel@tonic-gate _sendmsg(int sock, struct msghdr *msg, int flags)
139*0Sstevel@tonic-gate {
140*0Sstevel@tonic-gate 	return (_so_sendmsg(sock, msg, flags & ~MSG_XPG4_2));
141*0Sstevel@tonic-gate }
142*0Sstevel@tonic-gate 
143*0Sstevel@tonic-gate int
144*0Sstevel@tonic-gate _sendto(int sock, char *buf, int len, int flags,
145*0Sstevel@tonic-gate 	struct sockaddr *addr, int *addrlen)
146*0Sstevel@tonic-gate {
147*0Sstevel@tonic-gate 	return (_so_sendto(sock, buf, len, flags & ~MSG_XPG4_2,
148*0Sstevel@tonic-gate 		addr, addrlen));
149*0Sstevel@tonic-gate }
150*0Sstevel@tonic-gate 
151*0Sstevel@tonic-gate int
152*0Sstevel@tonic-gate _getpeername(int sock, struct sockaddr *name, int *namelen)
153*0Sstevel@tonic-gate {
154*0Sstevel@tonic-gate 	return (_so_getpeername(sock, name, namelen, SOV_DEFAULT));
155*0Sstevel@tonic-gate }
156*0Sstevel@tonic-gate 
157*0Sstevel@tonic-gate int
158*0Sstevel@tonic-gate _getsockname(int sock, struct sockaddr *name, int *namelen)
159*0Sstevel@tonic-gate {
160*0Sstevel@tonic-gate 	return (_so_getsockname(sock, name, namelen, SOV_DEFAULT));
161*0Sstevel@tonic-gate }
162*0Sstevel@tonic-gate 
163*0Sstevel@tonic-gate int
164*0Sstevel@tonic-gate _getsockopt(int sock, int level, int optname, char *optval, int *optlen)
165*0Sstevel@tonic-gate {
166*0Sstevel@tonic-gate 	if (level == IPPROTO_SCTP) {
167*0Sstevel@tonic-gate 		sctp_assoc_t id = 0;
168*0Sstevel@tonic-gate 		socklen_t len = *optlen;
169*0Sstevel@tonic-gate 		int err = 0;
170*0Sstevel@tonic-gate 		struct sctpopt sopt;
171*0Sstevel@tonic-gate 
172*0Sstevel@tonic-gate 		switch (optname) {
173*0Sstevel@tonic-gate 		case SCTP_RTOINFO:
174*0Sstevel@tonic-gate 		case SCTP_ASSOCINFO:
175*0Sstevel@tonic-gate 		case SCTP_SET_PEER_PRIMARY_ADDR:
176*0Sstevel@tonic-gate 		case SCTP_PRIMARY_ADDR:
177*0Sstevel@tonic-gate 		case SCTP_PEER_ADDR_PARAMS:
178*0Sstevel@tonic-gate 		case SCTP_STATUS:
179*0Sstevel@tonic-gate 		case SCTP_GET_PEER_ADDR_INFO:
180*0Sstevel@tonic-gate 			/*
181*0Sstevel@tonic-gate 			 * Association ID is the first element params struct
182*0Sstevel@tonic-gate 			 */
183*0Sstevel@tonic-gate 			bcopy(optval, &id, sizeof (id));
184*0Sstevel@tonic-gate 			break;
185*0Sstevel@tonic-gate 		case SCTP_DEFAULT_SEND_PARAM:
186*0Sstevel@tonic-gate 			bcopy(&((struct sctp_sndrcvinfo *)
187*0Sstevel@tonic-gate 				optval)->sinfo_assoc_id, &id, sizeof (id));
188*0Sstevel@tonic-gate 			break;
189*0Sstevel@tonic-gate 		}
190*0Sstevel@tonic-gate 
191*0Sstevel@tonic-gate 		sopt.sopt_aid = id;
192*0Sstevel@tonic-gate 		sopt.sopt_name = optname;
193*0Sstevel@tonic-gate 		sopt.sopt_val = optval;
194*0Sstevel@tonic-gate 		sopt.sopt_len = len;
195*0Sstevel@tonic-gate 		if (ioctl(sock, SIOCSCTPGOPT, &sopt) == -1) {
196*0Sstevel@tonic-gate 			err = -1;
197*0Sstevel@tonic-gate 		} else {
198*0Sstevel@tonic-gate 			*optlen = sopt.sopt_len;
199*0Sstevel@tonic-gate 		}
200*0Sstevel@tonic-gate 		return (err);
201*0Sstevel@tonic-gate 	} else {
202*0Sstevel@tonic-gate 		return (_so_getsockopt(sock, level, optname, optval, optlen,
203*0Sstevel@tonic-gate 			    SOV_DEFAULT));
204*0Sstevel@tonic-gate 	}
205*0Sstevel@tonic-gate }
206*0Sstevel@tonic-gate 
207*0Sstevel@tonic-gate int
208*0Sstevel@tonic-gate _setsockopt(int sock, int level, int optname, char *optval, int optlen)
209*0Sstevel@tonic-gate {
210*0Sstevel@tonic-gate 	return (_so_setsockopt(sock, level, optname, optval, optlen,
211*0Sstevel@tonic-gate 		SOV_DEFAULT));
212*0Sstevel@tonic-gate }
213*0Sstevel@tonic-gate 
214*0Sstevel@tonic-gate int
215*0Sstevel@tonic-gate __xnet_bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
216*0Sstevel@tonic-gate {
217*0Sstevel@tonic-gate 	return (_so_bind(sock, addr, addrlen, SOV_XPG4_2));
218*0Sstevel@tonic-gate }
219*0Sstevel@tonic-gate 
220*0Sstevel@tonic-gate 
221*0Sstevel@tonic-gate int
222*0Sstevel@tonic-gate __xnet_listen(int sock, int backlog)
223*0Sstevel@tonic-gate {
224*0Sstevel@tonic-gate 	return (_so_listen(sock, backlog, SOV_XPG4_2));
225*0Sstevel@tonic-gate }
226*0Sstevel@tonic-gate 
227*0Sstevel@tonic-gate int
228*0Sstevel@tonic-gate __xnet_connect(int sock, const struct sockaddr *addr, socklen_t addrlen)
229*0Sstevel@tonic-gate {
230*0Sstevel@tonic-gate 	return (_so_connect(sock, addr, addrlen, SOV_XPG4_2));
231*0Sstevel@tonic-gate }
232*0Sstevel@tonic-gate 
233*0Sstevel@tonic-gate int
234*0Sstevel@tonic-gate __xnet_recvmsg(int sock, struct msghdr *msg, int flags)
235*0Sstevel@tonic-gate {
236*0Sstevel@tonic-gate 	return (_so_recvmsg(sock, msg, flags | MSG_XPG4_2));
237*0Sstevel@tonic-gate }
238*0Sstevel@tonic-gate 
239*0Sstevel@tonic-gate int
240*0Sstevel@tonic-gate __xnet_sendmsg(int sock, const struct msghdr *msg, int flags)
241*0Sstevel@tonic-gate {
242*0Sstevel@tonic-gate 	return (_so_sendmsg(sock, msg, flags | MSG_XPG4_2));
243*0Sstevel@tonic-gate }
244*0Sstevel@tonic-gate 
245*0Sstevel@tonic-gate int
246*0Sstevel@tonic-gate __xnet_sendto(int sock, const void *buf, size_t len, int flags,
247*0Sstevel@tonic-gate 	const struct sockaddr *addr, socklen_t addrlen)
248*0Sstevel@tonic-gate {
249*0Sstevel@tonic-gate 	return (_so_sendto(sock, buf, len, flags | MSG_XPG4_2,
250*0Sstevel@tonic-gate 		addr, addrlen));
251*0Sstevel@tonic-gate }
252*0Sstevel@tonic-gate 
253*0Sstevel@tonic-gate int
254*0Sstevel@tonic-gate __xnet_getsockopt(int sock, int level, int option_name,
255*0Sstevel@tonic-gate 	void *option_value, socklen_t *option_lenp)
256*0Sstevel@tonic-gate {
257*0Sstevel@tonic-gate 	if (level == IPPROTO_SCTP) {
258*0Sstevel@tonic-gate 		return (_getsockopt(sock, level, option_name, option_value,
259*0Sstevel@tonic-gate 			    (int *)option_lenp));
260*0Sstevel@tonic-gate 	} else {
261*0Sstevel@tonic-gate 		return (_so_getsockopt(sock, level, option_name, option_value,
262*0Sstevel@tonic-gate 			    option_lenp, SOV_XPG4_2));
263*0Sstevel@tonic-gate 	}
264*0Sstevel@tonic-gate }
265