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