1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Network address classes
4 // Author: Guilhem Lavaux
8 // Copyright: (c) 1997, 1998 Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_SCKADDR_H_
13 #define _WX_SCKADDR_H_
19 #include "wx/string.h"
21 class wxSockAddressImpl
;
23 // Any socket address kind
24 class WXDLLIMPEXP_NET wxSockAddress
: public wxObject
36 wxSockAddress(const wxSockAddress
& other
);
37 virtual ~wxSockAddress();
39 wxSockAddress
& operator=(const wxSockAddress
& other
);
42 virtual Family
Type() = 0;
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;
49 // implementation only, don't use
50 const wxSockAddressImpl
& GetAddress() const { return *m_impl
; }
51 void SetAddress(const wxSockAddressImpl
& address
);
54 wxSockAddressImpl
*m_impl
;
58 DECLARE_ABSTRACT_CLASS(wxSockAddress
)
61 // An IP address (either IPv4 or IPv6)
62 class WXDLLIMPEXP_NET wxIPaddress
: public wxSockAddress
65 wxIPaddress() : wxSockAddress() { }
66 wxIPaddress(const wxIPaddress
& other
)
67 : wxSockAddress(other
),
68 m_origHostname(other
.m_origHostname
)
72 bool operator==(const wxIPaddress
& addr
) const;
74 bool Hostname(const wxString
& name
);
75 bool Service(const wxString
& name
);
76 bool Service(unsigned short port
);
79 virtual bool IsLocalHost() const = 0;
83 virtual wxString
IPAddress() const = 0;
85 wxString
Hostname() const;
86 unsigned short Service() const;
88 wxString
OrigHostname() const { return m_origHostname
; }
91 // get m_impl initialized to the right family if it hadn't been done yet
92 wxSockAddressImpl
& GetImpl();
93 const wxSockAddressImpl
& GetImpl() const
95 return const_cast<wxIPaddress
*>(this)->GetImpl();
98 // host name originally passed to Hostname()
99 wxString m_origHostname
;
102 // create the wxSockAddressImpl object of the correct family if it's
103 // currently uninitialized
104 virtual void DoInitImpl() = 0;
107 DECLARE_ABSTRACT_CLASS(wxIPaddress
)
111 class WXDLLIMPEXP_NET wxIPV4address
: public wxIPaddress
114 wxIPV4address() : wxIPaddress() { }
115 wxIPV4address(const wxIPV4address
& other
) : wxIPaddress(other
) { }
117 // implement wxSockAddress pure virtuals:
118 virtual Family
Type() { return IPV4
; }
119 virtual wxSockAddress
*Clone() const { return new wxIPV4address(*this); }
122 // implement wxIPaddress pure virtuals:
123 virtual bool IsLocalHost() const;
125 virtual wxString
IPAddress() const;
128 // IPv4-specific methods:
129 bool Hostname(unsigned long addr
);
131 // make base class methods hidden by our overload visible
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
); }
138 bool BroadcastAddress();
141 virtual void DoInitImpl();
143 DECLARE_DYNAMIC_CLASS(wxIPV4address
)
150 class WXDLLIMPEXP_NET wxIPV6address
: public wxIPaddress
153 wxIPV6address() : wxIPaddress() { }
154 wxIPV6address(const wxIPV6address
& other
) : wxIPaddress(other
) { }
156 // implement wxSockAddress pure virtuals:
157 virtual Family
Type() { return IPV6
; }
158 virtual wxSockAddress
*Clone() const { return new wxIPV6address(*this); }
161 // implement wxIPaddress pure virtuals:
162 virtual bool IsLocalHost() const;
164 virtual wxString
IPAddress() const;
166 // IPv6-specific methods:
167 bool Hostname(unsigned char addr
[16]);
169 using wxIPaddress::Hostname
;
172 virtual void DoInitImpl();
174 DECLARE_DYNAMIC_CLASS(wxIPV6address
)
179 // Unix domain sockets are only available under, well, Unix
180 #if defined(__UNIX__) && !defined(__WINDOWS__) && !defined(__WINE__)
181 #define wxHAS_UNIX_DOMAIN_SOCKETS
184 #ifdef wxHAS_UNIX_DOMAIN_SOCKETS
186 // A Unix domain socket address
187 class WXDLLIMPEXP_NET wxUNIXaddress
: public wxSockAddress
190 wxUNIXaddress() : wxSockAddress() { }
191 wxUNIXaddress(const wxUNIXaddress
& other
) : wxSockAddress(other
) { }
193 void Filename(const wxString
& name
);
194 wxString
Filename() const;
196 virtual Family
Type() { return UNIX
; }
197 virtual wxSockAddress
*Clone() const { return new wxUNIXaddress(*this); }
200 wxSockAddressImpl
& GetUNIX();
201 const wxSockAddressImpl
& GetUNIX() const
203 return const_cast<wxUNIXaddress
*>(this)->GetUNIX();
206 DECLARE_DYNAMIC_CLASS(wxUNIXaddress
)
209 #endif // wxHAS_UNIX_DOMAIN_SOCKETS
211 #endif // wxUSE_SOCKETS
213 #endif // _WX_SCKADDR_H_