]> git.saurik.com Git - wxWidgets.git/blob - include/wx/sckaddr.h
fix wxColourDialog::Centre() and SetSize() (modified patch 1831628)
[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_NETWORK_ADDRESS_H
13 #define _WX_NETWORK_ADDRESS_H
14
15 #include "wx/defs.h"
16
17 #if wxUSE_SOCKETS
18
19 #include "wx/string.h"
20 #include "wx/gsocket.h"
21
22
23 class WXDLLIMPEXP_NET wxSockAddress : public wxObject {
24 DECLARE_ABSTRACT_CLASS(wxSockAddress)
25 public:
26 typedef enum { IPV4=1, IPV6=2, UNIX=3 } Addr;
27
28 wxSockAddress();
29 wxSockAddress(const wxSockAddress& other);
30 virtual ~wxSockAddress();
31
32 wxSockAddress& operator=(const wxSockAddress& other);
33
34 virtual void Clear();
35 virtual int Type() = 0;
36
37 GAddress *GetAddress() const { return m_address; }
38 void SetAddress(GAddress *address);
39
40 // we need to be able to create copies of the addresses polymorphically (i.e.
41 // without knowing the exact address class)
42 virtual wxSockAddress *Clone() const = 0;
43
44 protected:
45 GAddress *m_address;
46
47 private:
48 void Init();
49 };
50
51 // Interface to an IP address (either IPV4 or IPV6)
52 class WXDLLIMPEXP_NET wxIPaddress : public wxSockAddress {
53 DECLARE_ABSTRACT_CLASS(wxIPaddress)
54 public:
55 wxIPaddress();
56 wxIPaddress(const wxIPaddress& other);
57 virtual ~wxIPaddress();
58
59 virtual bool Hostname(const wxString& name) = 0;
60 virtual bool Service(const wxString& name) = 0;
61 virtual bool Service(unsigned short port) = 0;
62
63 virtual bool LocalHost() = 0;
64 virtual bool IsLocalHost() const = 0;
65
66 virtual bool AnyAddress() = 0;
67 virtual bool BroadcastAddress() = 0;
68
69 virtual wxString IPAddress() const = 0;
70
71 virtual wxString Hostname() const = 0;
72 virtual unsigned short Service() const = 0;
73 };
74
75 class WXDLLIMPEXP_NET wxIPV4address : public wxIPaddress {
76 DECLARE_DYNAMIC_CLASS(wxIPV4address)
77 public:
78 wxIPV4address();
79 wxIPV4address(const wxIPV4address& other);
80 virtual ~wxIPV4address();
81
82 // IPV4 name formats
83 //
84 // hostname
85 // dot format a.b.c.d
86 virtual bool Hostname(const wxString& name);
87 bool Hostname(unsigned long addr);
88 virtual bool Service(const wxString& name);
89 virtual bool Service(unsigned short port);
90
91 // localhost (127.0.0.1)
92 virtual bool LocalHost();
93 virtual bool IsLocalHost() const;
94
95 // any (0.0.0.0)
96 virtual bool AnyAddress();
97 // all (255.255.255.255)
98 virtual bool BroadcastAddress();
99
100 virtual wxString Hostname() const;
101 wxString OrigHostname() { return m_origHostname; }
102 virtual unsigned short Service() const;
103
104 // a.b.c.d
105 virtual wxString IPAddress() const;
106
107 virtual int Type() { return wxSockAddress::IPV4; }
108 virtual wxSockAddress *Clone() const;
109
110 bool operator==(const wxIPV4address& addr) const;
111
112 private:
113 wxString m_origHostname;
114 };
115
116
117 // the IPv6 code probably doesn't work, untested -- set to 1 at your own risk
118 #ifndef wxUSE_IPV6
119 #define wxUSE_IPV6 0
120 #endif
121
122 #if wxUSE_IPV6
123
124 // Experimental Only:
125 //
126 // IPV6 has not yet been implemented in socket layer
127 class WXDLLIMPEXP_NET wxIPV6address : public wxIPaddress {
128 DECLARE_DYNAMIC_CLASS(wxIPV6address)
129 private:
130 struct sockaddr_in6 *m_addr;
131 public:
132 wxIPV6address();
133 wxIPV6address(const wxIPV6address& other);
134 virtual ~wxIPV6address();
135
136 // IPV6 name formats
137 //
138 // hostname
139 // 3ffe:ffff:0100:f101:0210:a4ff:fee3:9566
140 // compact (base85) Itu&-ZQ82s>J%s99FJXT
141 // compressed format ::1
142 // ipv4 mapped ::ffff:1.2.3.4
143 virtual bool Hostname(const wxString& name);
144
145 bool Hostname(unsigned char addr[16]);
146 virtual bool Service(const wxString& name);
147 virtual bool Service(unsigned short port);
148
149 // localhost (0000:0000:0000:0000:0000:0000:0000:0001 (::1))
150 virtual bool LocalHost();
151 virtual bool IsLocalHost() const;
152
153 // any (0000:0000:0000:0000:0000:0000:0000:0000 (::))
154 virtual bool AnyAddress();
155 // all (?)
156 virtual bool BroadcastAddress();
157
158 // 3ffe:ffff:0100:f101:0210:a4ff:fee3:9566
159 virtual wxString IPAddress() const;
160
161 virtual wxString Hostname() const;
162 virtual unsigned short Service() const;
163
164 virtual int Type() { return wxSockAddress::IPV6; }
165 virtual wxSockAddress *Clone() const { return new wxIPV6address(*this); }
166 };
167
168 #endif // wxUSE_IPV6
169
170 #if defined(__UNIX__) && !defined(__WINE__) && (!defined(__WXMAC__) || defined(__DARWIN__)) && !defined(__WXMSW__)
171 #include <sys/socket.h>
172 #ifndef __VMS__
173 # include <sys/un.h>
174 #endif
175
176 class WXDLLIMPEXP_NET wxUNIXaddress : public wxSockAddress {
177 DECLARE_DYNAMIC_CLASS(wxUNIXaddress)
178 private:
179 struct sockaddr_un *m_addr;
180 public:
181 wxUNIXaddress();
182 wxUNIXaddress(const wxUNIXaddress& other);
183 virtual ~wxUNIXaddress();
184
185 void Filename(const wxString& name);
186 wxString Filename();
187
188 virtual int Type() { return wxSockAddress::UNIX; }
189 virtual wxSockAddress *Clone() const { return new wxUNIXaddress(*this); }
190 };
191 #endif
192 // __UNIX__
193
194 #endif
195 // wxUSE_SOCKETS
196
197 #endif
198 // _WX_NETWORK_ADDRESS_H