Applied patch [ 837515 ] wxIPaddress + docs patch
authorJulian Smart <julian@anthemion.co.uk>
Sun, 11 Jan 2004 15:50:10 +0000 (15:50 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Sun, 11 Jan 2004 15:50:10 +0000 (15:50 +0000)
(Ray Gilbert)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25123 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/category.tex
docs/latex/wx/classes.tex
docs/latex/wx/ipaddr.tex [new file with mode: 0644]
docs/latex/wx/ipvaddr.tex
docs/latex/wx/sckaddr.tex
include/wx/sckaddr.h
src/common/sckaddr.cpp

index 4b5f68693c02d85f968bf69570cb00ac2c7e0717..5cc2615cc3acbcca07d8b8947a6149cbf4fe943a 100644 (file)
@@ -358,6 +358,7 @@ wxWindows provides its own classes for socket based networking.
 \begin{twocollist}\itemsep=0pt
 \twocolitem{\helpref{wxDialUpManager}{wxdialupmanager}}{Provides functions to check the status of network connection and to establish one}
 \twocolitem{\helpref{wxIPV4address}{wxipv4address}}{Represents an Internet address}
+\twocolitem{\helpref{wxIPaddress}{wxipaddress}}{Represents an Internet address}
 \twocolitem{\helpref{wxSocketBase}{wxsocketbase}}{Represents a socket base object}
 \twocolitem{\helpref{wxSocketClient}{wxsocketclient}}{Represents a socket client}
 \twocolitem{\helpref{wxSocketServer}{wxsocketserver}}{Represents a socket server}
index 0e6433dafc53a86065b0a58ff63644b17564fcb5..b432699b23056a01035beaaeeb609c8c9460a74a 100644 (file)
 \input ilayout.tex
 \input indlgevt.tex
 \input inputstr.tex
+\input ipaddr.tex
 \input ipvaddr.tex
 \input joystick.tex
 \input joyevent.tex
diff --git a/docs/latex/wx/ipaddr.tex b/docs/latex/wx/ipaddr.tex
new file mode 100644 (file)
index 0000000..1e99a04
--- /dev/null
@@ -0,0 +1,146 @@
+% ----------------------------------------------------------------------------
+% CLASS: wxIPaddress
+% ----------------------------------------------------------------------------
+\section{\class{wxIPaddress}}\label{wxipaddress}
+
+wxIPaddress is an abstract base class for all internet protocol address 
+objects. Currently, only \helpref{wxIPV4address}{wxipv4address} 
+is implemented. An experimental implementation for IPV6, wxIPV6address,
+is being developed.
+
+\wxheading{Derived from}
+
+\helpref{wxSockAddress}{wxsockaddress}
+
+\wxheading{Include files}
+
+<wx/socket.h>
+
+% ----------------------------------------------------------------------------
+% MEMBERS
+% ----------------------------------------------------------------------------
+\latexignore{\rtfignore{\wxheading{Members}}}
+
+%
+% Hostname
+%
+
+\membersection{wxIPaddress::Hostname}
+
+\func{virtual bool}{Hostname}{\param{const wxString\&}{ hostname}}
+
+Set the address to {\it hostname}, which can be a host name
+or an IP-style address in a format dependent on implementation.
+
+\wxheading{Return value}
+
+Returns true on success, false if something goes wrong
+(invalid hostname or invalid IP address).
+
+%
+% Hostname
+%
+
+\membersection{wxIPaddress::Hostname}
+
+\func{virtual wxString}{Hostname}{\void}
+
+Returns the hostname which matches the IP address.
+
+%
+% IPAddress
+%
+
+\membersection{wxIPaddress::IPAddress}
+
+\func{virtual wxString}{IPAddress}{\void}
+
+Returns a wxString containing the IP address.
+
+%
+% Service
+%
+
+\membersection{wxIPaddress::Service}
+
+\func{virtual bool}{Service}{\param{const wxString\&}{ service}}
+
+Set the port to that corresponding to the specified {\it service}.
+
+\wxheading{Return value}
+
+Returns true on success, false if something goes wrong
+(invalid service).
+
+%
+% Service
+%
+
+\membersection{wxIPaddress::Service}
+
+\func{virtual bool}{Service}{\param{unsigned short}{ service}}
+
+Set the port to that corresponding to the specified {\it service}.
+
+\wxheading{Return value}
+
+Returns true on success, false if something goes wrong
+(invalid service).
+
+%
+% Service
+%
+
+\membersection{wxIPaddress::Service}
+
+\func{virtual unsigned short}{Service}{\void}
+
+Returns the current service.
+
+%
+% AnyAddress
+%
+
+\membersection{wxIPaddress::AnyAddress}\label{wxIPaddressanyaddress}
+
+\func{virtual bool}{AnyAddress}{\void}
+
+Internally, this is the same as setting the IP address
+to {\bf INADDR\_ANY}.
+
+On IPV4 implementations, 0.0.0.0
+
+On IPV6 implementations, ::
+
+\wxheading{Return value}
+
+Returns true on success, false if something went wrong.
+
+%
+% LocalHost
+%
+
+\membersection{wxIPaddress::LocalHost}\label{wxIPaddresslocalhost}
+
+\func{virtual bool}{LocalHost}{\void}
+
+Set address to localhost. 
+
+On IPV4 implementations, 127.0.0.1
+
+On IPV6 implementations, ::1
+
+\wxheading{Return value}
+
+Returns true on success, false if something went wrong.
+
+\membersection{wxIPaddress::LocalHost}\label{wxIPaddresslocalhost}
+
+\func{virtual bool}{IsLocalHost}{\void}
+
+Determines if current address is set to localhost. 
+
+\wxheading{Return value}
+
+Returns true if address is localhost, false if internet address.
+
index d78ac3ffb4be2f9991a34057f9dd9c42298272af..fef4c521a7e9aad1b19906b16dcee78aa4ce04e7 100644 (file)
@@ -5,7 +5,7 @@
 
 \wxheading{Derived from}
 
-\helpref{wxSockAddress}{wxsockaddress}
+\helpref{wxIPaddress}{wxipaddress}
 
 \wxheading{Include files}
 
index 7ab64c2b7f26623846f7e67be12e0ef03e3cefc2..07c38fbe2985534d164da14c474f098c7931cc88 100644 (file)
@@ -16,6 +16,7 @@ You are unlikely to need to use this class: only wxSocketBase uses it.
 \wxheading{See also}
 
 \helpref{wxSocketBase}{wxsocketbase}
+\helpref{wxIPaddress}{wxipaddress}
 \helpref{wxIPV4address}{wxipv4address}
 
 % ----------------------------------------------------------------------------
index bd37455fcc7b99db57adf4547c014b5e1ff3b25c..bc472331c9917de8d8a27d3195bc5412b022670d 100644 (file)
@@ -52,24 +52,58 @@ private:
   void Init();
 };
 
