1

In a networking socket between two host, recv() return value will be 0 when the peer in the other end has performed an orderly shutdown.

what is the meaning of recv() returning 0 in a netlink socket(to communicate between userspace and kernel) listening in userspace? for example, in user space listening for netlink message from kernel of type RTM_NEWLINK anf family NETLINK_ROUTE.

user1762571
  • 1,888
  • 7
  • 28
  • 47
  • 1
    There is every reason to suppose that it means the same thing for a netlink socket as for any other -- the socket at the other end of the connection was cleanly closed. Under what circumstances that might happen surely depends on which netlink family you are using (roughly, which module you are talking to). – John Bollinger Oct 08 '15 at 19:06
  • Does kernel close the socket? am interested in listening for RTM_NEWLINK type messages. – user1762571 Oct 08 '15 at 19:33
  • 1
    If the kernel's end of the socket is being closed then it is certainly the kernel that closes it. In any event, `RTM_NEWLINK` is a *message type*. The corresponding netlink family is `NETLINK_ROUTE`. I don't immediately see any *documented* reason why the kernel would close such a socket, but a lot about that (and all other netlink protocols) is private and/or undocumented. – John Bollinger Oct 08 '15 at 19:45
  • I don't think `send()` and `recv()` are used for netlink sockets as they are connectionless. See: https://people.redhat.com/nhorman/papers/netlink.pdf – JMercer Dec 13 '17 at 15:52

1 Answers1

0

In a networking socket between two host, recv() return value will be 0 when the peer in the other end has performed an orderly shutdown.

That's not what it says in the man page. It says

The return value will be 0 when the peer has performed an orderly shutdown.

The part about 'in a networking socket between two hosts' is your invention.

The specification there applies to recv(), period.

what is the meaning of recv() returning 0 in a netlink socket(to communicate between userspace and kernel) listening in userspace? for example, in user space listening for netlink message from kernel of type RTM_NEWLINK anf family NETLINK_ROUTE.

The meaning is exactly the same. It's a socket, it's connected, recv() returns zero => the peer has performed an orderly shutdown.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • I found that the meaning of receiving 0 in netlink socket is EOF. I dont understand what it means in this case. Does that mean kernel has sent all the available data or kernel has closed the socket? – user1762571 Oct 09 '15 at 22:21