]>
Commit | Line | Data |
---|---|---|
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 | 21 | class wxSockAddressImpl; |
f4ada568 | 22 | |
8ac36abb VZ |
23 | // Any socket address kind |
24 | class WXDLLIMPEXP_NET wxSockAddress : public wxObject | |
25 | { | |
f4ada568 | 26 | public: |
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 | 53 | protected: |
c9bccf23 | 54 | wxSockAddressImpl *m_impl; |
6c0d0845 VZ |
55 | |
56 | private: | |
8ac36abb VZ |
57 | void Init(); |
58 | DECLARE_ABSTRACT_CLASS(wxSockAddress) | |
f4ada568 GL |
59 | }; |
60 | ||
8ac36abb VZ |
61 | // An IP address (either IPv4 or IPv6) |
62 | class WXDLLIMPEXP_NET wxIPaddress : public wxSockAddress | |
63 | { | |
be4bd463 | 64 | public: |
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 | ||
90 | protected: | |
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 | ||
101 | private: | |
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 |
111 | class WXDLLIMPEXP_NET wxIPV4address : public wxIPaddress | |
112 | { | |
f4ada568 | 113 | public: |
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 VZ |
130 | |
131 | bool BroadcastAddress(); | |
132 | ||
133 | using wxIPaddress::Hostname; | |
ce22d615 RD |
134 | |
135 | private: | |
c9bccf23 | 136 | virtual void DoInitImpl(); |
f4ada568 | 137 | |
8ac36abb VZ |
138 | DECLARE_DYNAMIC_CLASS(wxIPV4address) |
139 | }; | |
2ff35079 | 140 | |
2ff35079 | 141 | |
be4bd463 JS |
142 | #if wxUSE_IPV6 |
143 | ||
8ac36abb VZ |
144 | // An IPv6 address |
145 | class WXDLLIMPEXP_NET wxIPV6address : public wxIPaddress | |
146 | { | |
f4ada568 | 147 | public: |
c9bccf23 VZ |
148 | wxIPV6address() : wxIPaddress() { } |
149 | wxIPV6address(const wxIPV6address& other) : wxIPaddress(other) { } | |
8ac36abb VZ |
150 | |
151 | // implement wxSockAddress pure virtuals: | |
c9bccf23 | 152 | virtual Family Type() { return IPV6; } |
8ac36abb VZ |
153 | virtual wxSockAddress *Clone() const { return new wxIPV6address(*this); } |
154 | ||
155 | ||
156 | // implement wxIPaddress pure virtuals: | |
8ac36abb VZ |
157 | virtual bool IsLocalHost() const; |
158 | ||
8ac36abb VZ |
159 | virtual wxString IPAddress() const; |
160 | ||
8ac36abb | 161 | // IPv6-specific methods: |
8ac36abb VZ |
162 | bool Hostname(unsigned char addr[16]); |
163 | ||
c9bccf23 VZ |
164 | using wxIPaddress::Hostname; |
165 | ||
8ac36abb | 166 | private: |
c9bccf23 | 167 | virtual void DoInitImpl(); |
8ac36abb VZ |
168 | |
169 | DECLARE_DYNAMIC_CLASS(wxIPV6address) | |
f4ada568 | 170 | }; |
be4bd463 JS |
171 | |
172 | #endif // wxUSE_IPV6 | |
f4ada568 | 173 | |
c9bccf23 VZ |
174 | // Unix domain sockets are only available under, well, Unix |
175 | #if defined(__UNIX__) && !defined(__WINDOWS__) && !defined(__WINE__) | |
176 | #define wxHAS_UNIX_DOMAIN_SOCKETS | |
e1c70641 | 177 | #endif |
f4ada568 | 178 | |
c9bccf23 VZ |
179 | #ifdef wxHAS_UNIX_DOMAIN_SOCKETS |
180 | ||
8ac36abb VZ |
181 | // A Unix domain socket address |
182 | class WXDLLIMPEXP_NET wxUNIXaddress : public wxSockAddress | |
183 | { | |
f4ada568 | 184 | public: |
c9bccf23 VZ |
185 | wxUNIXaddress() : wxSockAddress() { } |
186 | wxUNIXaddress(const wxUNIXaddress& other) : wxSockAddress(other) { } | |
8ac36abb VZ |
187 | |
188 | void Filename(const wxString& name); | |
c9bccf23 | 189 | wxString Filename() const; |
f4ada568 | 190 | |
c9bccf23 | 191 | virtual Family Type() { return UNIX; } |
8ac36abb VZ |
192 | virtual wxSockAddress *Clone() const { return new wxUNIXaddress(*this); } |
193 | ||
194 | private: | |
c9bccf23 VZ |
195 | wxSockAddressImpl& GetUNIX(); |
196 | const wxSockAddressImpl& GetUNIX() const | |
197 | { | |
198 | return const_cast<wxUNIXaddress *>(this)->GetUNIX(); | |
199 | } | |
f4ada568 | 200 | |
8ac36abb | 201 | DECLARE_DYNAMIC_CLASS(wxUNIXaddress) |
f4ada568 | 202 | }; |
f4ada568 | 203 | |
c9bccf23 | 204 | #endif // wxHAS_UNIX_DOMAIN_SOCKETS |
65ccd2b8 | 205 | |
8ac36abb VZ |
206 | #endif // wxUSE_SOCKETS |
207 | ||
208 | #endif // _WX_SCKADDR_H_ |