]> git.saurik.com Git - wxWidgets.git/blob - include/wx/sckaddr.h
always dispatch messages for the hidden window which receives process termination...
[wxWidgets.git] / include / wx / sckaddr.h
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 // RCS-ID: $Id$
8 // Copyright: (c) 1997, 1998 Guilhem Lavaux
9 // (c) 2008, 2009 Vadim Zeitlin
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifndef _WX_SCKADDR_H_
14 #define _WX_SCKADDR_H_
15
16 #include "wx/defs.h"
17
18 #if wxUSE_SOCKETS
19
20 #include "wx/string.h"
21
22 class wxSockAddressImpl;
23
24 // forward declare it instead of including the system headers defining it which
25 // can bring in <windows.h> under Windows which we don't want to include from
26 // public wx headers
27 struct sockaddr;
28
29 // Any socket address kind
30 class WXDLLIMPEXP_NET wxSockAddress : public wxObject
31 {
32 public:
33 enum Family
34 {
35 NONE,
36 IPV4,
37 IPV6,
38 UNIX
39 };
40
41 wxSockAddress();
42 wxSockAddress(const wxSockAddress& other);
43 virtual ~wxSockAddress();
44
45 wxSockAddress& operator=(const wxSockAddress& other);
46
47 virtual void Clear();
48 virtual Family Type() = 0;
49
50 // accessors for the low level address represented by this object
51 const sockaddr *GetAddressData() const;
52 int GetAddressDataLen() const;
53
54 // we need to be able to create copies of the addresses polymorphically
55 // (i.e. without knowing the exact address class)
56 virtual wxSockAddress *Clone() const = 0;
57
58
59 // implementation only, don't use
60 const wxSockAddressImpl& GetAddress() const { return *m_impl; }
61 void SetAddress(const wxSockAddressImpl& address);
62
63 protected:
64 wxSockAddressImpl *m_impl;
65
66 private:
67 void Init();
68 DECLARE_ABSTRACT_CLASS(wxSockAddress)
69 };
70
71 // An IP address (either IPv4 or IPv6)
72 class WXDLLIMPEXP_NET wxIPaddress : public wxSockAddress
73 {
74 public:
75 wxIPaddress() : wxSockAddress() { }
76 wxIPaddress(const wxIPaddress& other)
77 : wxSockAddress(other),
78 m_origHostname(other.m_origHostname)
79 {
80 }
81
82 bool operator==(const wxIPaddress& addr) const;
83
84 bool Hostname(const wxString& name);
85 bool Service(const wxString& name);
86 bool Service(unsigned short port);
87
88 bool LocalHost();
89 virtual bool IsLocalHost() const = 0;
90
91 bool AnyAddress();
92
93 virtual wxString IPAddress() const = 0;
94
95 wxString Hostname() const;
96 unsigned short Service() const;
97
98 wxString OrigHostname() const { return m_origHostname; }
99
100 protected:
101 // get m_impl initialized to the right family if it hadn't been done yet
102 wxSockAddressImpl& GetImpl();
103 const wxSockAddressImpl& GetImpl() const
104 {
105 return const_cast<wxIPaddress *>(this)->GetImpl();
106 }
107
108 // host name originally passed to Hostname()
109 wxString m_origHostname;
110
111 private:
112 // create the wxSockAddressImpl object of the correct family if it's
113 // currently uninitialized
114 virtual void DoInitImpl() = 0;
115
116
117 DECLARE_ABSTRACT_CLASS(wxIPaddress)
118 };
119
120 // An IPv4 address
121 class WXDLLIMPEXP_NET wxIPV4address : public wxIPaddress
122 {
123 public:
124 wxIPV4address() : wxIPaddress() { }
125 wxIPV4address(const wxIPV4address& other) : wxIPaddress(other) { }
126
127 // implement wxSockAddress pure virtuals:
128 virtual Family Type() { return IPV4; }
129 virtual wxSockAddress *Clone() const { return new wxIPV4address(*this); }
130
131
132 // implement wxIPaddress pure virtuals:
133 virtual bool IsLocalHost() const;
134
135 virtual wxString IPAddress() const;
136
137
138 // IPv4-specific methods:
139 bool Hostname(unsigned long addr);
140
141 // make base class methods hidden by our overload visible
142 //
143 // FIXME-VC6: replace this with "using IPAddress::Hostname" (not supported
144 // by VC6) when support for it is dropped
145 wxString Hostname() const { return wxIPaddress::Hostname(); }
146 bool Hostname(const wxString& name) { return wxIPaddress::Hostname(name); }
147
148 bool BroadcastAddress();
149
150 private:
151 virtual void DoInitImpl();
152
153 DECLARE_DYNAMIC_CLASS(wxIPV4address)
154 };
155
156
157 #if wxUSE_IPV6
158
159 // An IPv6 address
160 class WXDLLIMPEXP_NET wxIPV6address : public wxIPaddress
161 {
162 public:
163 wxIPV6address() : wxIPaddress() { }
164 wxIPV6address(const wxIPV6address& other) : wxIPaddress(other) { }
165
166 // implement wxSockAddress pure virtuals:
167 virtual Family Type() { return IPV6; }
168 virtual wxSockAddress *Clone() const { return new wxIPV6address(*this); }
169
170
171 // implement wxIPaddress pure virtuals:
172 virtual bool IsLocalHost() const;
173
174 virtual wxString IPAddress() const;
175
176 // IPv6-specific methods:
177 bool Hostname(unsigned char addr[16]);
178
179 using wxIPaddress::Hostname;
180
181 private:
182 virtual void DoInitImpl();
183
184 DECLARE_DYNAMIC_CLASS(wxIPV6address)
185 };
186
187 #endif // wxUSE_IPV6
188
189 // Unix domain sockets are only available under, well, Unix
190 #if defined(__UNIX__) && !defined(__WINDOWS__) && !defined(__WINE__)
191 #define wxHAS_UNIX_DOMAIN_SOCKETS
192 #endif
193
194 #ifdef wxHAS_UNIX_DOMAIN_SOCKETS
195
196 // A Unix domain socket address
197 class WXDLLIMPEXP_NET wxUNIXaddress : public wxSockAddress
198 {
199 public:
200 wxUNIXaddress() : wxSockAddress() { }
201 wxUNIXaddress(const wxUNIXaddress& other) : wxSockAddress(other) { }
202
203 void Filename(const wxString& name);
204 wxString Filename() const;
205
206 virtual Family Type() { return UNIX; }
207 virtual wxSockAddress *Clone() const { return new wxUNIXaddress(*this); }
208
209 private:
210 wxSockAddressImpl& GetUNIX();
211 const wxSockAddressImpl& GetUNIX() const
212 {
213 return const_cast<wxUNIXaddress *>(this)->GetUNIX();
214 }
215
216 DECLARE_DYNAMIC_CLASS(wxUNIXaddress)
217 };
218
219 #endif // wxHAS_UNIX_DOMAIN_SOCKETS
220
221 #endif // wxUSE_SOCKETS
222
223 #endif // _WX_SCKADDR_H_