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_SCKADDR_H_
13 #define _WX_SCKADDR_H_
19 #include "wx/string.h"
21 #include "wx/gsocket.h"
23 // Any socket address kind
24 class WXDLLIMPEXP_NET wxSockAddress
: public wxObject
35 wxSockAddress(const wxSockAddress
& other
);
36 virtual ~wxSockAddress();
38 wxSockAddress
& operator=(const wxSockAddress
& other
);
41 virtual int Type() = 0;
43 // we need to be able to create copies of the addresses polymorphically
44 // (i.e. without knowing the exact address class)
45 virtual wxSockAddress
*Clone() const = 0;
48 // implementation only, don't use
49 GAddress
*GetAddress() const { return m_address
; }
50 void SetAddress(GAddress
*address
);
57 DECLARE_ABSTRACT_CLASS(wxSockAddress
)
60 // An IP address (either IPv4 or IPv6)
61 class WXDLLIMPEXP_NET wxIPaddress
: public wxSockAddress
65 wxIPaddress(const wxIPaddress
& other
);
66 virtual ~wxIPaddress();
68 virtual bool Hostname(const wxString
& name
) = 0;
69 virtual bool Service(const wxString
& name
) = 0;
70 virtual bool Service(unsigned short port
) = 0;
72 virtual bool LocalHost() = 0;
73 virtual bool IsLocalHost() const = 0;
75 virtual bool AnyAddress() = 0;
76 virtual bool BroadcastAddress() = 0;
78 virtual wxString
IPAddress() const = 0;
80 virtual wxString
Hostname() const = 0;
81 virtual unsigned short Service() const = 0;
83 DECLARE_ABSTRACT_CLASS(wxIPaddress
)
87 class WXDLLIMPEXP_NET wxIPV4address
: public wxIPaddress
91 wxIPV4address(const wxIPV4address
& other
);
92 virtual ~wxIPV4address();
94 bool operator==(const wxIPV4address
& addr
) const;
96 // implement wxSockAddress pure virtuals:
97 virtual int Type() { return wxSockAddress::IPV4
; }
98 virtual wxSockAddress
*Clone() const;
101 // implement wxIPaddress pure virtuals:
103 // handles the usual dotted quad format too
104 virtual bool Hostname(const wxString
& name
);
105 virtual bool Service(const wxString
& name
);
106 virtual bool Service(unsigned short port
);
108 // localhost (127.0.0.1)
109 virtual bool LocalHost();
110 virtual bool IsLocalHost() const;
113 virtual bool AnyAddress();
114 // all (255.255.255.255)
115 virtual bool BroadcastAddress();
118 virtual wxString
IPAddress() const;
120 virtual wxString
Hostname() const;
121 virtual unsigned short Service() const;
124 // IPv4-specific methods:
126 bool Hostname(unsigned long addr
);
127 wxString
OrigHostname() { return m_origHostname
; }
130 wxString m_origHostname
;
132 DECLARE_DYNAMIC_CLASS(wxIPV4address
)
139 class WXDLLIMPEXP_NET wxIPV6address
: public wxIPaddress
143 wxIPV6address(const wxIPV6address
& other
);
144 virtual ~wxIPV6address();
146 // implement wxSockAddress pure virtuals:
148 virtual int Type() { return wxSockAddress::IPV6
; }
149 virtual wxSockAddress
*Clone() const { return new wxIPV6address(*this); }
152 // implement wxIPaddress pure virtuals:
154 virtual bool Hostname(const wxString
& name
);
155 virtual bool Service(const wxString
& name
);
156 virtual bool Service(unsigned short port
);
158 // localhost (0000:0000:0000:0000:0000:0000:0000:0001 (::1))
159 virtual bool LocalHost();
160 virtual bool IsLocalHost() const;
162 // any (0000:0000:0000:0000:0000:0000:0000:0000 (::))
163 virtual bool AnyAddress();
165 virtual bool BroadcastAddress();
167 // 3ffe:ffff:0100:f101:0210:a4ff:fee3:9566
168 virtual wxString
IPAddress() const;
170 virtual wxString
Hostname() const;
171 virtual unsigned short Service() const;
174 // IPv6-specific methods:
176 bool Hostname(unsigned char addr
[16]);
179 wxString m_origHostname
;
181 DECLARE_DYNAMIC_CLASS(wxIPV6address
)
186 #if defined(__UNIX__) && !defined(__WINE__)
188 #include <sys/socket.h>
193 // A Unix domain socket address
194 class WXDLLIMPEXP_NET wxUNIXaddress
: public wxSockAddress
198 wxUNIXaddress(const wxUNIXaddress
& other
);
199 virtual ~wxUNIXaddress();
201 void Filename(const wxString
& name
);
204 virtual int Type() { return wxSockAddress::UNIX
; }
205 virtual wxSockAddress
*Clone() const { return new wxUNIXaddress(*this); }
208 struct sockaddr_un
*m_addr
;
210 DECLARE_DYNAMIC_CLASS(wxUNIXaddress
)
215 #endif // wxUSE_SOCKETS
217 #endif // _WX_SCKADDR_H_