/Externals/wxWidgets3/include/wx/sckaddr.h

https://gitlab.com/Hexexpeck/dolphin-emulator · C Header · 218 lines · 122 code · 62 blank · 34 comment · 2 complexity · 499e06e62fcfe4452dd2a1d7d18eb261 MD5 · raw file

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/sckaddr.h
  3. // Purpose: Network address classes
  4. // Author: Guilhem Lavaux
  5. // Modified by: Vadim Zeitlin to switch to wxSockAddressImpl implementation
  6. // Created: 26/04/1997
  7. // Copyright: (c) 1997, 1998 Guilhem Lavaux
  8. // (c) 2008, 2009 Vadim Zeitlin
  9. // Licence: wxWindows licence
  10. /////////////////////////////////////////////////////////////////////////////
  11. #ifndef _WX_SCKADDR_H_
  12. #define _WX_SCKADDR_H_
  13. #include "wx/defs.h"
  14. #if wxUSE_SOCKETS
  15. #include "wx/string.h"
  16. class wxSockAddressImpl;
  17. // forward declare it instead of including the system headers defining it which
  18. // can bring in <windows.h> under Windows which we don't want to include from
  19. // public wx headers
  20. struct sockaddr;
  21. // Any socket address kind
  22. class WXDLLIMPEXP_NET wxSockAddress : public wxObject
  23. {
  24. public:
  25. enum Family
  26. {
  27. NONE,
  28. IPV4,
  29. IPV6,
  30. UNIX
  31. };
  32. wxSockAddress();
  33. wxSockAddress(const wxSockAddress& other);
  34. virtual ~wxSockAddress();
  35. wxSockAddress& operator=(const wxSockAddress& other);
  36. virtual void Clear();
  37. virtual Family Type() = 0;
  38. // accessors for the low level address represented by this object
  39. const sockaddr *GetAddressData() const;
  40. int GetAddressDataLen() const;
  41. // we need to be able to create copies of the addresses polymorphically
  42. // (i.e. without knowing the exact address class)
  43. virtual wxSockAddress *Clone() const = 0;
  44. // implementation only, don't use
  45. const wxSockAddressImpl& GetAddress() const { return *m_impl; }
  46. void SetAddress(const wxSockAddressImpl& address);
  47. protected:
  48. wxSockAddressImpl *m_impl;
  49. private:
  50. void Init();
  51. wxDECLARE_ABSTRACT_CLASS(wxSockAddress);
  52. };
  53. // An IP address (either IPv4 or IPv6)
  54. class WXDLLIMPEXP_NET wxIPaddress : public wxSockAddress
  55. {
  56. public:
  57. wxIPaddress() : wxSockAddress() { }
  58. wxIPaddress(const wxIPaddress& other)
  59. : wxSockAddress(other),
  60. m_origHostname(other.m_origHostname)
  61. {
  62. }
  63. bool operator==(const wxIPaddress& addr) const;
  64. bool Hostname(const wxString& name);
  65. bool Service(const wxString& name);
  66. bool Service(unsigned short port);
  67. bool LocalHost();
  68. virtual bool IsLocalHost() const = 0;
  69. bool AnyAddress();
  70. virtual wxString IPAddress() const = 0;
  71. wxString Hostname() const;
  72. unsigned short Service() const;
  73. wxString OrigHostname() const { return m_origHostname; }
  74. protected:
  75. // get m_impl initialized to the right family if it hadn't been done yet
  76. wxSockAddressImpl& GetImpl();
  77. const wxSockAddressImpl& GetImpl() const
  78. {
  79. return const_cast<wxIPaddress *>(this)->GetImpl();
  80. }
  81. // host name originally passed to Hostname()
  82. wxString m_origHostname;
  83. private:
  84. // create the wxSockAddressImpl object of the correct family if it's
  85. // currently uninitialized
  86. virtual void DoInitImpl() = 0;
  87. wxDECLARE_ABSTRACT_CLASS(wxIPaddress);
  88. };
  89. // An IPv4 address
  90. class WXDLLIMPEXP_NET wxIPV4address : public wxIPaddress
  91. {
  92. public:
  93. wxIPV4address() : wxIPaddress() { }
  94. wxIPV4address(const wxIPV4address& other) : wxIPaddress(other) { }
  95. // implement wxSockAddress pure virtuals:
  96. virtual Family Type() wxOVERRIDE { return IPV4; }
  97. virtual wxSockAddress *Clone() const wxOVERRIDE { return new wxIPV4address(*this); }
  98. // implement wxIPaddress pure virtuals:
  99. virtual bool IsLocalHost() const wxOVERRIDE;
  100. virtual wxString IPAddress() const wxOVERRIDE;
  101. // IPv4-specific methods:
  102. bool Hostname(unsigned long addr);
  103. // make base class methods hidden by our overload visible
  104. using wxIPaddress::Hostname;
  105. bool BroadcastAddress();
  106. private:
  107. virtual void DoInitImpl() wxOVERRIDE;
  108. wxDECLARE_DYNAMIC_CLASS(wxIPV4address);
  109. };
  110. #if wxUSE_IPV6
  111. // An IPv6 address
  112. class WXDLLIMPEXP_NET wxIPV6address : public wxIPaddress
  113. {
  114. public:
  115. wxIPV6address() : wxIPaddress() { }
  116. wxIPV6address(const wxIPV6address& other) : wxIPaddress(other) { }
  117. // implement wxSockAddress pure virtuals:
  118. virtual Family Type() { return IPV6; }
  119. virtual wxSockAddress *Clone() const { return new wxIPV6address(*this); }
  120. // implement wxIPaddress pure virtuals:
  121. virtual bool IsLocalHost() const;
  122. virtual wxString IPAddress() const;
  123. // IPv6-specific methods:
  124. bool Hostname(unsigned char addr[16]);
  125. using wxIPaddress::Hostname;
  126. private:
  127. virtual void DoInitImpl();
  128. wxDECLARE_DYNAMIC_CLASS(wxIPV6address);
  129. };
  130. #endif // wxUSE_IPV6
  131. // Unix domain sockets are only available under, well, Unix
  132. #if defined(__UNIX__) && !defined(__WINDOWS__) && !defined(__WINE__)
  133. #define wxHAS_UNIX_DOMAIN_SOCKETS
  134. #endif
  135. #ifdef wxHAS_UNIX_DOMAIN_SOCKETS
  136. // A Unix domain socket address
  137. class WXDLLIMPEXP_NET wxUNIXaddress : public wxSockAddress
  138. {
  139. public:
  140. wxUNIXaddress() : wxSockAddress() { }
  141. wxUNIXaddress(const wxUNIXaddress& other) : wxSockAddress(other) { }
  142. void Filename(const wxString& name);
  143. wxString Filename() const;
  144. virtual Family Type() wxOVERRIDE { return UNIX; }
  145. virtual wxSockAddress *Clone() const wxOVERRIDE { return new wxUNIXaddress(*this); }
  146. private:
  147. wxSockAddressImpl& GetUNIX();
  148. const wxSockAddressImpl& GetUNIX() const
  149. {
  150. return const_cast<wxUNIXaddress *>(this)->GetUNIX();
  151. }
  152. wxDECLARE_DYNAMIC_CLASS(wxUNIXaddress);
  153. };
  154. #endif // wxHAS_UNIX_DOMAIN_SOCKETS
  155. #endif // wxUSE_SOCKETS
  156. #endif // _WX_SCKADDR_H_