Applied patch [ 842285 ] comparison for wxIPV4address
[wxWidgets.git] / include / wx / sckaddr.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: sckaddr.h
3 // Purpose: Network address classes
4 // Author: Guilhem Lavaux
5 // Modified by:
6 // Created: 26/04/1997
7 // RCS-ID: $Id$
8 // Copyright: (c) 1997, 1998 Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_NETWORK_ADDRESS_H
13 #define _WX_NETWORK_ADDRESS_H
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "sckaddr.h"
17 #endif
18
19 #include "wx/defs.h"
20
21 #if wxUSE_SOCKETS
22
23 #include "wx/string.h"
24 #include "wx/gsocket.h"
25
26
27 class WXDLLIMPEXP_NET wxSockAddress : public wxObject {
28 DECLARE_ABSTRACT_CLASS(wxSockAddress)
29 public:
30 typedef enum { IPV4=1, IPV6=2, UNIX=3 } Addr;
31
32 wxSockAddress();
33 wxSockAddress(const wxSockAddress& other);
34 virtual ~wxSockAddress();
35
36 wxSockAddress& operator=(const wxSockAddress& other);
37
38 virtual void Clear();
39 virtual int Type() = 0;
40
41 GAddress *GetAddress() const { return m_address; }
42 void SetAddress(GAddress *address);
43
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;
47
48 protected:
49 GAddress *m_address;
50
51 private:
52 void Init();
53 };
54
55 class WXDLLIMPEXP_NET wxIPV4address : public wxSockAddress {
56 DECLARE_DYNAMIC_CLASS(wxIPV4address)
57 public:
58 wxIPV4address();
59 wxIPV4address(const wxIPV4address& other);
60 virtual ~wxIPV4address();
61
62 bool Hostname(const wxString& name);
63 bool Hostname(unsigned long addr);
64 bool Service(const wxString& name);
65 bool Service(unsigned short port);
66 bool LocalHost();
67 bool AnyAddress();
68
69 wxString Hostname();
70 wxString OrigHostname() { return m_origHostname; }
71 unsigned short Service();
72 wxString IPAddress() const;
73
74 virtual int Type() { return wxSockAddress::IPV4; }
75 virtual wxSockAddress *Clone() const;
76
77 bool operator==(wxIPV4address& addr);
78
79 private:
80 wxString m_origHostname;
81 };
82
83 #ifdef ENABLE_IPV6
84 class WXDLLIMPEXP_NET wxIPV6address : public wxSockAddress {
85 DECLARE_DYNAMIC_CLASS(wxIPV6address)
86 private:
87 struct sockaddr_in6 *m_addr;
88 public:
89 wxIPV6address();
90 wxIPV6address(const wxIPV6address& other);
91 virtual ~wxIPV6address();
92
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);
97 bool LocalHost();
98
99 wxString Hostname() const;
100 unsigned short Service() const;
101
102 virtual int Type() { return wxSockAddress::IPV6; }
103 virtual wxSockAddress *Clone() const { return new wxIPV6address(*this); }
104 };
105 #endif
106
107 #if defined(__UNIX__) && !defined(__WINE__) && (!defined(__WXMAC__) || defined(__DARWIN__))
108 #include <sys/socket.h>
109 #ifndef __VMS__
110 # include <sys/un.h>
111 #endif
112
113 class WXDLLIMPEXP_NET wxUNIXaddress : public wxSockAddress {
114 DECLARE_DYNAMIC_CLASS(wxUNIXaddress)
115 private:
116 struct sockaddr_un *m_addr;
117 public:
118 wxUNIXaddress();
119 wxUNIXaddress(const wxUNIXaddress& other);
120 virtual ~wxUNIXaddress();
121
122 void Filename(const wxString& name);
123 wxString Filename();
124
125 virtual int Type() { return wxSockAddress::UNIX; }
126 virtual wxSockAddress *Clone() const { return new wxUNIXaddress(*this); }
127 };
128 #endif
129 // __UNIX__
130
131 #endif
132 // wxUSE_SOCKETS
133
134 #endif
135 // _WX_NETWORK_ADDRESS_H