From 7172db18572590af6b79492bcabe284de33bd090 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 9 May 2009 13:07:21 +0000 Subject: [PATCH] initialize the local address before calling getsockname() on it (closes #10779) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60567 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/private/sckaddr.h | 24 ++++++++++++++++++++++++ src/common/socket.cpp | 8 ++++++++ 2 files changed, 32 insertions(+) diff --git a/include/wx/private/sckaddr.h b/include/wx/private/sckaddr.h index 19f9e0f674..a4971fd4aa 100644 --- a/include/wx/private/sckaddr.h +++ b/include/wx/private/sckaddr.h @@ -166,6 +166,30 @@ public: #ifdef wxHAS_UNIX_DOMAIN_SOCKETS void CreateUnix(); #endif // wxHAS_UNIX_DOMAIN_SOCKETS + void Create(Family family) + { + switch ( family ) + { + case FAMILY_INET: + CreateINET(); + break; + +#if wxUSE_IPV6 + case FAMILY_INET6: + CreateINET6(); + break; +#endif + +#ifdef wxHAS_UNIX_DOMAIN_SOCKETS + case FAMILY_UNIX: +#endif + CreateUnix(); + break; + + default: + wxFAIL_MSG( "unsupported socket address family" ); + } + } // simple accessors Family GetFamily() const { return m_family; } diff --git a/src/common/socket.cpp b/src/common/socket.cpp index 3c4f417e75..c7af4a2600 100644 --- a/src/common/socket.cpp +++ b/src/common/socket.cpp @@ -364,6 +364,14 @@ void wxSocketImpl::PostCreation() wxSocketError wxSocketImpl::UpdateLocalAddress() { + if ( !m_local.IsOk() ) + { + // ensure that we have a valid object using the correct family: correct + // being the same one as our peer uses as we have no other way to + // determine it + m_local.Create(m_peer.GetFamily()); + } + WX_SOCKLEN_T lenAddr = m_local.GetLen(); if ( getsockname(m_fd, m_local.GetWritableAddr(), &lenAddr) != 0 ) { -- 2.45.2