stanonik@nprdc.navy.mil (Ron Stanonik) (06/14/90)
How can I tell if a socket (4.3bsd, sunos, et al) is bound? getsockname returns a struct sockaddr_in regardless. Checking sin_port? It does seem to be 0 when unbound, but is this reliable? Next question, how can I unbind a socket? unlink it? Are either of these documented in TFM? Thanks, Ron Stanonik stanonik@nprdc.navy.mil
stanonik@nprdc.navy.mil (Ron Stanonik) (06/15/90)
"Seriously, what are you trying to do?" The problem is that I'm using a library routine (clntudp_bufcreate in sun's yp/nis library) which returns a socket. The routine apparently attempts to bind the socket to a priviledged (< 1024) port. Because of this undocumented "feature", if the user is root, then the socket returned is already bound and any attempt by the user to bind it will fail. Ah, you exclaim, check errno and if it indicates "already bound", then ignore the error. The errno, EINVAL, can mean "already bound" OR it can mean "namelen is wrong", in sunos4.X. True, I can probably assume that namelen is okay, since I code flawlessly. :-) If sun hadn't overloaded EINVAL, then checking errno would unquestionably be the solution. My question about unbinding a socket was just idle curiousity spurred by trying to deal with this "is it bound or is it not" problem. Thanks, Ron stanonik@nprdc.navy.mil