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