]> git.saurik.com Git - wxWidgets.git/blame - include/wx/sckaddr.h
Don't accept focus in the dummy main generic spin control window.
[wxWidgets.git] / include / wx / sckaddr.h
CommitLineData
f4ada568 1/////////////////////////////////////////////////////////////////////////////
5fab0c8d 2// Name: wx/sckaddr.h
f4ada568
GL
3// Purpose: Network address classes
4// Author: Guilhem Lavaux
e143fb63 5// Modified by: Vadim Zeitlin to switch to wxSockAddressImpl implementation
f4ada568
GL
6// Created: 26/04/1997
7// RCS-ID: $Id$
8// Copyright: (c) 1997, 1998 Guilhem Lavaux
e143fb63 9// (c) 2008, 2009 Vadim Zeitlin
65571936 10// Licence: wxWindows licence
f4ada568 11/////////////////////////////////////////////////////////////////////////////
2df7be7f 12
8ac36abb
VZ
13#ifndef _WX_SCKADDR_H_
14#define _WX_SCKADDR_H_
f4ada568 15
2df7be7f
RR
16#include "wx/defs.h"
17
18#if wxUSE_SOCKETS
19
2df7be7f 20#include "wx/string.h"
a324a7bc 21
c9bccf23 22class wxSockAddressImpl;
f4ada568 23
5fab0c8d
VZ
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
27struct sockaddr;
28
8ac36abb
VZ
29// Any socket address kind
30class WXDLLIMPEXP_NET wxSockAddress : public wxObject
31{
f4ada568 32public:
c9bccf23 33 enum Family
8ac36abb 34 {
c9bccf23
VZ
35 NONE,
36 IPV4,
37 IPV6,
38 UNIX
39 };
8ac36abb
VZ
40
41 wxSockAddress();
42 wxSockAddress(const wxSockAddress& other);
43 virtual ~wxSockAddress();
f4ada568 44
8ac36abb 45 wxSockAddress& operator=(const wxSockAddress& other);
a324a7bc 46
8ac36abb 47 virtual void Clear();
c9bccf23 48 virtual Family Type() = 0;
1539c2f5 49
5fab0c8d
VZ
50 // accessors for the low level address represented by this object
51 const sockaddr *GetAddressData() const;
52 int GetAddressDataLen() const;
53
8ac36abb
VZ
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;
f4ada568 57
f4ada568 58
8ac36abb 59 // implementation only, don't use
c9bccf23
VZ
60 const wxSockAddressImpl& GetAddress() const { return *m_impl; }
61 void SetAddress(const wxSockAddressImpl& address);
f4ada568 62
a324a7bc 63protected:
c9bccf23 64 wxSockAddressImpl *m_impl;
6c0d0845
VZ
65
66private:
8ac36abb
VZ
67 void Init();
68 DECLARE_ABSTRACT_CLASS(wxSockAddress)
f4ada568
GL
69};
70
8ac36abb
VZ
71// An IP address (either IPv4 or IPv6)
72class WXDLLIMPEXP_NET wxIPaddress : public wxSockAddress
73{
be4bd463 74public:
c9bccf23
VZ
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;
be4bd463 83
c9bccf23
VZ
84 bool Hostname(const wxString& name);
85 bool Service(const wxString& name);
86 bool Service(unsigned short port);
be4bd463 87
c9bccf23 88 bool LocalHost();
8ac36abb 89 virtual bool IsLocalHost() const = 0;
be4bd463 90
c9bccf23 91 bool AnyAddress();
be4bd463 92
8ac36abb 93 virtual wxString IPAddress() const = 0;
be4bd463 94
c9bccf23
VZ
95 wxString Hostname() const;
96 unsigned short Service() const;
97
98 wxString OrigHostname() const { return m_origHostname; }
99
100protected:
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
111private:
112 // create the wxSockAddressImpl object of the correct family if it's
113 // currently uninitialized
114 virtual void DoInitImpl() = 0;
115
8ac36abb
VZ
116
117 DECLARE_ABSTRACT_CLASS(wxIPaddress)
be4bd463
JS
118};
119
8ac36abb
VZ
120// An IPv4 address
121class WXDLLIMPEXP_NET wxIPV4address : public wxIPaddress
122{
f4ada568 123public:
c9bccf23
VZ
124 wxIPV4address() : wxIPaddress() { }
125 wxIPV4address(const wxIPV4address& other) : wxIPaddress(other) { }
f4ada568 126
8ac36abb 127 // implement wxSockAddress pure virtuals:
c9bccf23
VZ
128 virtual Family Type() { return IPV4; }
129 virtual wxSockAddress *Clone() const { return new wxIPV4address(*this); }
be4bd463 130
f4ada568 131
8ac36abb 132 // implement wxIPaddress pure virtuals:
8ac36abb 133 virtual bool IsLocalHost() const;
f4ada568 134
8ac36abb
VZ
135 virtual wxString IPAddress() const;
136
8ac36abb
VZ
137
138 // IPv4-specific methods:
8ac36abb 139 bool Hostname(unsigned long addr);
c9bccf23 140
8dc5f051
VZ
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); }
c9bccf23 147
8dc5f051 148 bool BroadcastAddress();
ce22d615
RD
149
150private:
c9bccf23 151 virtual void DoInitImpl();
f4ada568 152
8ac36abb
VZ
153 DECLARE_DYNAMIC_CLASS(wxIPV4address)
154};
2ff35079 155
2ff35079 156
be4bd463
JS
157#if wxUSE_IPV6
158
8ac36abb
VZ
159// An IPv6 address
160class WXDLLIMPEXP_NET wxIPV6address : public wxIPaddress
161{
f4ada568 162public:
c9bccf23
VZ
163 wxIPV6address() : wxIPaddress() { }
164 wxIPV6address(const wxIPV6address& other) : wxIPaddress(other) { }
8ac36abb
VZ
165
166 // implement wxSockAddress pure virtuals:
c9bccf23 167 virtual Family Type() { return IPV6; }
8ac36abb
VZ
168 virtual wxSockAddress *Clone() const { return new wxIPV6address(*this); }
169
170
171 // implement wxIPaddress pure virtuals:
8ac36abb
VZ
172 virtual bool IsLocalHost() const;
173
8ac36abb
VZ
174 virtual wxString IPAddress() const;
175
8ac36abb 176 // IPv6-specific methods:
8ac36abb
VZ
177 bool Hostname(unsigned char addr[16]);
178
c9bccf23
VZ
179 using wxIPaddress::Hostname;
180
8ac36abb 181private:
c9bccf23 182 virtual void DoInitImpl();
8ac36abb
VZ
183
184 DECLARE_DYNAMIC_CLASS(wxIPV6address)
f4ada568 185};
be4bd463
JS
186
187#endif // wxUSE_IPV6
f4ada568 188
c9bccf23
VZ
189// Unix domain sockets are only available under, well, Unix
190#if defined(__UNIX__) && !defined(__WINDOWS__) && !defined(__WINE__)
191 #define wxHAS_UNIX_DOMAIN_SOCKETS
e1c70641 192#endif
f4ada568 193
c9bccf23
VZ
194#ifdef wxHAS_UNIX_DOMAIN_SOCKETS
195
8ac36abb
VZ
196// A Unix domain socket address
197class WXDLLIMPEXP_NET wxUNIXaddress : public wxSockAddress
198{
f4ada568 199public:
c9bccf23
VZ
200 wxUNIXaddress() : wxSockAddress() { }
201 wxUNIXaddress(const wxUNIXaddress& other) : wxSockAddress(other) { }
8ac36abb
VZ
202
203 void Filename(const wxString& name);
c9bccf23 204 wxString Filename() const;
f4ada568 205
c9bccf23 206 virtual Family Type() { return UNIX; }
8ac36abb
VZ
207 virtual wxSockAddress *Clone() const { return new wxUNIXaddress(*this); }
208
209private:
c9bccf23
VZ
210 wxSockAddressImpl& GetUNIX();
211 const wxSockAddressImpl& GetUNIX() const
212 {
213 return const_cast<wxUNIXaddress *>(this)->GetUNIX();
214 }
f4ada568 215
8ac36abb 216 DECLARE_DYNAMIC_CLASS(wxUNIXaddress)
f4ada568 217};
f4ada568 218
c9bccf23 219#endif // wxHAS_UNIX_DOMAIN_SOCKETS
65ccd2b8 220
8ac36abb
VZ
221#endif // wxUSE_SOCKETS
222
223#endif // _WX_SCKADDR_H_