8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libsocket / socket / weaks.c
blob51e8d13e062c40e20013688d7762437c9aaaf24c
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
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>
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>
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
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();
78 * Note that regular sockets use SOV_SOCKBSD here to not allow a rebind of an
79 * already bound socket.
81 int
82 _bind(int sock, struct sockaddr *addr, int addrlen)
84 return (_so_bind(sock, addr, addrlen, SOV_SOCKBSD));
87 int
88 _listen(int sock, int backlog)
90 return (_so_listen(sock, backlog, SOV_DEFAULT));
93 int
94 _accept(int sock, struct sockaddr *addr, int *addrlen)
96 return (_so_accept(sock, addr, addrlen, SOV_DEFAULT, 0));
99 int
100 _accept4(int sock, struct sockaddr *addr, int *addrlen, int flags)
102 return (_so_accept(sock, addr, addrlen, SOV_DEFAULT, flags));
106 _connect(int sock, struct sockaddr *addr, int addrlen)
108 return (_so_connect(sock, addr, addrlen, SOV_DEFAULT));
112 _shutdown(int sock, int how)
114 return (_so_shutdown(sock, how, SOV_DEFAULT));
118 _recv(int sock, char *buf, int len, int flags)
120 return (_so_recv(sock, buf, len, flags & ~MSG_XPG4_2));
124 _recvfrom(int sock, char *buf, int len, int flags,
125 struct sockaddr *addr, int *addrlen)
127 return (_so_recvfrom(sock, buf, len, flags & ~MSG_XPG4_2,
128 addr, addrlen));
132 _recvmsg(int sock, struct msghdr *msg, int flags)
134 return (_so_recvmsg(sock, msg, flags & ~MSG_XPG4_2));
138 _send(int sock, char *buf, int len, int flags)
140 return (_so_send(sock, buf, len, flags & ~MSG_XPG4_2));
144 _sendmsg(int sock, struct msghdr *msg, int flags)
146 return (_so_sendmsg(sock, msg, flags & ~MSG_XPG4_2));
150 _sendto(int sock, char *buf, int len, int flags,
151 struct sockaddr *addr, int *addrlen)
153 return (_so_sendto(sock, buf, len, flags & ~MSG_XPG4_2,
154 addr, addrlen));
158 _getpeername(int sock, struct sockaddr *name, int *namelen)
160 return (_so_getpeername(sock, name, namelen, SOV_DEFAULT));
164 _getsockname(int sock, struct sockaddr *name, int *namelen)
166 return (_so_getsockname(sock, name, namelen, SOV_DEFAULT));
170 _getsockopt(int sock, int level, int optname, char *optval, int *optlen)
172 if (level == IPPROTO_SCTP) {
173 sctp_assoc_t id = 0;
174 socklen_t len = *optlen;
175 int err = 0;
176 struct sctpopt sopt;
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:
187 * Association ID is the first element params struct
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;
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;
206 return (err);
207 } else {
208 return (_so_getsockopt(sock, level, optname, optval, optlen,
209 SOV_DEFAULT));
214 _setsockopt(int sock, int level, int optname, char *optval, int optlen)
216 return (_so_setsockopt(sock, level, optname, optval, optlen,
217 SOV_DEFAULT));
221 __xnet_bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
223 return (_so_bind(sock, addr, addrlen, SOV_XPG4_2));
228 __xnet_listen(int sock, int backlog)
230 return (_so_listen(sock, backlog, SOV_XPG4_2));
234 __xnet_connect(int sock, const struct sockaddr *addr, socklen_t addrlen)
236 return (_so_connect(sock, addr, addrlen, SOV_XPG4_2));
240 __xnet_recvmsg(int sock, struct msghdr *msg, int flags)
242 return (_so_recvmsg(sock, msg, flags | MSG_XPG4_2));
246 __xnet_sendmsg(int sock, const struct msghdr *msg, int flags)
248 return (_so_sendmsg(sock, msg, flags | MSG_XPG4_2));
252 __xnet_sendto(int sock, const void *buf, size_t len, int flags,
253 const struct sockaddr *addr, socklen_t addrlen)
255 return (_so_sendto(sock, buf, len, flags | MSG_XPG4_2,
256 addr, addrlen));
260 __xnet_getsockopt(int sock, int level, int option_name,
261 void *option_value, socklen_t *option_lenp)
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));