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
19 #include "wx/string.h"
20 #include "wx/gsocket.h"
23 class WXDLLIMPEXP_NET wxSockAddress
: public wxObject
{
24 DECLARE_ABSTRACT_CLASS(wxSockAddress
)
26 typedef enum { IPV4
=1, IPV6
=2, UNIX
=3 } Addr
;
29 wxSockAddress(const wxSockAddress
& other
);
30 virtual ~wxSockAddress();
32 wxSockAddress
& operator=(const wxSockAddress
& other
);
35 virtual int Type() = 0;
37 GAddress
*GetAddress() const { return m_address
; }
38 void SetAddress(GAddress
*address
);
40 // we need to be able to create copies of the addresses polymorphically (i.e.
41 // without knowing the exact address class)
42 virtual wxSockAddress
*Clone() const = 0;
51 // Interface to an IP address (either IPV4 or IPV6)
52 class WXDLLIMPEXP_NET wxIPaddress
: public wxSockAddress
{
53 DECLARE_ABSTRACT_CLASS(wxIPaddress
)
56 wxIPaddress(const wxIPaddress
& other
);
57 virtual ~wxIPaddress();
59 virtual bool Hostname(const wxString
& name
) = 0;
60 virtual bool Service(const wxString
& name
) = 0;
61 virtual bool Service(unsigned short port
) = 0;
63 virtual bool LocalHost() = 0;
64 virtual bool IsLocalHost() const = 0;
66 virtual bool AnyAddress() = 0;
67 virtual bool BroadcastAddress() = 0;
69 virtual wxString
IPAddress() const = 0;
71 virtual wxString
Hostname() const = 0;
72 virtual unsigned short Service() const = 0;
75 class WXDLLIMPEXP_NET wxIPV4address
: public wxIPaddress
{
76 DECLARE_DYNAMIC_CLASS(wxIPV4address
)
79 wxIPV4address(const wxIPV4address
& other
);
80 virtual ~wxIPV4address();
86 virtual bool Hostname(const wxString
& name
);
87 bool Hostname(unsigned long addr
);
88 virtual bool Service(const wxString
& name
);
89 virtual bool Service(unsigned short port
);
91 // localhost (127.0.0.1)
92 virtual bool LocalHost();
93 virtual bool IsLocalHost() const;
96 virtual bool AnyAddress();
97 // all (255.255.255.255)
98 virtual bool BroadcastAddress();
100 virtual wxString
Hostname() const;
101 wxString
OrigHostname() { return m_origHostname
; }
102 virtual unsigned short Service() const;
105 virtual wxString
IPAddress() const;
107 virtual int Type() { return wxSockAddress::IPV4
; }
108 virtual wxSockAddress
*Clone() const;
110 bool operator==(const wxIPV4address
& addr
) const;
113 wxString m_origHostname
;
117 // the IPv6 code probably doesn't work, untested -- set to 1 at your own risk
124 class WXDLLIMPEXP_NET wxIPV6address
: public wxIPaddress
{
125 DECLARE_DYNAMIC_CLASS(wxIPV6address
)
127 wxString m_origHostname
;
130 wxIPV6address(const wxIPV6address
& other
);
131 virtual ~wxIPV6address();
136 // 3ffe:ffff:0100:f101:0210:a4ff:fee3:9566
137 // compact (base85) Itu&-ZQ82s>J%s99FJXT (depends on platform api)
138 // compressed format ::1
139 // ipv4 mapped ::ffff:1.2.3.4
140 virtual bool Hostname(const wxString
& name
);
142 bool Hostname(unsigned char addr
[16]);
143 virtual bool Service(const wxString
& name
);
144 virtual bool Service(unsigned short port
);
146 // localhost (0000:0000:0000:0000:0000:0000:0000:0001 (::1))
147 virtual bool LocalHost();
148 virtual bool IsLocalHost() const;
150 // any (0000:0000:0000:0000:0000:0000:0000:0000 (::))
151 virtual bool AnyAddress();
153 virtual bool BroadcastAddress();
155 // 3ffe:ffff:0100:f101:0210:a4ff:fee3:9566
156 virtual wxString
IPAddress() const;
158 virtual wxString
Hostname() const;
159 virtual unsigned short Service() const;
161 virtual int Type() { return wxSockAddress::IPV6
; }
162 virtual wxSockAddress
*Clone() const { return new wxIPV6address(*this); }
167 #if defined(__UNIX__) && !defined(__WINE__) && (!defined(__WXMAC__) || defined(__DARWIN__)) && !defined(__WXMSW__)
168 #include <sys/socket.h>
173 class WXDLLIMPEXP_NET wxUNIXaddress
: public wxSockAddress
{
174 DECLARE_DYNAMIC_CLASS(wxUNIXaddress
)
176 struct sockaddr_un
*m_addr
;
179 wxUNIXaddress(const wxUNIXaddress
& other
);
180 virtual ~wxUNIXaddress();
182 void Filename(const wxString
& name
);
185 virtual int Type() { return wxSockAddress::UNIX
; }
186 virtual wxSockAddress
*Clone() const { return new wxUNIXaddress(*this); }
195 // _WX_NETWORK_ADDRESS_H