]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/sckaddr.h
added forward declaration of FrameSite apparently needed by mingw32 4.3
[wxWidgets.git] / include / wx / sckaddr.h
... / ...
CommitLineData
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
21class wxSockAddressImpl;
22
23// Any socket address kind
24class WXDLLIMPEXP_NET wxSockAddress : public wxObject
25{
26public:
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
53protected:
54 wxSockAddressImpl *m_impl;
55
56private:
57 void Init();
58 DECLARE_ABSTRACT_CLASS(wxSockAddress)
59};
60
61// An IP address (either IPv4 or IPv6)
62class WXDLLIMPEXP_NET wxIPaddress : public wxSockAddress
63{
64public:
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
90protected:
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
101private:
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
111class WXDLLIMPEXP_NET wxIPV4address : public wxIPaddress
112{
113public:
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 // make base class methods hidden by our overload visible
132 //
133 // FIXME-VC6: replace this with "using IPAddress::Hostname" (not supported
134 // by VC6) when support for it is dropped
135 wxString Hostname() const { return wxIPaddress::Hostname(); }
136 bool Hostname(const wxString& name) { return wxIPaddress::Hostname(name); }
137
138 bool BroadcastAddress();
139
140private:
141 virtual void DoInitImpl();
142
143 DECLARE_DYNAMIC_CLASS(wxIPV4address)
144};
145
146
147#if wxUSE_IPV6
148
149// An IPv6 address
150class WXDLLIMPEXP_NET wxIPV6address : public wxIPaddress
151{
152public:
153 wxIPV6address() : wxIPaddress() { }
154 wxIPV6address(const wxIPV6address& other) : wxIPaddress(other) { }
155
156 // implement wxSockAddress pure virtuals:
157 virtual Family Type() { return IPV6; }
158 virtual wxSockAddress *Clone() const { return new wxIPV6address(*this); }
159
160
161 // implement wxIPaddress pure virtuals:
162 virtual bool IsLocalHost() const;
163
164 virtual wxString IPAddress() const;
165
166 // IPv6-specific methods:
167 bool Hostname(unsigned char addr[16]);
168
169 using wxIPaddress::Hostname;
170
171private:
172 virtual void DoInitImpl();
173
174 DECLARE_DYNAMIC_CLASS(wxIPV6address)
175};
176
177#endif // wxUSE_IPV6
178
179// Unix domain sockets are only available under, well, Unix
180#if defined(__UNIX__) && !defined(__WINDOWS__) && !defined(__WINE__)
181 #define wxHAS_UNIX_DOMAIN_SOCKETS
182#endif
183
184#ifdef wxHAS_UNIX_DOMAIN_SOCKETS
185
186// A Unix domain socket address
187class WXDLLIMPEXP_NET wxUNIXaddress : public wxSockAddress
188{
189public:
190 wxUNIXaddress() : wxSockAddress() { }
191 wxUNIXaddress(const wxUNIXaddress& other) : wxSockAddress(other) { }
192
193 void Filename(const wxString& name);
194 wxString Filename() const;
195
196 virtual Family Type() { return UNIX; }
197 virtual wxSockAddress *Clone() const { return new wxUNIXaddress(*this); }
198
199private:
200 wxSockAddressImpl& GetUNIX();
201 const wxSockAddressImpl& GetUNIX() const
202 {
203 return const_cast<wxUNIXaddress *>(this)->GetUNIX();
204 }
205
206 DECLARE_DYNAMIC_CLASS(wxUNIXaddress)
207};
208
209#endif // wxHAS_UNIX_DOMAIN_SOCKETS
210
211#endif // wxUSE_SOCKETS
212
213#endif // _WX_SCKADDR_H_