== You can re-_connect()_ UDP sockets (portably) A commentator on [[my entry on UDP sockets and _sendto()_ UDPConnectVsSendto]] noted: > You can disconnect or re-connect a UDP socket, at least under > Linux. The man page says: > > "If address is a null address for the protocol, the socket's peer > address shall be reset." They are absolutely correct. More than that, this is a portable socket feature; you can find similar wording in the manpages for FreeBSD and even Solaris 10, to name two Unixes that I checked manpages for. Everyone supports both completely resetting a UDP socket back to the disconnected state (as stated above) and simply changing the address that it's connected to (you just _connect()_ it to the new address). In fact this caused me to become curious about how far back this particular feature went, which is where [[the Unix Heritage Society's http://www.tuhs.org/]] [[Unix Tree http://minnie.tuhs.org/cgi-bin/utree.pl]] comes in really handy. I will cut to the chase: this _connect()_ behavior first appeared in and was first documented in the first 4.3 BSD release. It was not in 4.2 BSD, where you really could only _connect()_ a UDP socket once. (I actually read the online kernel source code to make sure of this, because I thought it might have been in the code but just not documented. No such luck. [[The relevant 4.3 BSD kernel source http://minnie.tuhs.org/cgi-bin/utree.pl?file=4.3BSD/usr/src/sys/sys/uipc_socket.c]] actually has a rare comment to explicitly discuss the new behavior; see _soconnect()_.) In an interesting note, this 4.3 BSD change apparently did not immediately make it into commercial Unixes. The [[Unix Tree]] has PDP-11 Ultrix 3.1 source online and its _soconnect()_ has the original 4.2 BSD behavior, although it was apparently released two years after 4.3 BSD. Ultrix did eventually pick up this 4.3 BSD behavior; we happen to have Ultrix 4.2 source still online and it has this change. Based on kernel source again, SunOS also appears to have picked up this change sometime between SunOS 3.5 and SunOS 4.1. (The [[SunOS history page http://en.wikipedia.org/wiki/SunOS]] suggests that this change likely appeared in SunOS 4.0 when it became fully based on 4.3 BSD.) (You may wonder why we have so much ancient Unix source code sitting around. The answer boils down to 'university sysadmins hate deleting source code, especially once it becomes an antique'. It's not like this stuff takes up much disk space, either; the entire Ultrix 4.2 source tree is only 210 MBytes. Instead the way we usually lose this historical stuff is by forgetting that it's there and then casually abandoning entire filesystems because they're just 'obsolete stuff'.)