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