]> git.saurik.com Git - wxWidgets.git/blob - include/wx/sckaddr.h
made wxHeaderCtrl::GetColumn() const to get rid of the const_cast<>s
[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 struct GAddress;
22
23 // Any socket address kind
24 class WXDLLIMPEXP_NET wxSockAddress : public wxObject
25 {
26 public:
27 enum
28 {
29 IPV4 = 1,
30 IPV6 = 2,
31 UNIX = 3
32 } Addr;
33
34 wxSockAddress();
35 wxSockAddress(const wxSockAddress& other);
36 virtual ~wxSockAddress();
37
38 wxSockAddress& operator=(const wxSockAddress& other);
39
40 virtual void Clear();
41 virtual int Type() = 0;
42
43 // we need to be able to create copies of the addresses polymorphically
44 // (i.e. without knowing the exact address class)
45 virtual wxSockAddress *Clone() const = 0;
46
47
48 // implementation only, don't use
49 GAddress *GetAddress() const { return m_address; }
50 void SetAddress(GAddress *address);
51
52 protected:
53 GAddress *m_address;
54
55 private:
56 void Init();
57 DECLARE_ABSTRACT_CLASS(wxSockAddress)
58 };
59
60 // An IP address (either IPv4 or IPv6)
61 class WXDLLIMPEXP_NET wxIPaddress : public wxSockAddress
62 {
63 public:
64 wxIPaddress();
65 wxIPaddress(const wxIPaddress& other);
66 virtual ~wxIPaddress();
67
68 virtual bool Hostname(const wxString& name) = 0;
69 virtual bool Service(const wxString& name) = 0;
70 virtual bool Service(unsigned short port) = 0;
71
72 virtual bool LocalHost() = 0;
73 virtual bool IsLocalHost() const = 0;
74
75 virtual bool AnyAddress() = 0;
76 virtual bool BroadcastAddress() = 0;
77
78 virtual wxString IPAddress() const = 0;
79
80 virtual wxString Hostname() const = 0;
81 virtual unsigned short Service() const = 0;
82
83 DECLARE_ABSTRACT_CLASS(wxIPaddress)
84 };
85
86 // An IPv4 address
87 class WXDLLIMPEXP_NET wxIPV4address : public wxIPaddress
88 {
89 public:
90 wxIPV4address();
91 wxIPV4address(const wxIPV4address& other);
92 virtual ~wxIPV4address();
93
94 bool operator==(const wxIPV4address& addr) const;
95
96 // implement wxSockAddress pure virtuals:
97 virtual int Type() { return wxSockAddress::IPV4; }
98 virtual wxSockAddress *Clone() const;
99
100
101 // implement wxIPaddress pure virtuals:
102
103 // handles the usual dotted quad format too
104 virtual bool Hostname(const wxString& name);
105 virtual bool Service(const wxString& name);
106 virtual bool Service(unsigned short port);
107
108 // localhost (127.0.0.1)
109 virtual bool LocalHost();
110 virtual bool IsLocalHost() const;
111
112 // any (0.0.0.0)
113 virtual bool AnyAddress();
114 // all (255.255.255.255)
115 virtual bool BroadcastAddress();
116
117 // a.b.c.d
118 virtual wxString IPAddress() const;
119
120 virtual wxString Hostname() const;
121 virtual unsigned short Service() const;
122
123
124 // IPv4-specific methods:
125
126 bool Hostname(unsigned long addr);
127 wxString OrigHostname() { return m_origHostname; }
128
129 private:
130 wxString m_origHostname;
131
132 DECLARE_DYNAMIC_CLASS(wxIPV4address)
133 };
134
135
136 #if wxUSE_IPV6
137
138 // An IPv6 address
139 class WXDLLIMPEXP_NET wxIPV6address : public wxIPaddress
140 {
141 public:
142 wxIPV6address();
143 wxIPV6address(const wxIPV6address& other);
144 virtual ~wxIPV6address();
145
146 // implement wxSockAddress pure virtuals:
147
148 virtual int Type() { return wxSockAddress::IPV6; }
149 virtual wxSockAddress *Clone() const { return new wxIPV6address(*this); }
150
151
152 // implement wxIPaddress pure virtuals:
153
154 virtual bool Hostname(const wxString& name);
155 virtual bool Service(const wxString& name);
156 virtual bool Service(unsigned short port);
157
158 // localhost (0000:0000:0000:0000:0000:0000:0000:0001 (::1))
159 virtual bool LocalHost();
160 virtual bool IsLocalHost() const;
161
162 // any (0000:0000:0000:0000:0000:0000:0000:0000 (::))
163 virtual bool AnyAddress();
164 // all (?)
165 virtual bool BroadcastAddress();
166
167 // 3ffe:ffff:0100:f101:0210:a4ff:fee3:9566
168 virtual wxString IPAddress() const;
169
170 virtual wxString Hostname() const;
171 virtual unsigned short Service() const;
172
173
174 // IPv6-specific methods:
175
176 bool Hostname(unsigned char addr[16]);
177
178 private:
179 wxString m_origHostname;
180
181 DECLARE_DYNAMIC_CLASS(wxIPV6address)
182 };
183
184 #endif // wxUSE_IPV6
185
186 #if defined(__UNIX__) && !defined(__WINE__)
187
188 #include <sys/socket.h>
189 #ifndef __VMS__
190 #include <sys/un.h>
191 #endif
192
193 // A Unix domain socket address
194 class WXDLLIMPEXP_NET wxUNIXaddress : public wxSockAddress
195 {
196 public:
197 wxUNIXaddress();
198 wxUNIXaddress(const wxUNIXaddress& other);
199 virtual ~wxUNIXaddress();
200
201 void Filename(const wxString& name);
202 wxString Filename();
203
204 virtual int Type() { return wxSockAddress::UNIX; }
205 virtual wxSockAddress *Clone() const { return new wxUNIXaddress(*this); }
206
207 private:
208 struct sockaddr_un *m_addr;
209
210 DECLARE_DYNAMIC_CLASS(wxUNIXaddress)
211 };
212
213 #endif // __UNIX__
214
215 #endif // wxUSE_SOCKETS
216
217 #endif // _WX_SCKADDR_H_