-class WXDLLIMPEXP_NET wxIPV4address : public wxSockAddress {
+// Interface to an IP address (either IPV4 or IPV6)
+class WXDLLIMPEXP_NET wxIPaddress : public wxSockAddress {
+  DECLARE_ABSTRACT_CLASS(wxIPaddress)
+public:
+  wxIPaddress();
+  wxIPaddress(const wxIPaddress& other);
+  virtual ~wxIPaddress();
+
+  virtual bool Hostname(const wxString& name) = 0;
+  virtual bool Service(const wxString& name) = 0;
+  virtual bool Service(unsigned short port) = 0;
+
+  virtual bool LocalHost() = 0;
+  virtual bool IsLocalHost() const = 0;
+
+  virtual bool AnyAddress() = 0;
+
+  virtual wxString IPAddress() const = 0;
+
+  virtual wxString Hostname() const = 0;
+  virtual unsigned short Service() const = 0;
+};
+
+class WXDLLIMPEXP_NET wxIPV4address : public wxIPaddress {
   DECLARE_DYNAMIC_CLASS(wxIPV4address)
 public:
   wxIPV4address();
   wxIPV4address(const wxIPV4address& other);
   virtual ~wxIPV4address();
 
-  bool Hostname(const wxString& name);
+  // IPV4 name formats
+  //
+  //                    hostname
+  // dot format         a.b.c.d
+  virtual bool Hostname(const wxString& name);
   bool Hostname(unsigned long addr);
-  bool Service(const wxString& name);
-  bool Service(unsigned short port);
-  bool LocalHost();
-  bool AnyAddress();
+  virtual bool Service(const wxString& name);
+  virtual bool Service(unsigned short port);
+
+  // localhost (127.0.0.1)
+  virtual bool LocalHost();
+  virtual bool IsLocalHost() const;
 
-  wxString Hostname();
+  // any (0.0.0.0)
+  virtual bool AnyAddress();
+
+  virtual wxString Hostname() const;
   wxString OrigHostname() { return m_origHostname; }
-  unsigned short Service();
-  wxString IPAddress() const;
+  virtual unsigned short Service() const;
+
+  // a.b.c.d
+  virtual wxString IPAddress() const;
 
   virtual int Type() { return wxSockAddress::IPV4; }
   virtual wxSockAddress *Clone() const;
@@ -80,8 +114,12 @@ private:
   wxString m_origHostname;
 };
 
-#ifdef ENABLE_IPV6
-class WXDLLIMPEXP_NET wxIPV6address : public wxSockAddress {
+#if wxUSE_IPV6
+
+// Experimental Only:
+//
+// IPV6 has not yet been implemented in socket layer
+class WXDLLIMPEXP_NET wxIPV6address : public wxIPaddress {
   DECLARE_DYNAMIC_CLASS(wxIPV6address)
 private:
   struct sockaddr_in6 *m_addr;
@@ -90,19 +128,37 @@ public:
   wxIPV6address(const wxIPV6address& other);
   virtual ~wxIPV6address();
 
-  bool Hostname(const wxString& name);
+  // IPV6 name formats
+  //
+  //                          hostname
+  //                          3ffe:ffff:0100:f101:0210:a4ff:fee3:9566 
+  // compact (base85)         Itu&-ZQ82s>J%s99FJXT
+  // compressed format        ::1
+  // ipv4 mapped              ::ffff:1.2.3.4
+  virtual bool Hostname(const wxString& name);
+
   bool Hostname(unsigned char addr[16]);
-  bool Service(const wxString& name);
-  bool Service(unsigned short port);
-  bool LocalHost();
+  virtual bool Service(const wxString& name);
+  virtual bool Service(unsigned short port);
+
+  // localhost (0000:0000:0000:0000:0000:0000:0000:0001 (::1))
+  virtual bool LocalHost();
+  virtual bool IsLocalHost() const;
 
-  wxString Hostname() const;
-  unsigned short Service() const;
+  // any (0000:0000:0000:0000:0000:0000:0000:0000 (::))
+  virtual bool AnyAddress();
+
+  // 3ffe:ffff:0100:f101:0210:a4ff:fee3:9566 
+  virtual wxString IPAddress() const;
+
+  virtual wxString Hostname() const;
+  virtual unsigned short Service() const;
 
   virtual int Type() { return wxSockAddress::IPV6; }
   virtual wxSockAddress *Clone() const { return new wxIPV6address(*this); }
 };
-#endif
+
+#endif // wxUSE_IPV6
 
 #if defined(__UNIX__) && !defined(__WINE__) && (!defined(__WXMAC__) || defined(__DARWIN__))
 #include <sys/socket.h>
index 8f667937dc82057736a9f2725ed021c94622e437..3ac7e22d9f2555f3e3abb18b3e79d630198669be 100644 (file)
 #include "wx/sckaddr.h"
 
 IMPLEMENT_ABSTRACT_CLASS(wxSockAddress, wxObject)
-IMPLEMENT_DYNAMIC_CLASS(wxIPV4address, wxSockAddress)
-#ifdef ENABLE_IPV6
-IMPLEMENT_DYNAMIC_CLASS(wxIPV6address, wxSockAddress)
+IMPLEMENT_ABSTRACT_CLASS(wxIPaddress, wxSockAddress)
+IMPLEMENT_DYNAMIC_CLASS(wxIPV4address, wxIPaddress)
+#if wxUSE_IPV6
+IMPLEMENT_DYNAMIC_CLASS(wxIPV6address, wxIPaddress)
 #endif
 #if defined(__UNIX__) && !defined(__WINE__) && (!defined(__WXMAC__) || defined(__DARWIN__))
 IMPLEMENT_DYNAMIC_CLASS(wxUNIXaddress, wxSockAddress)
 #endif
 
 // ---------------------------------------------------------------------------
-// wxIPV4address
+// wxSockAddress
 // ---------------------------------------------------------------------------
 
 void wxSockAddress::Init()
@@ -101,16 +102,35 @@ void wxSockAddress::Clear()
   m_address = GAddress_new();
 }
 
+// ---------------------------------------------------------------------------
+// wxIPaddress
+// ---------------------------------------------------------------------------
+
+wxIPaddress::wxIPaddress()
+            : wxSockAddress()
+{
+}
+
+wxIPaddress::wxIPaddress(const wxIPaddress& other)
+            : wxSockAddress(other)
+{
+}
+
+wxIPaddress::~wxIPaddress()
+{
+}
+
 // ---------------------------------------------------------------------------
 // wxIPV4address
 // ---------------------------------------------------------------------------
 
 wxIPV4address::wxIPV4address()
+             : wxIPaddress()
 {
 }
 
 wxIPV4address::wxIPV4address(const wxIPV4address& other)
-             : wxSockAddress(other)
+             : wxIPaddress(other)
 {
 }
 
@@ -155,12 +175,17 @@ bool wxIPV4address::LocalHost()
   return (GAddress_INET_SetHostName(m_address, "localhost") == GSOCK_NOERROR);
 }
 
