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 #if defined(__WINDOWS__) && defined(WXSOCK_INTERNAL)
26 #elif defined(__UNIX__) && defined(WXSOCK_INTERNAL)
28 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <netinet/in.h>
33 #include "wx/string.h"
35 class WXDLLEXPORT wxSockAddress
: public wxObject
{
36 DECLARE_ABSTRACT_CLASS(wxSockAddress
)
38 typedef enum { IPV4
=1, IPV6
=2, UNIX
=3 } Addr
;
41 virtual ~wxSockAddress() {};
43 virtual void Clear() = 0;
45 virtual void Build(struct sockaddr
*& addr
, size_t& len
) = 0;
46 virtual void Disassemble(struct sockaddr
*addr
, size_t len
) = 0;
47 virtual int SockAddrLen() = 0;
49 virtual int GetFamily() = 0;
50 virtual int Type() = 0;
53 class WXDLLEXPORT wxIPV4address
: public wxSockAddress
{
54 DECLARE_DYNAMIC_CLASS(wxIPV4address
)
56 struct sockaddr_in
*m_addr
;
59 virtual ~wxIPV4address();
62 // const wxSockAddress& operator =(const wxSockAddress& addr);
64 virtual bool Hostname(const wxString
& name
);
65 virtual bool Hostname(unsigned long addr
);
66 virtual bool Service(const wxString
& name
);
67 virtual bool Service(unsigned short port
);
68 virtual bool LocalHost();
71 unsigned short Service();
73 void Build(struct sockaddr
*& addr
, size_t& len
);
74 void Disassemble(struct sockaddr
*addr
, size_t len
);
76 inline int SockAddrLen();
77 inline int GetFamily();
78 inline int Type() { return wxSockAddress::IPV4
; }
82 class WXDLLEXPORT wxIPV6address
: public wxSockAddress
{
83 DECLARE_DYNAMIC_CLASS(wxIPV6address
)
85 struct sockaddr_in6
*m_addr
;
91 // const wxSockAddress& operator =(const wxSockAddress& addr);
93 bool Hostname(const wxString
& name
);
94 bool Hostname(unsigned char addr
[16]);
95 bool Service(const wxString
& name
);
96 bool Service(unsigned short port
);
99 wxString
Hostname() const;
100 unsigned short Service() const;
102 void Build(struct sockaddr
*& addr
, size_t& len
);
103 void Disassemble(struct sockaddr
*addr
, size_t len
);
105 inline int SockAddrLen();
106 inline int GetFamily();
107 inline int Type() { return wxSockAddress::IPV6
; }
114 class WXDLLEXPORT wxUNIXaddress
: public wxSockAddress
{
115 DECLARE_DYNAMIC_CLASS(wxUNIXaddress
)
117 struct sockaddr_un
*m_addr
;
123 // const wxSockAddress& operator =(const wxSockAddress& addr);
125 void Filename(const wxString
& name
);
128 void Build(struct sockaddr
*& addr
, size_t& len
);
129 void Disassemble(struct sockaddr
*addr
, size_t len
);
131 inline int SockAddrLen();
132 inline int GetFamily();
133 inline int Type() { return wxSockAddress::UNIX
; }
142 // _WX_NETWORK_ADDRESS_H