From: Vadim Zeitlin Date: Sun, 22 Feb 2009 23:38:07 +0000 (+0000) Subject: add accessors for sockaddr to wxSockAddress (closes #10511) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/5fab0c8d86f7bd7015db8d0ece8ce02ba1b602d8?hp=70412bd46ca03700a7bb4b4af57d690d079e9230 add accessors for sockaddr to wxSockAddress (closes #10511) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59098 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/sckaddr.h b/include/wx/sckaddr.h index 28d1500cfd..71ec921463 100644 --- a/include/wx/sckaddr.h +++ b/include/wx/sckaddr.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: sckaddr.h +// Name: wx/sckaddr.h // Purpose: Network address classes // Author: Guilhem Lavaux // Modified by: @@ -20,6 +20,11 @@ class wxSockAddressImpl; +// forward declare it instead of including the system headers defining it which +// can bring in under Windows which we don't want to include from +// public wx headers +struct sockaddr; + // Any socket address kind class WXDLLIMPEXP_NET wxSockAddress : public wxObject { @@ -41,6 +46,10 @@ public: virtual void Clear(); virtual Family Type() = 0; + // accessors for the low level address represented by this object + const sockaddr *GetAddressData() const; + int GetAddressDataLen() const; + // we need to be able to create copies of the addresses polymorphically // (i.e. without knowing the exact address class) virtual wxSockAddress *Clone() const = 0; diff --git a/interface/wx/socket.h b/interface/wx/socket.h index 0791ff4bb8..fa6cb923f9 100644 --- a/interface/wx/socket.h +++ b/interface/wx/socket.h @@ -427,6 +427,26 @@ public: Returns the length of the socket address. */ int SockAddrLen(); + + /** + Returns the pointer to the low-level representation of the address. + + This can be used to pass socket address information to a 3rd party + library. + + @return + Pointer to a sockaddr-derived struct. + */ + const sockaddr *GetAddressData() const; + + /** + Returns the length of the buffer retrieved by GetAddressData(). + + @return + The size of the sockaddr-derived struct corresponding to this + address. + */ + int GetAddressDataLen() const; }; diff --git a/src/common/sckaddr.cpp b/src/common/sckaddr.cpp index 979d06853b..b706132e5c 100644 --- a/src/common/sckaddr.cpp +++ b/src/common/sckaddr.cpp @@ -722,6 +722,16 @@ wxString wxSockAddressImpl::GetPath() const // wxSockAddress // ---------------------------------------------------------------------------- +const sockaddr *wxSockAddress::GetAddressData() const +{ + return GetAddress().GetAddr(); +} + +int wxSockAddress::GetAddressDataLen() const +{ + return GetAddress().GetLen(); +} + void wxSockAddress::Init() { if ( !wxSocketBase::IsInitialized() )