1.\" $OpenBSD: shutdown.2,v 1.12 2007/05/31 19:19:34 jmc Exp $ 2.\" $NetBSD: shutdown.2,v 1.5 1995/02/27 12:37:11 cgd Exp $ 3.\" 4.\" Copyright (c) 1983, 1991, 1993 5.\" The Regents of the University of California. All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. Neither the name of the University nor the names of its contributors 16.\" may be used to endorse or promote products derived from this software 17.\" without specific prior written permission. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" SUCH DAMAGE. 30.\" 31.\" @(#)shutdown.2 8.1 (Berkeley) 6/4/93 32.\" 33.Dd $Mdocdate: May 31 2007 $ 34.Dt SHUTDOWN 2 35.Os 36.Sh NAME 37.Nm shutdown 38.Nd disable sends or receives on a socket 39.Sh SYNOPSIS 40.Fd #include <sys/types.h> 41.Fd #include <sys/socket.h> 42.Ft int 43.Fn shutdown "int s" "int how" 44.Sh DESCRIPTION 45The 46.Fn shutdown 47system call disables sends or receives on a socket. 48.Pp 49If the file descriptor 50.Fa s 51is associated with a 52.Dv SOCK_STREAM 53socket, all or part of the full-duplex connection will be shut down. 54.Pp 55The 56.Fa how 57argument specifies the type of shutdown. 58Possible values are: 59.Bl -tag -width "SHUT_RDWRXXX" -offset indent 60.It Dv SHUT_RD 61Further receives will be disallowed. 62.It Dv SHUT_WR 63Further sends will be disallowed. 64This may cause actions specific to the protocol family of the socket 65.Fa s 66to happen. 67.It Dv SHUT_RDWR 68Further sends and receives will be disallowed. 69.El 70.Pp 71The following protocol specific actions apply to the use of 72.Dv SHUT_WR 73based on the properties of the socket associated with the file descriptor 74.Fa s : 75.Bl -column "PF_INET6" "SOCK_STREAM" "IPPROTO_UDP" -offset indent 76.It DOMAIN Ta TYPE Ta PROTOCOL Ta "RETURN VALUE AND ACTION" 77.Pp 78.It Dv PF_INET Ta Dv SOCK_DGRAM Ta Dv IPPROTO_UDP Ta 79Return 0. 80ICMP messages will 81.Em not 82be generated. 83.It Dv PF_INET Ta Dv SOCK_STREAM Ta Dv IPPROTO_TCP Ta 84Return 0. 85Send queued data, wait for ACK, then send FIN. 86.It Dv PF_INET6 Ta Dv SOCK_DGRAM Ta Dv IPPROTO_UDP Ta 87Return 0. 88ICMP messages will 89.Em not 90be generated. 91.It Dv PF_INET6 Ta Dv SOCK_STREAM Ta Dv IPPROTO_TCP Ta 92Return 0. 93Send queued data, wait for ACK, then send FIN. 94.El 95.Sh RETURN VALUES 96.Rv -std shutdown 97.Sh ERRORS 98The 99.Fn shutdown 100system call fails if: 101.Bl -tag -width Er 102.It Bq Er EBADF 103The 104.Fa s 105argument is not a valid file descriptor. 106.It Bq Er EINVAL 107The 108.Fa how 109argument is invalid. 110.It Bq Er ENOTCONN 111The 112.Fa s 113argument specifies a 114.Dv SOCK_STREAM 115socket which is not connected. 116.It Bq Er ENOTSOCK 117The 118.Fa s 119argument does not refer to a socket. 120.It Bq Er EOPNOTSUPP 121The socket associated with the file descriptor 122.Fa s 123does not support this operation. 124.El 125.Sh SEE ALSO 126.Xr connect 2 , 127.Xr socket 2 , 128.Xr inet 4 , 129.Xr inet6 4 130.Sh HISTORY 131The 132.Fn shutdown 133function call appeared in 134.Bx 4.2 . 135The 136.Dv SHUT_RD , SHUT_WR , 137and 138.Dv SHUT_RDWR 139constants appeared in 140.St -p1003.1g-2000 . 141.Sh BUGS 142The ICMP 143.Dq port unreachable 144message should be generated in response to 145datagrams received on a local port to which 146.Fa s 147is bound 148after 149.Fn shutdown 150is called. 151