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