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