diff --git a/lib/libsys/getsockopt.2 b/lib/libsys/getsockopt.2
--- a/lib/libsys/getsockopt.2
+++ b/lib/libsys/getsockopt.2
@@ -173,7 +173,7 @@
 .It Dv SO_TYPE Ta "get the type of the socket (get only)"
 .It Dv SO_PROTOCOL Ta "get the protocol number for the socket (get only)"
 .It Dv SO_PROTOTYPE Ta "SunOS alias for the Linux SO_PROTOCOL (get only)"
-.It Dv SO_ERROR Ta "get and clear error on the socket (get only)"
+.It Dv SO_ERROR Ta "get and set error on the socket"
 .It Dv SO_RERROR Ta "enables receive error reporting"
 .It Dv SO_SETFIB Ta "set the associated FIB (routing table) for the socket (set only)"
 .El
@@ -202,6 +202,15 @@
 .Xr bind 2
 system call should allow reuse of local addresses.
 .Pp
+.Dv SO_ERROR can be used with
+.Fn getsockopt
+to return a pending error and clear the error status.
+It may be used to check for asynchronous errors on connected
+datagram sockets or for other asynchronous errors.
+It may be used with
+.Fn setsockopt
+to set the error status on the socket.
+.Pp
 .Dv SO_REUSEPORT
 allows completely duplicate bindings by multiple processes
 if they all set
@@ -485,11 +494,10 @@
 .Pp
 .Dv SO_ACCEPTCONN ,
 .Dv SO_TYPE ,
+and
 .Dv SO_PROTOCOL
 (and its alias
 .Dv SO_PROTOTYPE )
-and
-.Dv SO_ERROR
 are options used only with
 .Fn getsockopt .
 .Dv SO_ACCEPTCONN
@@ -507,11 +515,6 @@
 and
 .Dv AF_INET6
 address families.
-.Dv SO_ERROR
-returns any pending error on the socket and clears
-the error status.
-It may be used to check for asynchronous errors on connected
-datagram sockets or for other asynchronous errors.
 .Dv SO_RERROR
 indicates that receive buffer overflows should be handled as errors.
 Historically receive buffer overflows have been ignored and programs
diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c
--- a/sys/kern/uipc_socket.c
+++ b/sys/kern/uipc_socket.c
@@ -3149,6 +3149,16 @@
 			SOCK_UNLOCK(so);
 			break;
 
+		case SO_ERROR:
+			error = sooptcopyin(sopt, &optval, sizeof optval,
+			    sizeof optval);
+			if (error)
+				goto bad;
+			SOCK_LOCK(so);
+			so->so_error = optval;
+			SOCK_UNLOCK(so);
+			break;
+
 		case SO_DEBUG:
 		case SO_KEEPALIVE:
 		case SO_DONTROUTE: