1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Network address classes
4 // Author: Guilhem Lavaux
8 // Copyright: (c) 1997, 1998 Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_NETWORK_ADDRESS_H
13 #define _WX_NETWORK_ADDRESS_H
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "sckaddr.h"
23 #include "wx/string.h"
24 #include "wx/gsocket.h"
27 class WXDLLIMPEXP_NET wxSockAddress
: public wxObject
{
28 DECLARE_ABSTRACT_CLASS(wxSockAddress
)
30 typedef enum { IPV4
=1, IPV6
=2, UNIX
=3 } Addr
;
33 wxSockAddress(const wxSockAddress
& other
);
34 virtual ~wxSockAddress();
36 wxSockAddress
& operator=(const wxSockAddress
& other
);
39 virtual int Type() = 0;
41 GAddress
*GetAddress() const { return m_address
; }
42 void SetAddress(GAddress
*address
);
44 // we need to be able to create copies of the addresses polymorphically (i.e.
45 // without knowing the exact address class)
46 virtual wxSockAddress
*Clone() const = 0;
55 // Interface to an IP address (either IPV4 or IPV6)
56 class WXDLLIMPEXP_NET wxIPaddress
: public wxSockAddress
{
57 DECLARE_ABSTRACT_CLASS(wxIPaddress
)
60 wxIPaddress(const wxIPaddress
& other
);
61 virtual ~wxIPaddress();
63 virtual bool Hostname(const wxString
& name
) = 0;
64 virtual bool Service(const wxString
& name
) = 0;
65 virtual bool Service(unsigned short port
) = 0;
67 virtual bool LocalHost() = 0;
68 virtual bool IsLocalHost() const = 0;
70 virtual bool AnyAddress() = 0;
72 virtual wxString
IPAddress() const = 0;
74 virtual wxString
Hostname() const = 0;
75 virtual unsigned short Service() const = 0;
78 class WXDLLIMPEXP_NET wxIPV4address
: public wxIPaddress
{
79 DECLARE_DYNAMIC_CLASS(wxIPV4address
)
82 wxIPV4address(const wxIPV4address
& other
);
83 virtual ~wxIPV4address();
89 virtual bool Hostname(const wxString
& name
);
90 bool Hostname(unsigned long addr
);
91 virtual bool Service(const wxString
& name
);
92 virtual bool Service(unsigned short port
);
94 // localhost (127.0.0.1)
95 virtual bool LocalHost();
96 virtual bool IsLocalHost() const;
99 virtual bool AnyAddress();
101 virtual wxString
Hostname() const;
102 wxString
OrigHostname() { return m_origHostname
; }
103 virtual unsigned short Service() const;
106 virtual wxString
IPAddress() const;
108 virtual int Type() { return wxSockAddress::IPV4
; }
109 virtual wxSockAddress
*Clone() const;
111 bool operator==(wxIPV4address
& addr
);
114 wxString m_origHostname
;
118 // the IPv6 code probably doesn't work, untested -- set to 1 at your own risk
125 // Experimental Only:
127 // IPV6 has not yet been implemented in socket layer
128 class WXDLLIMPEXP_NET wxIPV6address
: public wxIPaddress
{
129 DECLARE_DYNAMIC_CLASS(wxIPV6address
)
131 struct sockaddr_in6
*m_addr
;
134 wxIPV6address(const wxIPV6address
& other
);
135 virtual ~wxIPV6address();
140 // 3ffe:ffff:0100:f101:0210:a4ff:fee3:9566
141 // compact (base85) Itu&-ZQ82s>J%s99FJXT
142 // compressed format ::1
143 // ipv4 mapped ::ffff:1.2.3.4
144 virtual bool Hostname(const wxString
& name
);
146 bool Hostname(unsigned char addr
[16]);
147 virtual bool Service(const wxString
& name
);
148 virtual bool Service(unsigned short port
);
150 // localhost (0000:0000:0000:0000:0000:0000:0000:0001 (::1))
151 virtual bool LocalHost();
152 virtual bool IsLocalHost() const;
154 // any (0000:0000:0000:0000:0000:0000:0000:0000 (::))
155 virtual bool AnyAddress();
157 // 3ffe:ffff:0100:f101:0210:a4ff:fee3:9566
158 virtual wxString
IPAddress() const;
160 virtual wxString
Hostname() const;
161 virtual unsigned short Service() const;
163 virtual int Type() { return wxSockAddress::IPV6
; }
164 virtual wxSockAddress
*Clone() const { return new wxIPV6address(*this); }
169 #if defined(__UNIX__) && !defined(__WINE__) && (!defined(__WXMAC__) || defined(__DARWIN__)) && !defined(__WXMSW__)
170 #include <sys/socket.h>
175 class WXDLLIMPEXP_NET wxUNIXaddress
: public wxSockAddress
{
176 DECLARE_DYNAMIC_CLASS(wxUNIXaddress
)
178 struct sockaddr_un
*m_addr
;
181 wxUNIXaddress(const wxUNIXaddress
& other
);
182 virtual ~wxUNIXaddress();
184 void Filename(const wxString
& name
);
187 virtual int Type() { return wxSockAddress::UNIX
; }
188 virtual wxSockAddress
*Clone() const { return new wxUNIXaddress(*this); }
197 // _WX_NETWORK_ADDRESS_H