]> git.saurik.com Git - wxWidgets.git/blame - include/wx/sckaddr.h
slightly better error reporting (could still be improved)
[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
8ac36abb 21#include "wx/gsocket.h"
f4ada568 22
8ac36abb
VZ
23// Any socket address kind
24class WXDLLIMPEXP_NET wxSockAddress : public wxObject
25{
f4ada568 26public:
8ac36abb
VZ
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();
f4ada568 37
8ac36abb 38 wxSockAddress& operator=(const wxSockAddress& other);
a324a7bc 39
8ac36abb
VZ
40 virtual void Clear();
41 virtual int Type() = 0;
1539c2f5 42
8ac36abb
VZ
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;
f4ada568 46
f4ada568 47
8ac36abb
VZ
48 // implementation only, don't use
49 GAddress *GetAddress() const { return m_address; }
50 void SetAddress(GAddress *address);
f4ada568 51
a324a7bc 52protected:
8ac36abb 53 GAddress *m_address;
6c0d0845
VZ
54
55private:
8ac36abb
VZ
56 void Init();
57 DECLARE_ABSTRACT_CLASS(wxSockAddress)
f4ada568
GL
58};
59
8ac36abb
VZ
60// An IP address (either IPv4 or IPv6)
61class WXDLLIMPEXP_NET wxIPaddress : public wxSockAddress
62{
be4bd463 63public:
8ac36abb
VZ
64 wxIPaddress();
65 wxIPaddress(const wxIPaddress& other);
66 virtual ~wxIPaddress();
be4bd463 67
8ac36abb
VZ
68 virtual bool Hostname(const wxString& name) = 0;
69 virtual bool Service(const wxString& name) = 0;
70 virtual bool Service(unsigned short port) = 0;
be4bd463 71
8ac36abb
VZ
72 virtual bool LocalHost() = 0;
73 virtual bool IsLocalHost() const = 0;
be4bd463 74
8ac36abb
VZ
75 virtual bool AnyAddress() = 0;
76 virtual bool BroadcastAddress() = 0;
be4bd463 77
8ac36abb 78 virtual wxString IPAddress() const = 0;
be4bd463 79
8ac36abb
VZ
80 virtual wxString Hostname() const = 0;
81 virtual unsigned short Service() const = 0;
82
83 DECLARE_ABSTRACT_CLASS(wxIPaddress)
be4bd463
JS
84};
85
8ac36abb
VZ
86// An IPv4 address
87class WXDLLIMPEXP_NET wxIPV4address : public wxIPaddress
88{
f4ada568 89public:
8ac36abb
VZ
90 wxIPV4address();
91 wxIPV4address(const wxIPV4address& other);
92 virtual ~wxIPV4address();
93
94 bool operator==(const wxIPV4address& addr) const;
f4ada568 95
8ac36abb
VZ
96 // implement wxSockAddress pure virtuals:
97 virtual int Type() { return wxSockAddress::IPV4; }
98 virtual wxSockAddress *Clone() const;
be4bd463 99
f4ada568 100
8ac36abb 101 // implement wxIPaddress pure virtuals:
be4bd463 102
8ac36abb
VZ
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);
be4bd463 107
8ac36abb
VZ
108 // localhost (127.0.0.1)
109 virtual bool LocalHost();
110 virtual bool IsLocalHost() const;
f4ada568 111
8ac36abb
VZ
112 // any (0.0.0.0)
113 virtual bool AnyAddress();
114 // all (255.255.255.255)
115 virtual bool BroadcastAddress();
d775fa82 116
8ac36abb
VZ
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; }
ce22d615
RD
128
129private:
8ac36abb 130 wxString m_origHostname;
f4ada568 131
8ac36abb
VZ
132 DECLARE_DYNAMIC_CLASS(wxIPV4address)
133};
2ff35079 134
2ff35079 135
be4bd463
JS
136#if wxUSE_IPV6
137
8ac36abb
VZ
138// An IPv6 address
139class WXDLLIMPEXP_NET wxIPV6address : public wxIPaddress
140{
f4ada568 141public:
8ac36abb
VZ
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
178private:
179 wxString m_origHostname;
180
181 DECLARE_DYNAMIC_CLASS(wxIPV6address)
f4ada568 182};
be4bd463
JS
183
184#endif // wxUSE_IPV6
f4ada568 185
8ac36abb
VZ
186#if defined(__UNIX__) && !defined(__WINE__)
187
fd9811b1 188#include <sys/socket.h>
e1c70641 189#ifndef __VMS__
8ac36abb 190 #include <sys/un.h>
e1c70641 191#endif
f4ada568 192
8ac36abb
VZ
193// A Unix domain socket address
194class WXDLLIMPEXP_NET wxUNIXaddress : public wxSockAddress
195{
f4ada568 196public:
8ac36abb
VZ
197 wxUNIXaddress();
198 wxUNIXaddress(const wxUNIXaddress& other);
199 virtual ~wxUNIXaddress();
200
201 void Filename(const wxString& name);
202 wxString Filename();
f4ada568 203
8ac36abb
VZ
204 virtual int Type() { return wxSockAddress::UNIX; }
205 virtual wxSockAddress *Clone() const { return new wxUNIXaddress(*this); }
206
207private:
208 struct sockaddr_un *m_addr;
f4ada568 209
8ac36abb 210 DECLARE_DYNAMIC_CLASS(wxUNIXaddress)
f4ada568 211};
f4ada568 212
8ac36abb 213#endif // __UNIX__
65ccd2b8 214
8ac36abb
VZ
215#endif // wxUSE_SOCKETS
216
217#endif // _WX_SCKADDR_H_