10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*5891Sraf * Common Development and Distribution License (the "License").
6*5891Sraf * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
21*5891Sraf
220Sstevel@tonic-gate /*
23*5891Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
280Sstevel@tonic-gate
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <sys/socket.h>
310Sstevel@tonic-gate #include <sys/stropts.h>
320Sstevel@tonic-gate #include <sys/stream.h>
330Sstevel@tonic-gate #include <sys/socketvar.h>
340Sstevel@tonic-gate #include <sys/sockio.h>
350Sstevel@tonic-gate
360Sstevel@tonic-gate #include <errno.h>
370Sstevel@tonic-gate #include <stdlib.h>
380Sstevel@tonic-gate #include <unistd.h>
390Sstevel@tonic-gate #include <stropts.h>
400Sstevel@tonic-gate #include <stdio.h>
410Sstevel@tonic-gate #include <strings.h>
420Sstevel@tonic-gate #include <netinet/sctp.h>
430Sstevel@tonic-gate
440Sstevel@tonic-gate #pragma weak bind = _bind
450Sstevel@tonic-gate #pragma weak listen = _listen
460Sstevel@tonic-gate #pragma weak accept = _accept
470Sstevel@tonic-gate #pragma weak connect = _connect
480Sstevel@tonic-gate #pragma weak shutdown = _shutdown
490Sstevel@tonic-gate #pragma weak recv = _recv
500Sstevel@tonic-gate #pragma weak recvfrom = _recvfrom
510Sstevel@tonic-gate #pragma weak recvmsg = _recvmsg
520Sstevel@tonic-gate #pragma weak send = _send
530Sstevel@tonic-gate #pragma weak sendmsg = _sendmsg
540Sstevel@tonic-gate #pragma weak sendto = _sendto
550Sstevel@tonic-gate #pragma weak getpeername = _getpeername
560Sstevel@tonic-gate #pragma weak getsockname = _getsockname
570Sstevel@tonic-gate #pragma weak getsockopt = _getsockopt
580Sstevel@tonic-gate #pragma weak setsockopt = _setsockopt
590Sstevel@tonic-gate
600Sstevel@tonic-gate extern int _so_bind();
610Sstevel@tonic-gate extern int _so_listen();
620Sstevel@tonic-gate extern int _so_accept();
630Sstevel@tonic-gate extern int _so_connect();
640Sstevel@tonic-gate extern int _so_shutdown();
650Sstevel@tonic-gate extern int _so_recv();
660Sstevel@tonic-gate extern int _so_recvfrom();
670Sstevel@tonic-gate extern int _so_recvmsg();
680Sstevel@tonic-gate extern int _so_send();
690Sstevel@tonic-gate extern int _so_sendmsg();
700Sstevel@tonic-gate extern int _so_sendto();
710Sstevel@tonic-gate extern int _so_getpeername();
720Sstevel@tonic-gate extern int _so_getsockopt();
730Sstevel@tonic-gate extern int _so_setsockopt();
740Sstevel@tonic-gate extern int _so_getsockname();
750Sstevel@tonic-gate
760Sstevel@tonic-gate /*
770Sstevel@tonic-gate * Note that regular sockets use SOV_SOCKBSD here to not allow a rebind of an
780Sstevel@tonic-gate * already bound socket.
790Sstevel@tonic-gate */
800Sstevel@tonic-gate int
_bind(int sock,struct sockaddr * addr,int addrlen)810Sstevel@tonic-gate _bind(int sock, struct sockaddr *addr, int addrlen)
820Sstevel@tonic-gate {
830Sstevel@tonic-gate return (_so_bind(sock, addr, addrlen, SOV_SOCKBSD));
840Sstevel@tonic-gate }
850Sstevel@tonic-gate
860Sstevel@tonic-gate int
_listen(int sock,int backlog)870Sstevel@tonic-gate _listen(int sock, int backlog)
880Sstevel@tonic-gate {
890Sstevel@tonic-gate return (_so_listen(sock, backlog, SOV_DEFAULT));
900Sstevel@tonic-gate }
910Sstevel@tonic-gate
920Sstevel@tonic-gate int
_accept(int sock,struct sockaddr * addr,int * addrlen)930Sstevel@tonic-gate _accept(int sock, struct sockaddr *addr, int *addrlen)
940Sstevel@tonic-gate {
950Sstevel@tonic-gate return (_so_accept(sock, addr, addrlen, SOV_DEFAULT));
960Sstevel@tonic-gate }
970Sstevel@tonic-gate
980Sstevel@tonic-gate int
_connect(int sock,struct sockaddr * addr,int addrlen)990Sstevel@tonic-gate _connect(int sock, struct sockaddr *addr, int addrlen)
1000Sstevel@tonic-gate {
1010Sstevel@tonic-gate return (_so_connect(sock, addr, addrlen, SOV_DEFAULT));
1020Sstevel@tonic-gate }
1030Sstevel@tonic-gate
1040Sstevel@tonic-gate int
_shutdown(int sock,int how)1050Sstevel@tonic-gate _shutdown(int sock, int how)
1060Sstevel@tonic-gate {
1070Sstevel@tonic-gate return (_so_shutdown(sock, how, SOV_DEFAULT));
1080Sstevel@tonic-gate }
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate int
_recv(int sock,char * buf,int len,int flags)1110Sstevel@tonic-gate _recv(int sock, char *buf, int len, int flags)
1120Sstevel@tonic-gate {
1130Sstevel@tonic-gate return (_so_recv(sock, buf, len, flags & ~MSG_XPG4_2));
1140Sstevel@tonic-gate }
1150Sstevel@tonic-gate
1160Sstevel@tonic-gate int
_recvfrom(int sock,char * buf,int len,int flags,struct sockaddr * addr,int * addrlen)1170Sstevel@tonic-gate _recvfrom(int sock, char *buf, int len, int flags,
1180Sstevel@tonic-gate struct sockaddr *addr, int *addrlen)
1190Sstevel@tonic-gate {
1200Sstevel@tonic-gate return (_so_recvfrom(sock, buf, len, flags & ~MSG_XPG4_2,
121*5891Sraf addr, addrlen));
1220Sstevel@tonic-gate }
1230Sstevel@tonic-gate
1240Sstevel@tonic-gate int
_recvmsg(int sock,struct msghdr * msg,int flags)1250Sstevel@tonic-gate _recvmsg(int sock, struct msghdr *msg, int flags)
1260Sstevel@tonic-gate {
1270Sstevel@tonic-gate return (_so_recvmsg(sock, msg, flags & ~MSG_XPG4_2));
1280Sstevel@tonic-gate }
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate int
_send(int sock,char * buf,int len,int flags)1310Sstevel@tonic-gate _send(int sock, char *buf, int len, int flags)
1320Sstevel@tonic-gate {
1330Sstevel@tonic-gate return (_so_send(sock, buf, len, flags & ~MSG_XPG4_2));
1340Sstevel@tonic-gate }
1350Sstevel@tonic-gate
1360Sstevel@tonic-gate int
_sendmsg(int sock,struct msghdr * msg,int flags)1370Sstevel@tonic-gate _sendmsg(int sock, struct msghdr *msg, int flags)
1380Sstevel@tonic-gate {
1390Sstevel@tonic-gate return (_so_sendmsg(sock, msg, flags & ~MSG_XPG4_2));
1400Sstevel@tonic-gate }
1410Sstevel@tonic-gate
1420Sstevel@tonic-gate int
_sendto(int sock,char * buf,int len,int flags,struct sockaddr * addr,int * addrlen)1430Sstevel@tonic-gate _sendto(int sock, char *buf, int len, int flags,
1440Sstevel@tonic-gate struct sockaddr *addr, int *addrlen)
1450Sstevel@tonic-gate {
1460Sstevel@tonic-gate return (_so_sendto(sock, buf, len, flags & ~MSG_XPG4_2,
147*5891Sraf addr, addrlen));
1480Sstevel@tonic-gate }
1490Sstevel@tonic-gate
1500Sstevel@tonic-gate int
_getpeername(int sock,struct sockaddr * name,int * namelen)1510Sstevel@tonic-gate _getpeername(int sock, struct sockaddr *name, int *namelen)
1520Sstevel@tonic-gate {
1530Sstevel@tonic-gate return (_so_getpeername(sock, name, namelen, SOV_DEFAULT));
1540Sstevel@tonic-gate }
1550Sstevel@tonic-gate
1560Sstevel@tonic-gate int
_getsockname(int sock,struct sockaddr * name,int * namelen)1570Sstevel@tonic-gate _getsockname(int sock, struct sockaddr *name, int *namelen)
1580Sstevel@tonic-gate {
1590Sstevel@tonic-gate return (_so_getsockname(sock, name, namelen, SOV_DEFAULT));
1600Sstevel@tonic-gate }
1610Sstevel@tonic-gate
1620Sstevel@tonic-gate int
_getsockopt(int sock,int level,int optname,char * optval,int * optlen)1630Sstevel@tonic-gate _getsockopt(int sock, int level, int optname, char *optval, int *optlen)
1640Sstevel@tonic-gate {
1650Sstevel@tonic-gate if (level == IPPROTO_SCTP) {
1660Sstevel@tonic-gate sctp_assoc_t id = 0;
1670Sstevel@tonic-gate socklen_t len = *optlen;
1680Sstevel@tonic-gate int err = 0;
1690Sstevel@tonic-gate struct sctpopt sopt;
1700Sstevel@tonic-gate
1710Sstevel@tonic-gate switch (optname) {
1720Sstevel@tonic-gate case SCTP_RTOINFO:
1730Sstevel@tonic-gate case SCTP_ASSOCINFO:
1740Sstevel@tonic-gate case SCTP_SET_PEER_PRIMARY_ADDR:
1750Sstevel@tonic-gate case SCTP_PRIMARY_ADDR:
1760Sstevel@tonic-gate case SCTP_PEER_ADDR_PARAMS:
1770Sstevel@tonic-gate case SCTP_STATUS:
1780Sstevel@tonic-gate case SCTP_GET_PEER_ADDR_INFO:
1790Sstevel@tonic-gate /*
1800Sstevel@tonic-gate * Association ID is the first element params struct
1810Sstevel@tonic-gate */
1820Sstevel@tonic-gate bcopy(optval, &id, sizeof (id));
1830Sstevel@tonic-gate break;
1840Sstevel@tonic-gate case SCTP_DEFAULT_SEND_PARAM:
1850Sstevel@tonic-gate bcopy(&((struct sctp_sndrcvinfo *)
186*5891Sraf optval)->sinfo_assoc_id, &id, sizeof (id));
1870Sstevel@tonic-gate break;
1880Sstevel@tonic-gate }
1890Sstevel@tonic-gate
1900Sstevel@tonic-gate sopt.sopt_aid = id;
1910Sstevel@tonic-gate sopt.sopt_name = optname;
1920Sstevel@tonic-gate sopt.sopt_val = optval;
1930Sstevel@tonic-gate sopt.sopt_len = len;
1940Sstevel@tonic-gate if (ioctl(sock, SIOCSCTPGOPT, &sopt) == -1) {
1950Sstevel@tonic-gate err = -1;
1960Sstevel@tonic-gate } else {
1970Sstevel@tonic-gate *optlen = sopt.sopt_len;
1980Sstevel@tonic-gate }
1990Sstevel@tonic-gate return (err);
2000Sstevel@tonic-gate } else {
2010Sstevel@tonic-gate return (_so_getsockopt(sock, level, optname, optval, optlen,
202*5891Sraf SOV_DEFAULT));
2030Sstevel@tonic-gate }
2040Sstevel@tonic-gate }
2050Sstevel@tonic-gate
2060Sstevel@tonic-gate int
_setsockopt(int sock,int level,int optname,char * optval,int optlen)2070Sstevel@tonic-gate _setsockopt(int sock, int level, int optname, char *optval, int optlen)
2080Sstevel@tonic-gate {
2090Sstevel@tonic-gate return (_so_setsockopt(sock, level, optname, optval, optlen,
210*5891Sraf SOV_DEFAULT));
2110Sstevel@tonic-gate }
2120Sstevel@tonic-gate
2130Sstevel@tonic-gate int
__xnet_bind(int sock,const struct sockaddr * addr,socklen_t addrlen)2140Sstevel@tonic-gate __xnet_bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
2150Sstevel@tonic-gate {
2160Sstevel@tonic-gate return (_so_bind(sock, addr, addrlen, SOV_XPG4_2));
2170Sstevel@tonic-gate }
2180Sstevel@tonic-gate
2190Sstevel@tonic-gate
2200Sstevel@tonic-gate int
__xnet_listen(int sock,int backlog)2210Sstevel@tonic-gate __xnet_listen(int sock, int backlog)
2220Sstevel@tonic-gate {
2230Sstevel@tonic-gate return (_so_listen(sock, backlog, SOV_XPG4_2));
2240Sstevel@tonic-gate }
2250Sstevel@tonic-gate
2260Sstevel@tonic-gate int
__xnet_connect(int sock,const struct sockaddr * addr,socklen_t addrlen)2270Sstevel@tonic-gate __xnet_connect(int sock, const struct sockaddr *addr, socklen_t addrlen)
2280Sstevel@tonic-gate {
2290Sstevel@tonic-gate return (_so_connect(sock, addr, addrlen, SOV_XPG4_2));
2300Sstevel@tonic-gate }
2310Sstevel@tonic-gate
2320Sstevel@tonic-gate int
__xnet_recvmsg(int sock,struct msghdr * msg,int flags)2330Sstevel@tonic-gate __xnet_recvmsg(int sock, struct msghdr *msg, int flags)
2340Sstevel@tonic-gate {
2350Sstevel@tonic-gate return (_so_recvmsg(sock, msg, flags | MSG_XPG4_2));
2360Sstevel@tonic-gate }
2370Sstevel@tonic-gate
2380Sstevel@tonic-gate int
__xnet_sendmsg(int sock,const struct msghdr * msg,int flags)2390Sstevel@tonic-gate __xnet_sendmsg(int sock, const struct msghdr *msg, int flags)
2400Sstevel@tonic-gate {
2410Sstevel@tonic-gate return (_so_sendmsg(sock, msg, flags | MSG_XPG4_2));
2420Sstevel@tonic-gate }
2430Sstevel@tonic-gate
2440Sstevel@tonic-gate int
__xnet_sendto(int sock,const void * buf,size_t len,int flags,const struct sockaddr * addr,socklen_t addrlen)2450Sstevel@tonic-gate __xnet_sendto(int sock, const void *buf, size_t len, int flags,
2460Sstevel@tonic-gate const struct sockaddr *addr, socklen_t addrlen)
2470Sstevel@tonic-gate {
2480Sstevel@tonic-gate return (_so_sendto(sock, buf, len, flags | MSG_XPG4_2,
249*5891Sraf addr, addrlen));
2500Sstevel@tonic-gate }
2510Sstevel@tonic-gate
2520Sstevel@tonic-gate int
__xnet_getsockopt(int sock,int level,int option_name,void * option_value,socklen_t * option_lenp)2530Sstevel@tonic-gate __xnet_getsockopt(int sock, int level, int option_name,
2540Sstevel@tonic-gate void *option_value, socklen_t *option_lenp)
2550Sstevel@tonic-gate {
2560Sstevel@tonic-gate if (level == IPPROTO_SCTP) {
2570Sstevel@tonic-gate return (_getsockopt(sock, level, option_name, option_value,
258*5891Sraf (int *)option_lenp));
2590Sstevel@tonic-gate } else {
2600Sstevel@tonic-gate return (_so_getsockopt(sock, level, option_name, option_value,
261*5891Sraf option_lenp, SOV_XPG4_2));
2620Sstevel@tonic-gate }
2630Sstevel@tonic-gate }
264