1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Network address classes
4 // Author: Guilhem Lavaux
8 // Copyright: (c) 1997, 1998 Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_NETWORK_ADDRESS_H
12 #define _WX_NETWORK_ADDRESS_H
14 #if defined(__WINDOWS__) && defined(WXSOCK_INTERNAL)
17 #elif defined(__UNIX__) && defined(WXSOCK_INTERNAL)
19 #include <sys/types.h>
20 #include <sys/socket.h>
21 #include <netinet/in.h>
29 #include <wx/wxprec.h>
34 class WXDLLEXPORT wxSockAddress
: public wxObject
{
35 DECLARE_ABSTRACT_CLASS(wxSockAddress
)
37 typedef enum { IPV4
=1, IPV6
=2, UNIX
=3 } Addr
;
40 virtual ~wxSockAddress() {};
42 virtual void Clear() = 0;
44 virtual void Build(struct sockaddr
*& addr
, size_t& len
) = 0;
45 virtual void Disassemble(struct sockaddr
*addr
, size_t len
) = 0;
46 virtual int SockAddrLen() = 0;
48 virtual int GetFamily() = 0;
49 virtual int Type() = 0;
52 class WXDLLEXPORT wxIPV4address
: public wxSockAddress
{
53 DECLARE_DYNAMIC_CLASS(wxIPV4address
)
55 struct sockaddr_in
*m_addr
;
58 virtual ~wxIPV4address();
61 // const wxSockAddress& operator =(const wxSockAddress& addr);
63 virtual bool Hostname(const wxString
& name
);
64 virtual bool Hostname(unsigned long addr
);
65 virtual bool Service(const wxString
& name
);
66 virtual bool Service(unsigned short port
);
67 virtual bool LocalHost();
70 unsigned short Service();
72 void Build(struct sockaddr
*& addr
, size_t& len
);
73 void Disassemble(struct sockaddr
*addr
, size_t len
);
75 inline int SockAddrLen();
76 inline int GetFamily();
77 inline int Type() { return wxSockAddress::IPV4
; }
81 class WXDLLEXPORT wxIPV6address
: public wxSockAddress
{
82 DECLARE_DYNAMIC_CLASS(wxIPV6address
)
84 struct sockaddr_in6
*m_addr
;
90 // const wxSockAddress& operator =(const wxSockAddress& addr);
92 bool Hostname(const wxString
& name
);
93 bool Hostname(unsigned char addr
[16]);
94 bool Service(const wxString
& name
);
95 bool Service(unsigned short port
);
98 wxString
Hostname() const;
99 unsigned short Service() const;
101 void Build(struct sockaddr
*& addr
, size_t& len
);
102 void Disassemble(struct sockaddr
*addr
, size_t len
);
104 inline int SockAddrLen();
105 inline int GetFamily();
106 inline int Type() { return wxSockAddress::IPV6
; }
113 class WXDLLEXPORT wxUNIXaddress
: public wxSockAddress
{
114 DECLARE_DYNAMIC_CLASS(wxUNIXaddress
)
116 struct sockaddr_un
*m_addr
;
122 // const wxSockAddress& operator =(const wxSockAddress& addr);
124 void Filename(const wxString
& name
);
127 void Build(struct sockaddr
*& addr
, size_t& len
);
128 void Disassemble(struct sockaddr
*addr
, size_t len
);
130 inline int SockAddrLen();
131 inline int GetFamily();
132 inline int Type() { return wxSockAddress::UNIX
; }