]>
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" | |
36 | #include "wx/gsocket.h" | |
37 | #include "wx/sckaddr.h" | |
f4ada568 GL |
38 | |
39 | #if !USE_SHARED_LIBRARY | |
40 | IMPLEMENT_ABSTRACT_CLASS(wxSockAddress, wxObject) | |
41 | IMPLEMENT_DYNAMIC_CLASS(wxIPV4address, wxSockAddress) | |
42 | #ifdef ENABLE_IPV6 | |
43 | IMPLEMENT_DYNAMIC_CLASS(wxIPV6address, wxSockAddress) | |
44 | #endif | |
45 | #ifdef __UNIX__ | |
46 | IMPLEMENT_DYNAMIC_CLASS(wxUNIXaddress, wxSockAddress) | |
47 | #endif | |
48 | #endif | |
49 | ||
a324a7bc GL |
50 | // --------------------------------------------------------------------------- |
51 | // wxIPV4address | |
52 | // --------------------------------------------------------------------------- | |
53 | ||
54 | wxSockAddress::wxSockAddress() | |
69919241 | 55 | { |
a324a7bc | 56 | m_address = GAddress_new(); |
f4ada568 GL |
57 | } |
58 | ||
a324a7bc | 59 | wxSockAddress::~wxSockAddress() |
f4ada568 | 60 | { |
a324a7bc | 61 | GAddress_destroy(m_address); |
f4ada568 GL |
62 | } |
63 | ||
a324a7bc | 64 | void wxSockAddress::SetAddress(GAddress *address) |
f4ada568 | 65 | { |
a324a7bc GL |
66 | GAddress_destroy(m_address); |
67 | m_address = GAddress_copy(address); | |
f4ada568 GL |
68 | } |
69 | ||
a324a7bc | 70 | const wxSockAddress& wxSockAddress::operator=(const wxSockAddress& addr) |
f4ada568 | 71 | { |
a324a7bc GL |
72 | SetAddress(addr.GetAddress()); |
73 | return *this; | |
f4ada568 GL |
74 | } |
75 | ||
a324a7bc | 76 | void wxSockAddress::CopyObject(wxObject& dest) const |
f4ada568 | 77 | { |
a324a7bc GL |
78 | wxSockAddress *addr = (wxSockAddress *)&dest; |
79 | ||
80 | wxObject::CopyObject(dest); | |
81 | addr->SetAddress(GetAddress()); | |
f4ada568 GL |
82 | } |
83 | ||
a324a7bc GL |
84 | void wxSockAddress::Clear() |
85 | { | |
86 | GAddress_destroy(m_address); | |
87 | m_address = GAddress_new(); | |
f4ada568 | 88 | } |
f4ada568 | 89 | |
a324a7bc GL |
90 | // --------------------------------------------------------------------------- |
91 | // wxIPV4address | |
92 | // --------------------------------------------------------------------------- | |
93 | ||
94 | wxIPV4address::wxIPV4address() | |
95 | : wxSockAddress() | |
f4ada568 | 96 | { |
a324a7bc | 97 | } |
f4ada568 | 98 | |
a324a7bc GL |
99 | wxIPV4address::~wxIPV4address() |
100 | { | |
101 | } | |
f4ada568 | 102 | |
a324a7bc GL |
103 | bool wxIPV4address::Hostname(const wxString& name) |
104 | { | |
f61815af | 105 | // Some people are sometimes fool. |
223d09f6 KB |
106 | if (name == wxT("")) { |
107 | wxLogWarning( wxT("Trying to solve a NULL hostname: giving up") ); | |
f61815af GL |
108 | return FALSE; |
109 | } | |
110 | ||
a324a7bc | 111 | return (GAddress_INET_SetHostName(m_address, name.fn_str()) == GSOCK_NOERROR); |
f4ada568 GL |
112 | } |
113 | ||
114 | bool wxIPV4address::Hostname(unsigned long addr) | |
115 | { | |
5a96d2f4 | 116 | return (GAddress_INET_SetHostAddress(m_address, addr) == GSOCK_NOERROR); |
f4ada568 GL |
117 | } |
118 | ||
119 | bool wxIPV4address::Service(const wxString& name) | |
120 | { | |
5a96d2f4 | 121 | return (GAddress_INET_SetPortName(m_address, name.fn_str(), "tcp") == GSOCK_NOERROR); |
f4ada568 GL |
122 | } |
123 | ||
124 | bool wxIPV4address::Service(unsigned short port) | |
125 | { | |
a324a7bc | 126 | return (GAddress_INET_SetPort(m_address, port) == GSOCK_NOERROR); |
f4ada568 GL |
127 | } |
128 | ||
129 | bool wxIPV4address::LocalHost() | |
130 | { | |
a324a7bc | 131 | return (GAddress_INET_SetHostName(m_address, "localhost") == GSOCK_NOERROR); |
f4ada568 GL |
132 | } |
133 | ||
134 | wxString wxIPV4address::Hostname() | |
135 | { | |
a324a7bc | 136 | char hostname[1024]; |
f4ada568 | 137 | |
a324a7bc GL |
138 | hostname[0] = 0; |
139 | GAddress_INET_GetHostName(m_address, hostname, 1024); | |
140 | return wxString(hostname); | |
f4ada568 GL |
141 | } |
142 | ||
a324a7bc | 143 | unsigned short wxIPV4address::Service() |
f4ada568 | 144 | { |
a324a7bc | 145 | return GAddress_INET_GetPort(m_address); |
f4ada568 GL |
146 | } |
147 | ||
5a96d2f4 | 148 | #if 0 |
a324a7bc GL |
149 | // --------------------------------------------------------------------------- |
150 | // wxIPV6address | |
151 | // --------------------------------------------------------------------------- | |
f4ada568 GL |
152 | |
153 | wxIPV6address::wxIPV6address() | |
a324a7bc | 154 | : wxSockAddress() |
f4ada568 | 155 | { |
f4ada568 GL |
156 | } |
157 | ||
158 | wxIPV6address::~wxIPV6address() | |
159 | { | |
160 | } | |
161 | ||
f4ada568 GL |
162 | bool wxIPV6address::Hostname(const wxString& name) |
163 | { | |
a324a7bc | 164 | return (GAddress_INET_SetHostName(m_address, name.fn_str()) == GSOCK_NOERROR); |
f4ada568 GL |
165 | } |
166 | ||
167 | bool wxIPV6address::Hostname(unsigned char addr[16]) | |
168 | { | |
f4ada568 GL |
169 | return TRUE; |
170 | } | |
171 | ||
172 | bool wxIPV6address::Service(const char *name) | |
173 | { | |
a324a7bc | 174 | return (GAddress_INET_SetPortName(m_address, name.fn_str()) == GSOCK_NOERROR); |
f4ada568 GL |
175 | } |
176 | ||
177 | bool wxIPV6address::Service(unsigned short port) | |
178 | { | |
a324a7bc | 179 | return (GAddress_INET_SetPort(m_address, port) == GSOCK_NOERROR); |
f4ada568 GL |
180 | } |
181 | ||
182 | bool wxIPV6address::LocalHost() | |
183 | { | |
a324a7bc | 184 | return (GAddress_INET_SetHostName(m_address, "localhost") == GSOCK_NOERROR); |
f4ada568 GL |
185 | } |
186 | ||
187 | const wxString& wxIPV6address::Hostname() | |
188 | { | |
a324a7bc | 189 | return wxString(GAddress_INET_GetHostName(m_address)); |
f4ada568 GL |
190 | } |
191 | ||
192 | unsigned short wxIPV6address::Service() | |
193 | { | |
a324a7bc | 194 | return GAddress_INET_GetPort(m_address); |
f4ada568 GL |
195 | } |
196 | ||
197 | #endif | |
198 | ||
199 | #ifdef __UNIX__ | |
a324a7bc GL |
200 | // --------------------------------------------------------------------------- |
201 | // wxUNIXaddress | |
202 | // --------------------------------------------------------------------------- | |
f4ada568 GL |
203 | |
204 | wxUNIXaddress::wxUNIXaddress() | |
a324a7bc | 205 | : wxSockAddress() |
f4ada568 | 206 | { |
f4ada568 GL |
207 | } |
208 | ||
209 | wxUNIXaddress::~wxUNIXaddress() | |
210 | { | |
211 | } | |
212 | ||
f4ada568 GL |
213 | void wxUNIXaddress::Filename(const wxString& fname) |
214 | { | |
a324a7bc | 215 | GAddress_UNIX_SetPath(m_address, fname.fn_str()); |
f4ada568 GL |
216 | } |
217 | ||
218 | wxString wxUNIXaddress::Filename() | |
219 | { | |
a324a7bc | 220 | char path[1024]; |
f4ada568 | 221 | |
a324a7bc GL |
222 | path[0] = 0; |
223 | GAddress_UNIX_GetPath(m_address, path, 1024); | |
224 | return wxString(path); | |
f4ada568 GL |
225 | } |
226 | ||
f4ada568 | 227 | #endif |
35a4dab7 GL |
228 | |
229 | #endif | |
230 | // wxUSE_SOCKETS |