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 bool BroadcastAddress();
133 using wxIPaddress::Hostname
;
136 virtual void DoInitImpl();
138 DECLARE_DYNAMIC_CLASS(wxIPV4address
)
145 class WXDLLIMPEXP_NET wxIPV6address
: public wxIPaddress
148 wxIPV6address() : wxIPaddress() { }
149 wxIPV6address(const wxIPV6address
& other
) : wxIPaddress(other
) { }
151 // implement wxSockAddress pure virtuals:
152 virtual Family
Type() { return IPV6
; }
153 virtual wxSockAddress
*Clone() const { return new wxIPV6address(*this); }
156 // implement wxIPaddress pure virtuals:
157 virtual bool IsLocalHost() const;
159 virtual wxString
IPAddress() const;
161 // IPv6-specific methods:
162 bool Hostname(unsigned char addr
[16]);
164 using wxIPaddress::Hostname
;
167 virtual void DoInitImpl();
169 DECLARE_DYNAMIC_CLASS(wxIPV6address
)
174 // Unix domain sockets are only available under, well, Unix
175 #if defined(__UNIX__) && !defined(__WINDOWS__) && !defined(__WINE__)
176 #define wxHAS_UNIX_DOMAIN_SOCKETS
179 #ifdef wxHAS_UNIX_DOMAIN_SOCKETS
181 // A Unix domain socket address
182 class WXDLLIMPEXP_NET wxUNIXaddress
: public wxSockAddress
185 wxUNIXaddress() : wxSockAddress() { }
186 wxUNIXaddress(const wxUNIXaddress
& other
) : wxSockAddress(other
) { }
188 void Filename(const wxString
& name
);
189 wxString
Filename() const;
191 virtual Family
Type() { return UNIX
; }
192 virtual wxSockAddress
*Clone() const { return new wxUNIXaddress(*this); }
195 wxSockAddressImpl
& GetUNIX();
196 const wxSockAddressImpl
& GetUNIX() const
198 return const_cast<wxUNIXaddress
*>(this)->GetUNIX();
201 DECLARE_DYNAMIC_CLASS(wxUNIXaddress
)
204 #endif // wxHAS_UNIX_DOMAIN_SOCKETS
206 #endif // wxUSE_SOCKETS
208 #endif // _WX_SCKADDR_H_