+bool wxIPV4address::IsLocalHost() const
+{
+  return (Hostname() == wxT("localhost") || IPAddress() == wxT("127.0.0.1"));
+}
+
 bool wxIPV4address::AnyAddress()
 {
   return (GAddress_INET_SetAnyAddress(m_address) == GSOCK_NOERROR);
 }
 
-wxString wxIPV4address::Hostname()
+wxString wxIPV4address::Hostname() const
 {
    char hostname[1024];
 
@@ -169,7 +194,7 @@ wxString wxIPV4address::Hostname()
    return wxString::FromAscii(hostname);
 }
 
-unsigned short wxIPV4address::Service()
+unsigned short wxIPV4address::Service() const
 {
   return GAddress_INET_GetPort(m_address);
 }
@@ -199,18 +224,18 @@ bool wxIPV4address::operator==(wxIPV4address& addr)
        return false;
 }
 
-#if 0
+#if wxUSE_IPV6
 // ---------------------------------------------------------------------------
 // wxIPV6address
 // ---------------------------------------------------------------------------
 
 wxIPV6address::wxIPV6address()
-  : wxSockAddress()
+  : wxIPaddress()
 {
 }
 
 wxIPV6address::wxIPV6address(const wxIPV6address& other)
-             : wxSockAddress(other)
+             : wxIPaddress(other)
 {
 }
 
