17

TCP shows LISTENING in the state column while UDP does not show anything:

enter image description here

Is it because UDP has only one state (which is LISTENING) so there is no need to show it, or is there another reason?

Tom
  • 15
  • 5
user613132
  • 171
  • 1
  • 1
  • 3
  • 3
    UDP is a stateless protocol. – Patrick Seymour Jul 03 '16 at 22:24
  • @Patrick S So the listening that a UDP socket does is not called a state? – user613132 Jul 03 '16 at 22:29
  • 3
    Check out: http://stackoverflow.com/questions/8194323/why-the-listen-function-call-is-not-needed-when-use-udp-socket --> Quoted Answer --> "TCP is a streaming protocol between a server and clients. The protocol is reliable and requires separate state for each server<>client stream. The connect protocol, initiated with listen/accept, sets up this server<>client connection state. UDP is a connectionless, unreliable datagram, (message) protocol, so no need to listen for new connections - datagrams can come in in any order from any source." – Vomit IT - Chunky Mess Style Jul 03 '16 at 22:56
  • @PIMP_JUICE_IT So when we say that a socket **listens** on a port, we mean that it is listening for connection requests, and because a UDP socket does not listens for connection requests (it just opens a port and waits for datagrams), then a UDP socket is not said to be in a *LISTENING* state. Am I correct? – user613132 Jul 03 '16 at 23:26

2 Answers2

19

As mentioned in the comments, UDP is connectionless. Unlike with TCP, it has no concept of "listening", "established", "closed", or anything like that. If a UDP port is open, it appears in the listing; if it's not open, it doesn't. There is no other state to display. Showing LISTENING or something similar in that column could imply that there are other possible states, and that would be false.

Ben N
  • 40,045
  • 17
  • 140
  • 181
2

In spite of claims that netstat doesn't show state because UDP is stateless, netstat on non-Windows OS's does show a value for the State column. For instance, Solaris shows either "Idle" or "Unbound". As far as I can tell "Idle" sockets are the ones bound to particular local ports, while "Unbound" sockets are always "*.*" and so presumably somehow open but not tied to particular ports. netstat on Linux can show at least "ESTABLISHED". Also, I'd still like to know whether a UDP port is expecting connections from elsewhere to initiate traffic or is just open so it can send stuff elsewhere.

  • "_I'd still like to know whether a UDP port is expecting connections from elsewhere to initiate traffic or is just open so it can send stuff elsewhere._" Because UDP is connectionless, it is never expecting to send or receive anything. It will happily do either. It is the application using UDP that expects to send, receive, or both. – Ron Maupin Mar 19 '18 at 22:29
  • To the casual observer, you seem to be saying that Casual Reader’s suggestion is impossible.  In fact, you’re just quibbling over terminology.  Just like for a pipe or a tty (with regard to `read`), either there is or there isn’t a process waiting on a blocking `recv` (or related) system call, and the kernel knows whether there is such a process (because, just like with a pipe or a tty, it has to know how to react when input appears).  So it ought to be possible for ``netstat`` to determine and report whether a process is waiting to have data sent to it on a UDP socket. – Scott - Слава Україні Mar 19 '18 at 23:20