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