@@ -220,17 +245,22 @@ wxIPV6address::~wxIPV6address()
 
 bool wxIPV6address::Hostname(const wxString& name)
 {
-  return (GAddress_INET_SetHostName(m_address, name.fn_str()) == GSOCK_NOERROR);
+  if (name == wxT(""))
+  {
+    wxLogWarning( _("Trying to solve a NULL hostname: giving up") );
+    return FALSE;
+  }
+  return (GAddress_INET_SetHostName(m_address, name.mb_str()) == GSOCK_NOERROR);
 }
 
-bool wxIPV6address::Hostname(unsigned char addr[16])
+bool wxIPV6address::Hostname(unsigned char[16] WXUNUSED(addr))
 {
   return TRUE;
 }
 
-bool wxIPV6address::Service(const char *name)
+bool wxIPV6address::Service(const wxString& name)
 {
-  return (GAddress_INET_SetPortName(m_address, name.fn_str()) == GSOCK_NOERROR);
+  return (GAddress_INET_SetPortName(m_address, name.mb_str(), "tcp") == GSOCK_NOERROR);
 }
 
 bool wxIPV6address::Service(unsigned short port)
@@ -243,17 +273,43 @@ bool wxIPV6address::LocalHost()
   return (GAddress_INET_SetHostName(m_address, "localhost") == GSOCK_NOERROR);
 }
 
-const wxString& wxIPV6address::Hostname()
+bool wxIPV6address::IsLocalHost() const
+{
+  return (Hostname() == wxT("localhost") || IPAddress() == wxT("127.0.0.1"));
+}
+
+bool wxIPV6address::AnyAddress()
+{
+  return (GAddress_INET_SetAnyAddress(m_address) == GSOCK_NOERROR);
+}
+
+wxString wxIPV6address::IPAddress() const
+{      
+       unsigned long raw =  GAddress_INET_GetHostAddress(m_address);
+       return wxString::Format(
+               _T("%u.%u.%u.%u"),
+               (unsigned char)(raw & 0xff),
+               (unsigned char)((raw>>8) & 0xff),
+               (unsigned char)((raw>>16) & 0xff),
+               (unsigned char)((raw>>24) & 0xff)
+               );
+}
+
+wxString wxIPV6address::Hostname() const
 {
-  return wxString(GAddress_INET_GetHostName(m_address));
+   char hostname[1024];
+
+   hostname[0] = 0;
+   GAddress_INET_GetHostName(m_address, hostname, 1024);
+   return wxString::FromAscii(hostname);
 }
 
-unsigned short wxIPV6address::Service()
+unsigned short wxIPV6address::Service() const
 {
   return GAddress_INET_GetPort(m_address);
 }
 
-#endif // 0
+#endif // wxUSE_IPV6
 
 #if defined(__UNIX__) && !defined(__WINE__) && (!defined(__WXMAC__) || defined(__DARWIN__))