]>
Commit | Line | Data |
---|---|---|
f4ada568 GL |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: sckaddr.cpp | |
3 | // Purpose: Network address manager | |
4 | // Author: Guilhem Lavaux | |
5 | // Modified by: | |
6 | // Created: 26/04/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1997, 1998 Guilhem Lavaux | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
2df7be7f | 13 | #pragma implementation "sckaddr.h" |
f4ada568 GL |
14 | #endif |
15 | ||
fcc6dddd JS |
16 | // For compilers that support precompilation, includes "wx.h". |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
2df7be7f | 20 | #pragma hdrstop |
fcc6dddd JS |
21 | #endif |
22 | ||
35a4dab7 GL |
23 | #if wxUSE_SOCKETS |
24 | ||
f4ada568 GL |
25 | #include <stdio.h> |
26 | #include <stdlib.h> | |
27 | #include <ctype.h> | |
ce3ed50d JS |
28 | |
29 | #if !defined(__MWERKS__) && !defined(__SALFORDC__) | |
f4ada568 | 30 | #include <memory.h> |
469e1e5c | 31 | #endif |
f4ada568 | 32 | |
3096bd2f VZ |
33 | #include "wx/defs.h" |
34 | #include "wx/object.h" | |
35 | #include "wx/log.h" | |
58c837a4 | 36 | #include "wx/intl.h" |
3096bd2f VZ |
37 | #include "wx/gsocket.h" |
38 | #include "wx/sckaddr.h" | |
f4ada568 | 39 | |
f4ada568 GL |
40 | IMPLEMENT_ABSTRACT_CLASS(wxSockAddress, wxObject) |
41 | IMPLEMENT_DYNAMIC_CLASS(wxIPV4address, wxSockAddress) | |
42 | #ifdef ENABLE_IPV6 | |
43 | IMPLEMENT_DYNAMIC_CLASS(wxIPV6address, wxSockAddress) | |
44 | #endif | |
0cbb9297 | 45 | #if defined(__UNIX__) && !defined(__WXMAC__) |
f4ada568 GL |
46 | IMPLEMENT_DYNAMIC_CLASS(wxUNIXaddress, wxSockAddress) |
47 | #endif | |
f4ada568 | 48 | |
a324a7bc GL |
49 | // --------------------------------------------------------------------------- |
50 | // wxIPV4address | |
51 | // --------------------------------------------------------------------------- | |
52 | ||
53 | wxSockAddress::wxSockAddress() | |
69919241 | 54 | { |
a324a7bc | 55 | m_address = GAddress_new(); |
f4ada568 GL |
56 | } |
57 | ||
a324a7bc | 58 | wxSockAddress::~wxSockAddress() |
f4ada568 | 59 | { |
a324a7bc | 60 | GAddress_destroy(m_address); |
f4ada568 GL |
61 | } |
62 | ||
a324a7bc | 63 | void wxSockAddress::SetAddress(GAddress *address) |
f4ada568 | 64 | { |
a324a7bc GL |
65 | GAddress_destroy(m_address); |
66 | m_address = GAddress_copy(address); | |
f4ada568 GL |
67 | } |
68 | ||
a324a7bc | 69 | const wxSockAddress& wxSockAddress::operator=(const wxSockAddress& addr) |
f4ada568 | 70 | { |
a324a7bc GL |
71 | SetAddress(addr.GetAddress()); |
72 | return *this; | |
f4ada568 GL |
73 | } |
74 | ||
a324a7bc | 75 | void wxSockAddress::Clear() |
acd15a3f | 76 | { |
a324a7bc GL |
77 | GAddress_destroy(m_address); |
78 | m_address = GAddress_new(); | |
f4ada568 | 79 | } |
f4ada568 | 80 | |
a324a7bc GL |
81 | // --------------------------------------------------------------------------- |
82 | // wxIPV4address | |
83 | // --------------------------------------------------------------------------- | |
84 | ||
85 | wxIPV4address::wxIPV4address() | |
86 | : wxSockAddress() | |
f4ada568 | 87 | { |
a324a7bc | 88 | } |
f4ada568 | 89 | |
a324a7bc GL |
90 | wxIPV4address::~wxIPV4address() |
91 | { | |
92 | } | |
f4ada568 | 93 | |
a324a7bc GL |
94 | bool wxIPV4address::Hostname(const wxString& name) |
95 | { | |
f61815af | 96 | // Some people are sometimes fool. |
acd15a3f | 97 | if (name == wxT("")) |
58c837a4 RR |
98 | { |
99 | wxLogWarning( _("Trying to solve a NULL hostname: giving up") ); | |
f61815af GL |
100 | return FALSE; |
101 | } | |
102 | ||
f6bcfd97 | 103 | return (GAddress_INET_SetHostName(m_address, name.mb_str()) == GSOCK_NOERROR); |
f4ada568 GL |
104 | } |
105 | ||
106 | bool wxIPV4address::Hostname(unsigned long addr) | |
107 | { | |
5a96d2f4 | 108 | return (GAddress_INET_SetHostAddress(m_address, addr) == GSOCK_NOERROR); |
f4ada568 GL |
109 | } |
110 | ||
111 | bool wxIPV4address::Service(const wxString& name) | |
112 | { | |
f6bcfd97 | 113 | return (GAddress_INET_SetPortName(m_address, name.mb_str(), "tcp") == GSOCK_NOERROR); |
f4ada568 GL |
114 | } |
115 | ||
116 | bool wxIPV4address::Service(unsigned short port) | |
117 | { | |
a324a7bc | 118 | return (GAddress_INET_SetPort(m_address, port) == GSOCK_NOERROR); |
f4ada568 GL |
119 | } |
120 | ||
121 | bool wxIPV4address::LocalHost() | |
122 | { | |
a324a7bc | 123 | return (GAddress_INET_SetHostName(m_address, "localhost") == GSOCK_NOERROR); |
f4ada568 GL |
124 | } |
125 | ||
d3ea6527 GRG |
126 | bool wxIPV4address::AnyAddress() |
127 | { | |
128 | return (GAddress_INET_SetAnyAddress(m_address) == GSOCK_NOERROR); | |
129 | } | |
130 | ||
f4ada568 GL |
131 | wxString wxIPV4address::Hostname() |
132 | { | |
a324a7bc | 133 | char hostname[1024]; |
f4ada568 | 134 | |
a324a7bc GL |
135 | hostname[0] = 0; |
136 | GAddress_INET_GetHostName(m_address, hostname, 1024); | |
137 | return wxString(hostname); | |
f4ada568 GL |
138 | } |
139 | ||
a324a7bc | 140 | unsigned short wxIPV4address::Service() |
f4ada568 | 141 | { |
acd15a3f | 142 | return GAddress_INET_GetPort(m_address); |
f4ada568 GL |
143 | } |
144 | ||
5a96d2f4 | 145 | #if 0 |
a324a7bc GL |
146 | // --------------------------------------------------------------------------- |
147 | // wxIPV6address | |
148 | // --------------------------------------------------------------------------- | |
f4ada568 GL |
149 | |
150 | wxIPV6address::wxIPV6address() | |
a324a7bc | 151 | : wxSockAddress() |
f4ada568 | 152 | { |
f4ada568 GL |
153 | } |
154 | ||
155 | wxIPV6address::~wxIPV6address() | |
156 | { | |
157 | } | |
158 | ||
f4ada568 GL |
159 | bool wxIPV6address::Hostname(const wxString& name) |
160 | { | |
a324a7bc | 161 | return (GAddress_INET_SetHostName(m_address, name.fn_str()) == GSOCK_NOERROR); |
f4ada568 GL |
162 | } |
163 | ||
164 | bool wxIPV6address::Hostname(unsigned char addr[16]) | |
165 | { | |
f4ada568 GL |
166 | return TRUE; |
167 | } | |
168 | ||
169 | bool wxIPV6address::Service(const char *name) | |
170 | { | |
a324a7bc | 171 | return (GAddress_INET_SetPortName(m_address, name.fn_str()) == GSOCK_NOERROR); |
f4ada568 GL |
172 | } |
173 | ||
174 | bool wxIPV6address::Service(unsigned short port) | |
175 | { | |
a324a7bc | 176 | return (GAddress_INET_SetPort(m_address, port) == GSOCK_NOERROR); |
f4ada568 GL |
177 | } |
178 | ||
179 | bool wxIPV6address::LocalHost() | |
180 | { | |
a324a7bc | 181 | return (GAddress_INET_SetHostName(m_address, "localhost") == GSOCK_NOERROR); |
f4ada568 GL |
182 | } |
183 | ||
184 | const wxString& wxIPV6address::Hostname() | |
185 | { | |
a324a7bc | 186 | return wxString(GAddress_INET_GetHostName(m_address)); |
f4ada568 GL |
187 | } |
188 | ||
189 | unsigned short wxIPV6address::Service() | |
190 | { | |
acd15a3f | 191 | return GAddress_INET_GetPort(m_address); |
f4ada568 GL |
192 | } |
193 | ||
194 | #endif | |
195 | ||
0cbb9297 | 196 | #if defined(__UNIX__) && !defined(__WXMAC__) |
a324a7bc GL |
197 | // --------------------------------------------------------------------------- |
198 | // wxUNIXaddress | |
199 | // --------------------------------------------------------------------------- | |
f4ada568 GL |
200 | |
201 | wxUNIXaddress::wxUNIXaddress() | |
a324a7bc | 202 | : wxSockAddress() |
f4ada568 | 203 | { |
f4ada568 GL |
204 | } |
205 | ||
206 | wxUNIXaddress::~wxUNIXaddress() | |
207 | { | |
208 | } | |
209 | ||
f4ada568 GL |
210 | void wxUNIXaddress::Filename(const wxString& fname) |
211 | { | |
a324a7bc | 212 | GAddress_UNIX_SetPath(m_address, fname.fn_str()); |
f4ada568 GL |
213 | } |
214 | ||
215 | wxString wxUNIXaddress::Filename() | |
216 | { | |
a324a7bc | 217 | char path[1024]; |
f4ada568 | 218 | |
a324a7bc GL |
219 | path[0] = 0; |
220 | GAddress_UNIX_GetPath(m_address, path, 1024); | |
221 | return wxString(path); | |
f4ada568 GL |
222 | } |
223 | ||
f4ada568 | 224 | #endif |
35a4dab7 | 225 | |
acd15a3f | 226 | #endif |
35a4dab7 | 227 | // wxUSE_SOCKETS |