Index: lib/libc/sys/getsockopt.2 =================================================================== --- lib/libc/sys/getsockopt.2 +++ lib/libc/sys/getsockopt.2 @@ -311,6 +311,9 @@ The default value for .Dv SO_SNDLOWAT is set to a convenient size for network efficiency, often 1024. +This socket option is applicable only to +.Dv SOCK_STREAM +type sockets. .Pp .Dv SO_RCVLOWAT is an option to set the minimum count for input operations. @@ -328,6 +331,9 @@ Receive calls may still return less than the low water mark if an error occurs, a signal is caught, or the type of data next in the receive queue is different from that which was returned. +This socket option is applicable only to +.Dv SOCK_STREAM +type sockets. .Pp .Dv SO_SNDTIMEO is an option to set a timeout value for output operations. @@ -583,9 +589,10 @@ .Fa optlen is not in a valid part of the process address space. .It Bq Er EINVAL -Installing an +Use of a socket option not applicable to this kind of socket was attempted. +This includes, but is not limited to: attempt to install an .Xr accept_filter 9 -on a non-listening socket was attempted. +on a non-listening socket and attempt to set watermarks on non-stream sockets. .It Bq Er ENOMEM A memory allocation failed that was required to service the request. .El Index: sys/kern/uipc_socket.c =================================================================== --- sys/kern/uipc_socket.c +++ sys/kern/uipc_socket.c @@ -3137,10 +3137,15 @@ so->so_user_cookie = val32; break; - case SO_SNDBUF: - case SO_RCVBUF: case SO_SNDLOWAT: case SO_RCVLOWAT: + if (so->so_type != SOCK_STREAM) { + error = EINVAL; + goto bad; + } + /* FALLTHROUGH */ + case SO_SNDBUF: + case SO_RCVBUF: error = sooptcopyin(sopt, &optval, sizeof optval, sizeof optval); if (error)