--- /dev/null	Sun Aug  5 23:41:04 2018
+++ new/usr/src/lib/libc/port/socket/socket.c	Sun Aug  5 23:41:04 2018
@@ -0,0 +1,303 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
+ * Copyright 2018 Nexenta Systems, Inc.
+ */
+
+#include "lint.h"
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/stropts.h>
+#include <sys/stream.h>
+#include <sys/socketvar.h>
+#include <sys/sockio.h>
+
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stropts.h>
+#include <stdio.h>
+#include <strings.h>
+#include <netinet/sctp.h>
+
+#pragma weak accept = _accept
+#pragma weak accept4 = _accept4
+#pragma weak bind = _bind
+#pragma weak connect = _connect
+#pragma weak getpeername = _getpeername
+#pragma weak getsockname = _getsockname
+#pragma weak getsockopt = _getsockopt
+#pragma weak listen = _listen
+#pragma weak recv = _recv
+#pragma weak recvfrom = _recvfrom
+#pragma weak recvmsg = _recvmsg
+#pragma weak send = _send
+#pragma weak sendmsg = _sendmsg
+#pragma weak sendto = _sendto
+#pragma weak setsockopt = _setsockopt
+#pragma weak shutdown = _shutdown
+#pragma weak socket = _socket
+
+extern int _so_accept(int, struct sockaddr *, socklen_t *, int, int);
+extern int _so_bind(int, const struct sockaddr *, socklen_t, int);
+extern int _so_connect(int, const struct sockaddr *, socklen_t, int);
+extern int _so_getpeername(int, struct sockaddr *, socklen_t *,
+    int);
+extern int _so_getsockname(int, struct sockaddr *, socklen_t *,
+    int);
+extern int _so_getsockopt(int, int, int, void *, socklen_t *, int);
+extern int _so_listen(int, int, int);
+extern ssize_t _so_recv(int, void *, size_t, int);
+extern ssize_t _so_recvfrom(int, void *, size_t, int, struct sockaddr *,
+    socklen_t *);
+extern ssize_t _so_recvmsg(int, struct msghdr *, int);
+extern ssize_t _so_send(int, const void *, size_t, int);
+extern ssize_t _so_sendmsg(int, const struct msghdr *, int);
+extern ssize_t _so_sendto(int, const void *, size_t, int,
+    const struct sockaddr *, socklen_t);
+extern int _so_setsockopt(int, int, int, const void *, socklen_t, int);
+extern int _so_shutdown(int, int, int);
+extern int _so_socket(int, int, int, dev_t, int);
+
+int
+_accept(int sock, struct sockaddr *_RESTRICT_KYWD addr, socklen_t *addrlen)
+{
+	return (_so_accept(sock, addr, addrlen, SOV_DEFAULT, 0));
+}
+
+int
+_accept4(int sock, struct sockaddr *_RESTRICT_KYWD addr, socklen_t *addrlen,
+    int flags)
+{
+	return (_so_accept(sock, addr, addrlen, SOV_DEFAULT, flags));
+}
+
+/*
+ * Note that regular sockets use SOV_SOCKBSD here to not allow a rebind of an
+ * already bound socket.
+ */
+int
+_bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
+{
+	return (_so_bind(sock, addr, addrlen, SOV_SOCKBSD));
+}
+
+int
+_connect(int sock, const struct sockaddr *addr, socklen_t addrlen)
+{
+	return (_so_connect(sock, addr, addrlen, SOV_DEFAULT));
+}
+
+int
+_getpeername(int sock, struct sockaddr *_RESTRICT_KYWD name, socklen_t *namelen)
+{
+	return (_so_getpeername(sock, name, namelen, SOV_DEFAULT));
+}
+
+int
+_getsockname(int sock, struct sockaddr *_RESTRICT_KYWD name, socklen_t *namelen)
+{
+	return (_so_getsockname(sock, name, namelen, SOV_DEFAULT));
+}
+
+int
+_getsockopt(int sock, int level, int optname, void *_RESTRICT_KYWD optval,
+    socklen_t *optlen)
+{
+	if (level == IPPROTO_SCTP) {
+		sctp_assoc_t id = 0;
+		socklen_t len = *optlen;
+		int err = 0;
+		struct sctpopt sopt;
+
+		switch (optname) {
+		case SCTP_RTOINFO:
+		case SCTP_ASSOCINFO:
+		case SCTP_SET_PEER_PRIMARY_ADDR:
+		case SCTP_PRIMARY_ADDR:
+		case SCTP_PEER_ADDR_PARAMS:
+		case SCTP_STATUS:
+		case SCTP_GET_PEER_ADDR_INFO:
+			/*
+			 * Association ID is the first element params struct
+			 */
+			bcopy(optval, &id, sizeof (id));
+			break;
+		case SCTP_DEFAULT_SEND_PARAM:
+			bcopy(&((struct sctp_sndrcvinfo *)
+			    optval)->sinfo_assoc_id, &id, sizeof (id));
+			break;
+		}
+
+		sopt.sopt_aid = id;
+		sopt.sopt_name = optname;
+		sopt.sopt_val = optval;
+		sopt.sopt_len = len;
+		if (ioctl(sock, SIOCSCTPGOPT, &sopt) == -1) {
+			err = -1;
+		} else {
+			*optlen = sopt.sopt_len;
+		}
+		return (err);
+	} else {
+		return (_so_getsockopt(sock, level, optname, optval, optlen,
+		    SOV_DEFAULT));
+	}
+}
+
+int
+_listen(int sock, int backlog)
+{
+	return (_so_listen(sock, backlog, SOV_DEFAULT));
+}
+
+ssize_t
+_recv(int sock, void *buf, size_t len, int flags)
+{
+	return (_so_recv(sock, buf, len, flags & ~MSG_XPG4_2));
+}
+
+int
+_recvfrom(int sock, void *_RESTRICT_KYWD buf, size_t len, int flags,
+    struct sockaddr *_RESTRICT_KYWD addr, socklen_t *addrlen)
+{
+	return (_so_recvfrom(sock, buf, len, flags & ~MSG_XPG4_2,
+	    addr, addrlen));
+}
+
+ssize_t
+_recvmsg(int sock, struct msghdr *msg, int flags)
+{
+	return (_so_recvmsg(sock, msg, flags & ~MSG_XPG4_2));
+}
+
+ssize_t
+_send(int sock, const void *buf, size_t len, int flags)
+{
+	return (_so_send(sock, buf, len, flags & ~MSG_XPG4_2));
+}
+
+ssize_t
+_sendmsg(int sock, const struct msghdr *msg, int flags)
+{
+	return (_so_sendmsg(sock, msg, flags & ~MSG_XPG4_2));
+}
+
+ssize_t
+_sendto(int sock, const void *buf, size_t len, int flags,
+    const struct sockaddr *addr, socklen_t addrlen)
+{
+	return (_so_sendto(sock, buf, len, flags & ~MSG_XPG4_2, addr, addrlen));
+}
+
+int
+_setsockopt(int sock, int level, int optname, const void *optval,
+    socklen_t optlen)
+{
+	return (_so_setsockopt(sock, level, optname, optval, optlen,
+	    SOV_DEFAULT));
+}
+
+int
+_shutdown(int sock, int how)
+{
+	return (_so_shutdown(sock, how, SOV_DEFAULT));
+}
+
+int
+_socket(int family, int type, int protocol)
+{
+	return (_so_socket(family, type, protocol, NULL, SOV_DEFAULT));
+}
+
+/*
+ * Used by the BCP library.
+ */
+int
+_socket_bsd(int family, int type, int protocol)
+{
+	return (_so_socket(family, type, protocol, NULL, SOV_SOCKBSD));
+}
+
+
+int
+__xnet_bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
+{
+	return (_so_bind(sock, addr, addrlen, SOV_XPG4_2));
+}
+
+int
+__xnet_connect(int sock, const struct sockaddr *addr, socklen_t addrlen)
+{
+	return (_so_connect(sock, addr, addrlen, SOV_XPG4_2));
+}
+
+int
+__xnet_getsockopt(int sock, int level, int optname, void *optval,
+    socklen_t *optlen)
+{
+	if (level == IPPROTO_SCTP) {
+		return (_getsockopt(sock, level, optname, optval, optlen));
+	} else {
+		return (_so_getsockopt(sock, level, optname, optval, optlen,
+		    SOV_XPG4_2));
+	}
+}
+
+int
+__xnet_listen(int sock, int backlog)
+{
+	return (_so_listen(sock, backlog, SOV_XPG4_2));
+}
+
+int
+__xnet_recvmsg(int sock, struct msghdr *msg, int flags)
+{
+	return (_so_recvmsg(sock, msg, flags | MSG_XPG4_2));
+}
+
+int
+__xnet_sendmsg(int sock, const struct msghdr *msg, int flags)
+{
+	return (_so_sendmsg(sock, msg, flags | MSG_XPG4_2));
+}
+
+int
+__xnet_sendto(int sock, const void *buf, size_t len, int flags,
+	const struct sockaddr *addr, socklen_t addrlen)
+{
+	return (_so_sendto(sock, buf, len, flags | MSG_XPG4_2,
+	    addr, addrlen));
+}
+
+int
+__xnet_socket(int family, int type, int protocol)
+{
+	return (_so_socket(family, type, protocol, NULL, SOV_XPG4_2));
+}
