Commit | Line | Data |
---|---|---|
f4ada568 GL |
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 | |
65571936 | 9 | // Licence: wxWindows licence |
f4ada568 | 10 | ///////////////////////////////////////////////////////////////////////////// |
2df7be7f | 11 | |
f4ada568 GL |
12 | #ifndef _WX_NETWORK_ADDRESS_H |
13 | #define _WX_NETWORK_ADDRESS_H | |
14 | ||
12028905 | 15 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
af49c4b8 | 16 | #pragma interface "sckaddr.h" |
2df7be7f RR |
17 | #endif |
18 | ||
19 | #include "wx/defs.h" | |
20 | ||
21 | #if wxUSE_SOCKETS | |
22 | ||
2df7be7f | 23 | #include "wx/string.h" |
65ccd2b8 | 24 | #include "wx/gsocket.h" |
a324a7bc | 25 | |
f4ada568 | 26 | |
7c4728f6 | 27 | class WXDLLIMPEXP_NET wxSockAddress : public wxObject { |
f4ada568 GL |
28 | DECLARE_ABSTRACT_CLASS(wxSockAddress) |
29 | public: | |
30 | typedef enum { IPV4=1, IPV6=2, UNIX=3 } Addr; | |
31 | ||
a324a7bc | 32 | wxSockAddress(); |
1539c2f5 | 33 | wxSockAddress(const wxSockAddress& other); |
a324a7bc GL |
34 | virtual ~wxSockAddress(); |
35 | ||
1539c2f5 VZ |
36 | wxSockAddress& operator=(const wxSockAddress& other); |
37 | ||
a324a7bc GL |
38 | virtual void Clear(); |
39 | virtual int Type() = 0; | |
f4ada568 | 40 | |
a324a7bc GL |
41 | GAddress *GetAddress() const { return m_address; } |
42 | void SetAddress(GAddress *address); | |
f4ada568 | 43 | |
acd15a3f | 44 | // we need to be able to create copies of the addresses polymorphically (i.e. |
6c0d0845 | 45 | // without knowing the exact address class) |
acd15a3f | 46 | virtual wxSockAddress *Clone() const = 0; |
f4ada568 | 47 | |
a324a7bc GL |
48 | protected: |
49 | GAddress *m_address; | |
6c0d0845 VZ |
50 | |
51 | private: | |
52 | void Init(); | |
f4ada568 GL |
53 | }; |
54 | ||
be4bd463 JS |
55 | // Interface to an IP address (either IPV4 or IPV6) |
56 | class WXDLLIMPEXP_NET wxIPaddress : public wxSockAddress { | |
57 | DECLARE_ABSTRACT_CLASS(wxIPaddress) | |
58 | public: | |
59 | wxIPaddress(); | |
60 | wxIPaddress(const wxIPaddress& other); | |
61 | virtual ~wxIPaddress(); | |
62 | ||
63 | virtual bool Hostname(const wxString& name) = 0; | |
64 | virtual bool Service(const wxString& name) = 0; | |
65 | virtual bool Service(unsigned short port) = 0; | |
66 | ||
67 | virtual bool LocalHost() = 0; | |
68 | virtual bool IsLocalHost() const = 0; | |
69 | ||
70 | virtual bool AnyAddress() = 0; | |
71 | ||
72 | virtual wxString IPAddress() const = 0; | |
73 | ||
74 | virtual wxString Hostname() const = 0; | |
75 | virtual unsigned short Service() const = 0; | |
76 | }; | |
77 | ||
78 | class WXDLLIMPEXP_NET wxIPV4address : public wxIPaddress { | |
f4ada568 | 79 | DECLARE_DYNAMIC_CLASS(wxIPV4address) |
f4ada568 GL |
80 | public: |
81 | wxIPV4address(); | |
1539c2f5 | 82 | wxIPV4address(const wxIPV4address& other); |
f4ada568 GL |
83 | virtual ~wxIPV4address(); |
84 | ||
be4bd463 JS |
85 | // IPV4 name formats |
86 | // | |
87 | // hostname | |
88 | // dot format a.b.c.d | |
89 | virtual bool Hostname(const wxString& name); | |
a324a7bc | 90 | bool Hostname(unsigned long addr); |
be4bd463 JS |
91 | virtual bool Service(const wxString& name); |
92 | virtual bool Service(unsigned short port); | |
93 | ||
94 | // localhost (127.0.0.1) | |
95 | virtual bool LocalHost(); | |
96 | virtual bool IsLocalHost() const; | |
f4ada568 | 97 | |
be4bd463 JS |
98 | // any (0.0.0.0) |
99 | virtual bool AnyAddress(); | |
100 | ||
101 | virtual wxString Hostname() const; | |
ce22d615 | 102 | wxString OrigHostname() { return m_origHostname; } |
be4bd463 JS |
103 | virtual unsigned short Service() const; |
104 | ||
105 | // a.b.c.d | |
106 | virtual wxString IPAddress() const; | |
f4ada568 | 107 | |
acd15a3f | 108 | virtual int Type() { return wxSockAddress::IPV4; } |
ce22d615 | 109 | virtual wxSockAddress *Clone() const; |
d775fa82 | 110 | |
1d6d8b5d | 111 | bool operator==(wxIPV4address& addr); |
ce22d615 RD |
112 | |
113 | private: | |
114 | wxString m_origHostname; | |
f4ada568 GL |
115 | }; |
116 | ||
be4bd463 JS |
117 | #if wxUSE_IPV6 |
118 | ||
119 | // Experimental Only: | |
120 | // | |
121 | // IPV6 has not yet been implemented in socket layer | |
122 | class WXDLLIMPEXP_NET wxIPV6address : public wxIPaddress { | |
f4ada568 GL |
123 | DECLARE_DYNAMIC_CLASS(wxIPV6address) |
124 | private: | |
125 | struct sockaddr_in6 *m_addr; | |
126 | public: | |
127 | wxIPV6address(); | |
1539c2f5 VZ |
128 | wxIPV6address(const wxIPV6address& other); |
129 | virtual ~wxIPV6address(); | |
f4ada568 | 130 | |
be4bd463 JS |
131 | // IPV6 name formats |
132 | // | |
133 | // hostname | |
d775fa82 | 134 | // 3ffe:ffff:0100:f101:0210:a4ff:fee3:9566 |
be4bd463 JS |
135 | // compact (base85) Itu&-ZQ82s>J%s99FJXT |
136 | // compressed format ::1 | |
137 | // ipv4 mapped ::ffff:1.2.3.4 | |
138 | virtual bool Hostname(const wxString& name); | |
139 | ||
f4ada568 | 140 | bool Hostname(unsigned char addr[16]); |
be4bd463 JS |
141 | virtual bool Service(const wxString& name); |
142 | virtual bool Service(unsigned short port); | |
143 | ||
144 | // localhost (0000:0000:0000:0000:0000:0000:0000:0001 (::1)) | |
145 | virtual bool LocalHost(); | |
146 | virtual bool IsLocalHost() const; | |
f4ada568 | 147 | |
be4bd463 JS |
148 | // any (0000:0000:0000:0000:0000:0000:0000:0000 (::)) |
149 | virtual bool AnyAddress(); | |
150 | ||
d775fa82 | 151 | // 3ffe:ffff:0100:f101:0210:a4ff:fee3:9566 |
be4bd463 JS |
152 | virtual wxString IPAddress() const; |
153 | ||
154 | virtual wxString Hostname() const; | |
155 | virtual unsigned short Service() const; | |
f4ada568 | 156 | |
acd15a3f VZ |
157 | virtual int Type() { return wxSockAddress::IPV6; } |
158 | virtual wxSockAddress *Clone() const { return new wxIPV6address(*this); } | |
f4ada568 | 159 | }; |
be4bd463 JS |
160 | |
161 | #endif // wxUSE_IPV6 | |
f4ada568 | 162 | |
5283098e | 163 | #if defined(__UNIX__) && !defined(__WINE__) && (!defined(__WXMAC__) || defined(__DARWIN__)) |
fd9811b1 | 164 | #include <sys/socket.h> |
e1c70641 JJ |
165 | #ifndef __VMS__ |
166 | # include <sys/un.h> | |
167 | #endif | |
f4ada568 | 168 | |
7c4728f6 | 169 | class WXDLLIMPEXP_NET wxUNIXaddress : public wxSockAddress { |
f4ada568 GL |
170 | DECLARE_DYNAMIC_CLASS(wxUNIXaddress) |
171 | private: | |
172 | struct sockaddr_un *m_addr; | |
173 | public: | |
174 | wxUNIXaddress(); | |
1539c2f5 VZ |
175 | wxUNIXaddress(const wxUNIXaddress& other); |
176 | virtual ~wxUNIXaddress(); | |
f4ada568 | 177 | |
f4ada568 GL |
178 | void Filename(const wxString& name); |
179 | wxString Filename(); | |
180 | ||
acd15a3f VZ |
181 | virtual int Type() { return wxSockAddress::UNIX; } |
182 | virtual wxSockAddress *Clone() const { return new wxUNIXaddress(*this); } | |
f4ada568 GL |
183 | }; |
184 | #endif | |
2df7be7f | 185 | // __UNIX__ |
f4ada568 GL |
186 | |
187 | #endif | |
2df7be7f | 188 | // wxUSE_SOCKETS |
65ccd2b8 | 189 | |
2df7be7f RR |
190 | #endif |
191 | // _WX_NETWORK_ADDRESS_H |