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