]>
Commit | Line | Data |
---|---|---|
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__ | |
13 | #pragma implementation "sckaddr.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #if wxUSE_SOCKETS | |
24 | ||
25 | #include <stdio.h> | |
26 | #include <stdlib.h> | |
27 | #include <ctype.h> | |
28 | ||
29 | #if !defined(__MWERKS__) && !defined(__SALFORDC__) | |
30 | #include <memory.h> | |
31 | #endif | |
32 | ||
33 | #include <wx/defs.h> | |
34 | #include <wx/object.h> | |
35 | #include <wx/gsocket.h> | |
36 | #include <wx/sckaddr.h> | |
37 | ||
38 | #if !USE_SHARED_LIBRARY | |
39 | IMPLEMENT_ABSTRACT_CLASS(wxSockAddress, wxObject) | |
40 | IMPLEMENT_DYNAMIC_CLASS(wxIPV4address, wxSockAddress) | |
41 | #ifdef ENABLE_IPV6 | |
42 | IMPLEMENT_DYNAMIC_CLASS(wxIPV6address, wxSockAddress) | |
43 | #endif | |
44 | #ifdef __UNIX__ | |
45 | IMPLEMENT_DYNAMIC_CLASS(wxUNIXaddress, wxSockAddress) | |
46 | #endif | |
47 | #endif | |
48 | ||
49 | // --------------------------------------------------------------------------- | |
50 | // wxIPV4address | |
51 | // --------------------------------------------------------------------------- | |
52 | ||
53 | wxSockAddress::wxSockAddress() | |
54 | { | |
55 | m_address = GAddress_new(); | |
56 | } | |
57 | ||
58 | wxSockAddress::~wxSockAddress() | |
59 | { | |
60 | GAddress_destroy(m_address); | |
61 | } | |
62 | ||
63 | void wxSockAddress::SetAddress(GAddress *address) | |
64 | { | |
65 | GAddress_destroy(m_address); | |
66 | m_address = GAddress_copy(address); | |
67 | } | |
68 | ||
69 | const wxSockAddress& wxSockAddress::operator=(const wxSockAddress& addr) | |
70 | { | |
71 | SetAddress(addr.GetAddress()); | |
72 | return *this; | |
73 | } | |
74 | ||
75 | void wxSockAddress::CopyObject(wxObject& dest) const | |
76 | { | |
77 | wxSockAddress *addr = (wxSockAddress *)&dest; | |
78 | ||
79 | wxObject::CopyObject(dest); | |
80 | addr->SetAddress(GetAddress()); | |
81 | } | |
82 | ||
83 | void wxSockAddress::Clear() | |
84 | { | |
85 | GAddress_destroy(m_address); | |
86 | m_address = GAddress_new(); | |
87 | } | |
88 | ||
89 | // --------------------------------------------------------------------------- | |
90 | // wxIPV4address | |
91 | // --------------------------------------------------------------------------- | |
92 | ||
93 | wxIPV4address::wxIPV4address() | |
94 | : wxSockAddress() | |
95 | { | |
96 | } | |
97 | ||
98 | wxIPV4address::~wxIPV4address() | |
99 | { | |
100 | } | |
101 | ||
102 | bool wxIPV4address::Hostname(const wxString& name) | |
103 | { | |
104 | return (GAddress_INET_SetHostName(m_address, name.fn_str()) == GSOCK_NOERROR); | |
105 | } | |
106 | ||
107 | bool wxIPV4address::Hostname(unsigned long addr) | |
108 | { | |
109 | return (GAddress_INET_SetHostAddress(m_address, addr) == GSOCK_NOERROR); | |
110 | } | |
111 | ||
112 | bool wxIPV4address::Service(const wxString& name) | |
113 | { | |
114 | return (GAddress_INET_SetPortName(m_address, name.fn_str(), "tcp") == GSOCK_NOERROR); | |
115 | } | |
116 | ||
117 | bool wxIPV4address::Service(unsigned short port) | |
118 | { | |
119 | return (GAddress_INET_SetPort(m_address, port) == GSOCK_NOERROR); | |
120 | } | |
121 | ||
122 | bool wxIPV4address::LocalHost() | |
123 | { | |
124 | return (GAddress_INET_SetHostName(m_address, "localhost") == GSOCK_NOERROR); | |
125 | } | |
126 | ||
127 | wxString wxIPV4address::Hostname() | |
128 | { | |
129 | char hostname[1024]; | |
130 | ||
131 | hostname[0] = 0; | |
132 | GAddress_INET_GetHostName(m_address, hostname, 1024); | |
133 | return wxString(hostname); | |
134 | } | |
135 | ||
136 | unsigned short wxIPV4address::Service() | |
137 | { | |
138 | return GAddress_INET_GetPort(m_address); | |
139 | } | |
140 | ||
141 | #if 0 | |
142 | // --------------------------------------------------------------------------- | |
143 | // wxIPV6address | |
144 | // --------------------------------------------------------------------------- | |
145 | ||
146 | wxIPV6address::wxIPV6address() | |
147 | : wxSockAddress() | |
148 | { | |
149 | } | |
150 | ||
151 | wxIPV6address::~wxIPV6address() | |
152 | { | |
153 | } | |
154 | ||
155 | bool wxIPV6address::Hostname(const wxString& name) | |
156 | { | |
157 | return (GAddress_INET_SetHostName(m_address, name.fn_str()) == GSOCK_NOERROR); | |
158 | } | |
159 | ||
160 | bool wxIPV6address::Hostname(unsigned char addr[16]) | |
161 | { | |
162 | return TRUE; | |
163 | } | |
164 | ||
165 | bool wxIPV6address::Service(const char *name) | |
166 | { | |
167 | return (GAddress_INET_SetPortName(m_address, name.fn_str()) == GSOCK_NOERROR); | |
168 | } | |
169 | ||
170 | bool wxIPV6address::Service(unsigned short port) | |
171 | { | |
172 | return (GAddress_INET_SetPort(m_address, port) == GSOCK_NOERROR); | |
173 | } | |
174 | ||
175 | bool wxIPV6address::LocalHost() | |
176 | { | |
177 | return (GAddress_INET_SetHostName(m_address, "localhost") == GSOCK_NOERROR); | |
178 | } | |
179 | ||
180 | const wxString& wxIPV6address::Hostname() | |
181 | { | |
182 | return wxString(GAddress_INET_GetHostName(m_address)); | |
183 | } | |
184 | ||
185 | unsigned short wxIPV6address::Service() | |
186 | { | |
187 | return GAddress_INET_GetPort(m_address); | |
188 | } | |
189 | ||
190 | #endif | |
191 | ||
192 | #ifdef __UNIX__ | |
193 | // --------------------------------------------------------------------------- | |
194 | // wxUNIXaddress | |
195 | // --------------------------------------------------------------------------- | |
196 | ||
197 | wxUNIXaddress::wxUNIXaddress() | |
198 | : wxSockAddress() | |
199 | { | |
200 | } | |
201 | ||
202 | wxUNIXaddress::~wxUNIXaddress() | |
203 | { | |
204 | } | |
205 | ||
206 | void wxUNIXaddress::Filename(const wxString& fname) | |
207 | { | |
208 | GAddress_UNIX_SetPath(m_address, fname.fn_str()); | |
209 | } | |
210 | ||
211 | wxString wxUNIXaddress::Filename() | |
212 | { | |
213 | char path[1024]; | |
214 | ||
215 | path[0] = 0; | |
216 | GAddress_UNIX_GetPath(m_address, path, 1024); | |
217 | return wxString(path); | |
218 | } | |
219 | ||
220 | #endif | |
221 | ||
222 | #endif | |
223 | // wxUSE_SOCKETS |