]> git.saurik.com Git - wxWidgets.git/blame - include/wx/sckaddr.h
Call SetDataSource() from OnEnter() so that querying/accessing the data is possible...
[wxWidgets.git] / include / wx / sckaddr.h
CommitLineData
f4ada568
GL
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
65571936 9// Licence: wxWindows licence
f4ada568 10/////////////////////////////////////////////////////////////////////////////
2df7be7f 11
8ac36abb
VZ
12#ifndef _WX_SCKADDR_H_
13#define _WX_SCKADDR_H_
f4ada568 14
2df7be7f
RR
15#include "wx/defs.h"
16
17#if wxUSE_SOCKETS
18
2df7be7f 19#include "wx/string.h"
a324a7bc 20
c9bccf23 21class wxSockAddressImpl;
f4ada568 22
8ac36abb
VZ
23// Any socket address kind
24class WXDLLIMPEXP_NET wxSockAddress : public wxObject
25{
f4ada568 26public:
c9bccf23 27 enum Family
8ac36abb 28 {
c9bccf23
VZ
29 NONE,
30 IPV4,
31 IPV6,
32 UNIX
33 };
8ac36abb
VZ
34
35 wxSockAddress();
36 wxSockAddress(const wxSockAddress& other);
37 virtual ~wxSockAddress();
f4ada568 38
8ac36abb 39 wxSockAddress& operator=(const wxSockAddress& other);
a324a7bc 40
8ac36abb 41 virtual void Clear();
c9bccf23 42 virtual Family Type() = 0;
1539c2f5 43
8ac36abb
VZ
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;
f4ada568 47
f4ada568 48
8ac36abb 49 // implementation only, don't use
c9bccf23
VZ
50 const wxSockAddressImpl& GetAddress() const { return *m_impl; }
51 void SetAddress(const wxSockAddressImpl& address);
f4ada568 52
a324a7bc 53protected:
c9bccf23 54 wxSockAddressImpl *m_impl;
6c0d0845
VZ
55
56private:
8ac36abb
VZ
57 void Init();
58 DECLARE_ABSTRACT_CLASS(wxSockAddress)
f4ada568
GL
59};
60
8ac36abb
VZ
61// An IP address (either IPv4 or IPv6)
62class WXDLLIMPEXP_NET wxIPaddress : public wxSockAddress
63{
be4bd463 64public:
c9bccf23
VZ
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;
be4bd463 73
c9bccf23
VZ
74 bool Hostname(const wxString& name);
75 bool Service(const wxString& name);
76 bool Service(unsigned short port);
be4bd463 77
c9bccf23 78 bool LocalHost();
8ac36abb 79 virtual bool IsLocalHost() const = 0;
be4bd463 80
c9bccf23 81 bool AnyAddress();
be4bd463 82
8ac36abb 83 virtual wxString IPAddress() const = 0;
be4bd463 84
c9bccf23
VZ
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
8ac36abb
VZ
106
107 DECLARE_ABSTRACT_CLASS(wxIPaddress)
be4bd463
JS
108};
109
8ac36abb
VZ
110// An IPv4 address
111class WXDLLIMPEXP_NET wxIPV4address : public wxIPaddress
112{
f4ada568 113public:
c9bccf23
VZ
114 wxIPV4address() : wxIPaddress() { }
115 wxIPV4address(const wxIPV4address& other) : wxIPaddress(other) { }
f4ada568 116
8ac36abb 117 // implement wxSockAddress pure virtuals:
c9bccf23
VZ
118 virtual Family Type() { return IPV4; }
119 virtual wxSockAddress *Clone() const { return new wxIPV4address(*this); }
be4bd463 120
f4ada568 121
8ac36abb 122 // implement wxIPaddress pure virtuals:
8ac36abb 123 virtual bool IsLocalHost() const;
f4ada568 124
8ac36abb
VZ
125 virtual wxString IPAddress() const;
126
8ac36abb
VZ
127
128 // IPv4-specific methods:
8ac36abb 129 bool Hostname(unsigned long addr);
c9bccf23 130
8dc5f051
VZ
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); }
c9bccf23 137
8dc5f051 138 bool BroadcastAddress();
ce22d615
RD
139
140private:
c9bccf23 141 virtual void DoInitImpl();
f4ada568 142
8ac36abb
VZ
143 DECLARE_DYNAMIC_CLASS(wxIPV4address)
144};
2ff35079 145
2ff35079 146
be4bd463
JS
147#if wxUSE_IPV6
148
8ac36abb
VZ
149// An IPv6 address
150class WXDLLIMPEXP_NET wxIPV6address : public wxIPaddress
151{
f4ada568 152public:
c9bccf23
VZ
153 wxIPV6address() : wxIPaddress() { }
154 wxIPV6address(const wxIPV6address& other) : wxIPaddress(other) { }
8ac36abb
VZ
155
156 // implement wxSockAddress pure virtuals:
c9bccf23 157 virtual Family Type() { return IPV6; }
8ac36abb
VZ
158 virtual wxSockAddress *Clone() const { return new wxIPV6address(*this); }
159
160
161 // implement wxIPaddress pure virtuals:
8ac36abb
VZ
162 virtual bool IsLocalHost() const;
163
8ac36abb
VZ
164 virtual wxString IPAddress() const;
165
8ac36abb 166 // IPv6-specific methods:
8ac36abb
VZ
167 bool Hostname(unsigned char addr[16]);
168
c9bccf23
VZ
169 using wxIPaddress::Hostname;
170
8ac36abb 171private:
c9bccf23 172 virtual void DoInitImpl();
8ac36abb
VZ
173
174 DECLARE_DYNAMIC_CLASS(wxIPV6address)
f4ada568 175};
be4bd463
JS
176
177#endif // wxUSE_IPV6
f4ada568 178
c9bccf23
VZ
179// Unix domain sockets are only available under, well, Unix
180#if defined(__UNIX__) && !defined(__WINDOWS__) && !defined(__WINE__)
181 #define wxHAS_UNIX_DOMAIN_SOCKETS
e1c70641 182#endif
f4ada568 183
c9bccf23
VZ
184#ifdef wxHAS_UNIX_DOMAIN_SOCKETS
185
8ac36abb
VZ
186// A Unix domain socket address
187class WXDLLIMPEXP_NET wxUNIXaddress : public wxSockAddress
188{
f4ada568 189public:
c9bccf23
VZ
190 wxUNIXaddress() : wxSockAddress() { }
191 wxUNIXaddress(const wxUNIXaddress& other) : wxSockAddress(other) { }
8ac36abb
VZ
192
193 void Filename(const wxString& name);
c9bccf23 194 wxString Filename() const;
f4ada568 195
c9bccf23 196 virtual Family Type() { return UNIX; }
8ac36abb
VZ
197 virtual wxSockAddress *Clone() const { return new wxUNIXaddress(*this); }
198
199private:
c9bccf23
VZ
200 wxSockAddressImpl& GetUNIX();
201 const wxSockAddressImpl& GetUNIX() const
202 {
203 return const_cast<wxUNIXaddress *>(this)->GetUNIX();
204 }
f4ada568 205
8ac36abb 206 DECLARE_DYNAMIC_CLASS(wxUNIXaddress)
f4ada568 207};
f4ada568 208
c9bccf23 209#endif // wxHAS_UNIX_DOMAIN_SOCKETS
65ccd2b8 210
8ac36abb
VZ
211#endif // wxUSE_SOCKETS
212
213#endif // _WX_SCKADDR_H_