]> git.saurik.com Git - wxWidgets.git/blame - src/common/sckaddr.cpp
1. wxWizard supports setting images for each page, sample updated to show it
[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
45#ifdef __UNIX__
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
a324a7bc 111 return (GAddress_INET_SetHostName(m_address, name.fn_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{
5a96d2f4 121 return (GAddress_INET_SetPortName(m_address, name.fn_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
134wxString wxIPV4address::Hostname()
135{
a324a7bc 136 char hostname[1024];
f4ada568 137
a324a7bc
GL
138 hostname[0] = 0;
139 GAddress_INET_GetHostName(m_address, hostname, 1024);
140 return wxString(hostname);
f4ada568
GL
141}
142
a324a7bc 143unsigned short wxIPV4address::Service()
f4ada568 144{
a324a7bc 145 return GAddress_INET_GetPort(m_address);
f4ada568
GL
146}
147
5a96d2f4 148#if 0
a324a7bc
GL
149// ---------------------------------------------------------------------------
150// wxIPV6address
151// ---------------------------------------------------------------------------
f4ada568
GL
152
153wxIPV6address::wxIPV6address()
a324a7bc 154 : wxSockAddress()
f4ada568 155{
f4ada568
GL
156}
157
158wxIPV6address::~wxIPV6address()
159{
160}
161
f4ada568
GL
162bool wxIPV6address::Hostname(const wxString& name)
163{
a324a7bc 164 return (GAddress_INET_SetHostName(m_address, name.fn_str()) == GSOCK_NOERROR);
f4ada568
GL
165}
166
167bool wxIPV6address::Hostname(unsigned char addr[16])
168{
f4ada568
GL
169 return TRUE;
170}
171
172bool wxIPV6address::Service(const char *name)
173{
a324a7bc 174 return (GAddress_INET_SetPortName(m_address, name.fn_str()) == GSOCK_NOERROR);
f4ada568
GL
175}
176
177bool wxIPV6address::Service(unsigned short port)
178{
a324a7bc 179 return (GAddress_INET_SetPort(m_address, port) == GSOCK_NOERROR);
f4ada568
GL
180}
181
182bool wxIPV6address::LocalHost()
183{
a324a7bc 184 return (GAddress_INET_SetHostName(m_address, "localhost") == GSOCK_NOERROR);
f4ada568
GL
185}
186
187const wxString& wxIPV6address::Hostname()
188{
a324a7bc 189 return wxString(GAddress_INET_GetHostName(m_address));
f4ada568
GL
190}
191
192unsigned short wxIPV6address::Service()
193{
a324a7bc 194 return GAddress_INET_GetPort(m_address);
f4ada568
GL
195}
196
197#endif
198
199#ifdef __UNIX__
a324a7bc
GL
200// ---------------------------------------------------------------------------
201// wxUNIXaddress
202// ---------------------------------------------------------------------------
f4ada568
GL
203
204wxUNIXaddress::wxUNIXaddress()
a324a7bc 205 : wxSockAddress()
f4ada568 206{
f4ada568
GL
207}
208
209wxUNIXaddress::~wxUNIXaddress()
210{
211}
212
f4ada568
GL
213void wxUNIXaddress::Filename(const wxString& fname)
214{
a324a7bc 215 GAddress_UNIX_SetPath(m_address, fname.fn_str());
f4ada568
GL
216}
217
218wxString wxUNIXaddress::Filename()
219{
a324a7bc 220 char path[1024];
f4ada568 221
a324a7bc
GL
222 path[0] = 0;
223 GAddress_UNIX_GetPath(m_address, path, 1024);
224 return wxString(path);
f4ada568
GL
225}
226
f4ada568 227#endif
35a4dab7
GL
228
229#endif
230 // wxUSE_SOCKETS