]> git.saurik.com Git - wxWidgets.git/blob - src/common/sckaddr.cpp
fixed wxTaskBarIcon compilation
[wxWidgets.git] / src / common / sckaddr.cpp
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/log.h"
36 #include "wx/intl.h"
37 #include "wx/gsocket.h"
38 #include "wx/sckaddr.h"
39
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 #if defined(__UNIX__) && !defined(__WXMAC__)
46 IMPLEMENT_DYNAMIC_CLASS(wxUNIXaddress, wxSockAddress)
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::Clear()
76 {
77 GAddress_destroy(m_address);
78 m_address = GAddress_new();
79 }
80
81 // ---------------------------------------------------------------------------
82 // wxIPV4address
83 // ---------------------------------------------------------------------------
84
85 wxIPV4address::wxIPV4address()
86 : wxSockAddress()
87 {
88 }
89
90 wxIPV4address::~wxIPV4address()
91 {
92 }
93
94 bool wxIPV4address::Hostname(const wxString& name)
95 {
96 // Some people are sometimes fool.
97 if (name == wxT(""))
98 {
99 wxLogWarning( _("Trying to solve a NULL hostname: giving up") );
100 return FALSE;
101 }
102
103 return (GAddress_INET_SetHostName(m_address, name.mb_str()) == GSOCK_NOERROR);
104 }
105
106 bool wxIPV4address::Hostname(unsigned long addr)
107 {
108 return (GAddress_INET_SetHostAddress(m_address, addr) == GSOCK_NOERROR);
109 }
110
111 bool wxIPV4address::Service(const wxString& name)
112 {
113 return (GAddress_INET_SetPortName(m_address, name.mb_str(), "tcp") == GSOCK_NOERROR);
114 }
115
116 bool wxIPV4address::Service(unsigned short port)
117 {
118 return (GAddress_INET_SetPort(m_address, port) == GSOCK_NOERROR);
119 }
120
121 bool wxIPV4address::LocalHost()
122 {
123 return (GAddress_INET_SetHostName(m_address, "localhost") == GSOCK_NOERROR);
124 }
125
126 bool wxIPV4address::AnyAddress()
127 {
128 return (GAddress_INET_SetAnyAddress(m_address) == GSOCK_NOERROR);
129 }
130
131 wxString wxIPV4address::Hostname()
132 {
133 char hostname[1024];
134
135 hostname[0] = 0;
136 GAddress_INET_GetHostName(m_address, hostname, 1024);
137 return wxString(hostname);
138 }
139
140 unsigned short wxIPV4address::Service()
141 {
142 return GAddress_INET_GetPort(m_address);
143 }
144
145 #if 0
146 // ---------------------------------------------------------------------------
147 // wxIPV6address
148 // ---------------------------------------------------------------------------
149
150 wxIPV6address::wxIPV6address()
151 : wxSockAddress()
152 {
153 }
154
155 wxIPV6address::~wxIPV6address()
156 {
157 }
158
159 bool wxIPV6address::Hostname(const wxString& name)
160 {
161 return (GAddress_INET_SetHostName(m_address, name.fn_str()) == GSOCK_NOERROR);
162 }
163
164 bool wxIPV6address::Hostname(unsigned char addr[16])
165 {
166 return TRUE;
167 }
168
169 bool wxIPV6address::Service(const char *name)
170 {
171 return (GAddress_INET_SetPortName(m_address, name.fn_str()) == GSOCK_NOERROR);
172 }
173
174 bool wxIPV6address::Service(unsigned short port)
175 {
176 return (GAddress_INET_SetPort(m_address, port) == GSOCK_NOERROR);
177 }
178
179 bool wxIPV6address::LocalHost()
180 {
181 return (GAddress_INET_SetHostName(m_address, "localhost") == GSOCK_NOERROR);
182 }
183
184 const wxString& wxIPV6address::Hostname()
185 {
186 return wxString(GAddress_INET_GetHostName(m_address));
187 }
188
189 unsigned short wxIPV6address::Service()
190 {
191 return GAddress_INET_GetPort(m_address);
192 }
193
194 #endif
195
196 #if defined(__UNIX__) && !defined(__WXMAC__)
197 // ---------------------------------------------------------------------------
198 // wxUNIXaddress
199 // ---------------------------------------------------------------------------
200
201 wxUNIXaddress::wxUNIXaddress()
202 : wxSockAddress()
203 {
204 }
205
206 wxUNIXaddress::~wxUNIXaddress()
207 {
208 }
209
210 void wxUNIXaddress::Filename(const wxString& fname)
211 {
212 GAddress_UNIX_SetPath(m_address, fname.fn_str());
213 }
214
215 wxString wxUNIXaddress::Filename()
216 {
217 char path[1024];
218
219 path[0] = 0;
220 GAddress_UNIX_GetPath(m_address, path, 1024);
221 return wxString(path);
222 }
223
224 #endif
225
226 #endif
227 // wxUSE_SOCKETS