close() vs shutdown()
Reference:
close(sockfd);
This will prevent any more reads and writes to the socket. Anyone attempting to read or write the socket on the remote end will receive an error.
shutdown(sockfd, how);
how is one of the following:
0: Further receives are disallowed
1: Further sends are disallowed
2: Further sends and receives are disallowed (like close())
shutdown() returns 0 on success, and -1 on error (with errno set accordingly.)
If you deign to use shutdown() on unconnected datagram sockets, it will simply make the socket unavailable for further send() and recv() calls (remember that you can use these if you connect() your datagram socket.)
It's important to note that shutdown() doesn't actually close the file descriptor—it just changes its usability. To free a socket descriptor, you need to use close().