shutdown(2)

shutdown2

Disable sends and/or receives on a socket

Usage

#include <sys/types.h>

#include <sys/socket.h>

int

shutdown(int s, int how);

Library

Standard C Library (libc, -lc)

Overview

The shutdown() system call disables sends or receives on a socket. The how argument specifies the type of shutdown. Possible values are:

SHUT_RD

Further receives will be disallowed.

SHUT_WR

Further sends will be disallowed. This may cause actions specific to the protocol family of the socket s to happen; see IMPLEMENTATION NOTES.

SHUT_RDWR

Further sends and receives will be disallowed. Implies SHUT_WR.

If the file descriptor s is associated with a SOCK_STREAM socket, all or part of the full-duplex connection will be shut down.

Implementation notes

The following protocol specific actions apply to the use of SHUT_WR (and potentially also SHUT_RDWR), based on the properties of the socket associated with the file descriptor s.

DomainTypeProtocolAction
PF_INETSOCK_DGRAMIPPROTO_SCTP
PF_INETSOCK_DGRAMIPPROTO_UDP
PF_INETSOCK_STREAMIPPROTO_SCTP
PF_INETSOCK_STREAMIPPROTO_TCP
PF_INET6SOCK_DGRAMIPPROTO_SCTP
PF_INET6SOCK_DGRAMIPPROTO_UDP
PF_INET6SOCK_STREAMIPPROTO_SCTP
PF_INET6SOCK_STREAMIPPROTO_TCP

Return values

The shutdown() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

Errors

The shutdown() system call fails if:

[EBADF]

The s argument is not a valid file descriptor.

[EINVAL]

The how argument is invalid.

[ENOTCONN]

The s argument specifies a socket which is not connected.

[ENOTSOCK]

The s argument does not refer to a socket.

Releases

87 releases since FreeBSD 2.0.5-RELEASE; the text changed 46 times.

  1. 2.0.5–2.1.7.1
  2. 2.2.2–2.2.8
  3. 2.2.9
  4. 3.0–3.4
  5. 3.5–3.5.1
  6. 4.0
  7. 4.1
  8. 4.1.1–4.2
  9. 4.3
  10. 4.4
  11. 4.5–4.11
  12. 5.0
  13. 5.1–6.2
  14. 6.3
  15. 6.4
  16. 7.0
  17. 7.1
  18. 7.2
  19. 7.3
  20. 7.4
  21. 8.0
  22. 8.1
  23. 8.2
  24. 8.3
  25. 8.4
  26. 9.0
  27. 9.1
  28. 9.2
  29. 9.3
  30. 10.0
  31. 10.1
  32. 10.2
  33. 10.3
  34. 10.4
  35. 11.0
  36. 11.1
  37. 11.2
  38. 11.3
  39. 11.4
  40. 12.0
  41. 12.1
  42. 12.2
  43. 12.3
  44. 12.4
  45. 13.0–13.2
  46. 13.3–14.5
  47. 15.0–16.0

Standards

The shutdown() system call is expected to comply with IEEE Std 1003.1g-2000 (“POSIX.1g”), when finalized.

History

The shutdown() system call appeared in 4.2BSD. The SHUT_RD, SHUT_WR, and SHUT_RDWR constants appeared in IEEE Std 1003.1g-2000 (“POSIX.1g”).

Authors

This manual page was updated by Bruce M. Simpson ⟨[email protected]⟩ to reflect how shutdown() behaves with PF_INET and PF_INET6 sockets.

Bugs

The ICMP “port unreachable” message should be generated in response to datagrams received on a local port to which s is bound after shutdown() is called.

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.