1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Network address classes
4 // Author: Guilhem Lavaux
8 // Copyright: (c) 1997, 1998 Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_NETWORK_ADDRESS_H
13 #define _WX_NETWORK_ADDRESS_H
23 #include "wx/string.h"
24 #include "wx/gsocket.h"
27 class WXDLLEXPORT wxSockAddress
: public wxObject
{
28 DECLARE_ABSTRACT_CLASS(wxSockAddress
)
30 typedef enum { IPV4
=1, IPV6
=2, UNIX
=3 } Addr
;
33 virtual ~wxSockAddress();
36 virtual int Type() = 0;
38 GAddress
*GetAddress() const { return m_address
; }
39 void SetAddress(GAddress
*address
);
40 const wxSockAddress
& operator =(const wxSockAddress
& addr
);
42 // we need to be able to create copies of the addresses polymorphically (i.e.
43 // wihtout knowing the exact address class)
44 virtual wxSockAddress
*Clone() const = 0;
50 class WXDLLEXPORT wxIPV4address
: public wxSockAddress
{
51 DECLARE_DYNAMIC_CLASS(wxIPV4address
)
54 virtual ~wxIPV4address();
56 bool Hostname(const wxString
& name
);
57 bool Hostname(unsigned long addr
);
58 bool Service(const wxString
& name
);
59 bool Service(unsigned short port
);
64 unsigned short Service();
66 virtual int Type() { return wxSockAddress::IPV4
; }
67 virtual wxSockAddress
*Clone() const { return new wxIPV4address(*this); }
71 class WXDLLEXPORT wxIPV6address
: public wxSockAddress
{
72 DECLARE_DYNAMIC_CLASS(wxIPV6address
)
74 struct sockaddr_in6
*m_addr
;
79 bool Hostname(const wxString
& name
);
80 bool Hostname(unsigned char addr
[16]);
81 bool Service(const wxString
& name
);
82 bool Service(unsigned short port
);
85 wxString
Hostname() const;
86 unsigned short Service() const;
88 virtual int Type() { return wxSockAddress::IPV6
; }
89 virtual wxSockAddress
*Clone() const { return new wxIPV6address(*this); }
93 #if defined(__UNIX__) && !defined(__WXMAC__)
94 #include <sys/socket.h>
99 class WXDLLEXPORT wxUNIXaddress
: public wxSockAddress
{
100 DECLARE_DYNAMIC_CLASS(wxUNIXaddress
)
102 struct sockaddr_un
*m_addr
;
107 void Filename(const wxString
& name
);
110 virtual int Type() { return wxSockAddress::UNIX
; }
111 virtual wxSockAddress
*Clone() const { return new wxUNIXaddress(*this); }
120 // _WX_NETWORK_ADDRESS_H