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 wxSockAddress(const wxSockAddress
& other
);
34 virtual ~wxSockAddress();
36 wxSockAddress
& operator=(const wxSockAddress
& other
);
39 virtual int Type() = 0;
41 GAddress
*GetAddress() const { return m_address
; }
42 void SetAddress(GAddress
*address
);
44 // we need to be able to create copies of the addresses polymorphically (i.e.
45 // wihtout knowing the exact address class)
46 virtual wxSockAddress
*Clone() const = 0;
52 class WXDLLEXPORT wxIPV4address
: public wxSockAddress
{
53 DECLARE_DYNAMIC_CLASS(wxIPV4address
)
56 wxIPV4address(const wxIPV4address
& other
);
57 virtual ~wxIPV4address();
59 bool Hostname(const wxString
& name
);
60 bool Hostname(unsigned long addr
);
61 bool Service(const wxString
& name
);
62 bool Service(unsigned short port
);
67 unsigned short Service();
69 virtual int Type() { return wxSockAddress::IPV4
; }
70 virtual wxSockAddress
*Clone() const { return new wxIPV4address(*this); }
74 class WXDLLEXPORT wxIPV6address
: public wxSockAddress
{
75 DECLARE_DYNAMIC_CLASS(wxIPV6address
)
77 struct sockaddr_in6
*m_addr
;
80 wxIPV6address(const wxIPV6address
& other
);
81 virtual ~wxIPV6address();
83 bool Hostname(const wxString
& name
);
84 bool Hostname(unsigned char addr
[16]);
85 bool Service(const wxString
& name
);
86 bool Service(unsigned short port
);
89 wxString
Hostname() const;
90 unsigned short Service() const;
92 virtual int Type() { return wxSockAddress::IPV6
; }
93 virtual wxSockAddress
*Clone() const { return new wxIPV6address(*this); }
97 #if defined(__UNIX__) && !defined(__WXMAC__)
98 #include <sys/socket.h>
103 class WXDLLEXPORT wxUNIXaddress
: public wxSockAddress
{
104 DECLARE_DYNAMIC_CLASS(wxUNIXaddress
)
106 struct sockaddr_un
*m_addr
;
109 wxUNIXaddress(const wxUNIXaddress
& other
);
110 virtual ~wxUNIXaddress();
112 void Filename(const wxString
& name
);
115 virtual int Type() { return wxSockAddress::UNIX
; }
116 virtual wxSockAddress
*Clone() const { return new wxUNIXaddress(*this); }
125 // _WX_NETWORK_ADDRESS_H