diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2006-07-12 09:21:57 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2006-07-12 09:21:57 +0000 |
commit | e1e6bf1e482f109ead1e62589373d7a165754009 (patch) | |
tree | 2986e6b62823efd9cd6412805e2615a8911d9d73 | |
parent | 7e6248ec083f9339cb09e25c8f5a111ce415d82a (diff) | |
download | newlib-e1e6bf1e482f109ead1e62589373d7a165754009.zip newlib-e1e6bf1e482f109ead1e62589373d7a165754009.tar.gz newlib-e1e6bf1e482f109ead1e62589373d7a165754009.tar.bz2 |
* fhandler_socket.cc (fhandler_socket::getsockname): Return valid
result for unbound sockets.
-rw-r--r-- | winsup/cygwin/ChangeLog | 5 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_socket.cc | 31 |
2 files changed, 35 insertions, 1 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 4f1a766..836b2b7 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +2006-07-12 Corinna Vinschen <corinna@vinschen.de> + + * fhandler_socket.cc (fhandler_socket::getsockname): Return valid + result for unbound sockets. + 2006-07-11 Corinna Vinschen <corinna@vinschen.de> * fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index fa661fb..f5ca995 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -1195,7 +1195,36 @@ fhandler_socket::getsockname (struct sockaddr *name, int *namelen) { res = ::getsockname (get_socket (), name, namelen); if (res) - set_winsock_errno (); + { + if (WSAGetLastError () == WSAEINVAL) + { + /* Winsock returns WSAEINVAL if the socket is locally + unbound. Per SUSv3 this is not an error condition. + We're faking a valid return value here by creating the + same content in the sockaddr structure as on Linux. */ + switch (get_addr_family ()) + { + case AF_INET: + res = 0; + *namelen = sizeof (struct sockaddr_in); + break; + case AF_INET6: + res = 0; + *namelen = sizeof (struct sockaddr_in6); + break; + default: + WSASetLastError (WSAEOPNOTSUPP); + break; + } + if (!res) + { + memset (name, 0, *namelen); + name->sa_family = get_addr_family (); + } + } + if (res) + set_winsock_errno (); + } } return res; |