From e1e6bf1e482f109ead1e62589373d7a165754009 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 12 Jul 2006 09:21:57 +0000 Subject: * fhandler_socket.cc (fhandler_socket::getsockname): Return valid result for unbound sockets. --- winsup/cygwin/ChangeLog | 5 +++++ winsup/cygwin/fhandler_socket.cc | 31 ++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) 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 + + * fhandler_socket.cc (fhandler_socket::getsockname): Return valid + result for unbound sockets. + 2006-07-11 Corinna Vinschen * 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; -- cgit v1.1