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_NETWORK_ADDRESS_H
13 #define _WX_NETWORK_ADDRESS_H
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "sckaddr.h"
23 #include "wx/string.h"
24 #include "wx/gsocket.h"
27 class WXDLLIMPEXP_NET 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 // without knowing the exact address class)
46 virtual wxSockAddress
*Clone() const = 0;
55 class WXDLLIMPEXP_NET wxIPV4address
: public wxSockAddress
{
56 DECLARE_DYNAMIC_CLASS(wxIPV4address
)
59 wxIPV4address(const wxIPV4address
& other
);
60 virtual ~wxIPV4address();
62 bool Hostname(const wxString
& name
);
63 bool Hostname(unsigned long addr
);
64 bool Service(const wxString
& name
);
65 bool Service(unsigned short port
);
70 wxString
OrigHostname() { return m_origHostname
; }
71 unsigned short Service();
72 wxString
IPAddress() const;
74 virtual int Type() { return wxSockAddress::IPV4
; }
75 virtual wxSockAddress
*Clone() const;
78 wxString m_origHostname
;
82 class WXDLLIMPEXP_NET wxIPV6address
: public wxSockAddress
{
83 DECLARE_DYNAMIC_CLASS(wxIPV6address
)
85 struct sockaddr_in6
*m_addr
;
88 wxIPV6address(const wxIPV6address
& other
);
89 virtual ~wxIPV6address();
91 bool Hostname(const wxString
& name
);
92 bool Hostname(unsigned char addr
[16]);
93 bool Service(const wxString
& name
);
94 bool Service(unsigned short port
);
97 wxString
Hostname() const;
98 unsigned short Service() const;
100 virtual int Type() { return wxSockAddress::IPV6
; }
101 virtual wxSockAddress
*Clone() const { return new wxIPV6address(*this); }
105 #if defined(__UNIX__) && !defined(__WINE__) && (!defined(__WXMAC__) || defined(__DARWIN__))
106 #include <sys/socket.h>
111 class WXDLLIMPEXP_NET wxUNIXaddress
: public wxSockAddress
{
112 DECLARE_DYNAMIC_CLASS(wxUNIXaddress
)
114 struct sockaddr_un
*m_addr
;
117 wxUNIXaddress(const wxUNIXaddress
& other
);
118 virtual ~wxUNIXaddress();
120 void Filename(const wxString
& name
);
123 virtual int Type() { return wxSockAddress::UNIX
; }
124 virtual wxSockAddress
*Clone() const { return new wxUNIXaddress(*this); }
133 // _WX_NETWORK_ADDRESS_H