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