]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/common/sckaddr.cpp
1. added wxGetNumberFromUser (to textdlgg.cpp and dialogs sample)
[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/gsocket.h>
36#include <wx/sckaddr.h>
37
38#if !USE_SHARED_LIBRARY
39IMPLEMENT_ABSTRACT_CLASS(wxSockAddress, wxObject)
40IMPLEMENT_DYNAMIC_CLASS(wxIPV4address, wxSockAddress)
41#ifdef ENABLE_IPV6
42IMPLEMENT_DYNAMIC_CLASS(wxIPV6address, wxSockAddress)
43#endif
44#ifdef __UNIX__
45IMPLEMENT_DYNAMIC_CLASS(wxUNIXaddress, wxSockAddress)
46#endif
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 return (GAddress_INET_SetHostName(m_address, name.fn_str()) == GSOCK_NOERROR);
105}
106
107bool wxIPV4address::Hostname(unsigned long addr)
108{
109 /* Need API */
110 return TRUE;
111}
112
113bool wxIPV4address::Service(const wxString& name)
114{
115 return (GAddress_INET_SetPortName(m_address, name.fn_str()) == GSOCK_NOERROR);
116}
117
118bool wxIPV4address::Service(unsigned short port)
119{
120 return (GAddress_INET_SetPort(m_address, port) == GSOCK_NOERROR);
121}
122
123bool wxIPV4address::LocalHost()
124{
125 return (GAddress_INET_SetHostName(m_address, "localhost") == GSOCK_NOERROR);
126}
127
128wxString wxIPV4address::Hostname()
129{
130 char hostname[1024];
131
132 hostname[0] = 0;
133 GAddress_INET_GetHostName(m_address, hostname, 1024);
134 return wxString(hostname);
135}
136
137unsigned short wxIPV4address::Service()
138{
139 return GAddress_INET_GetPort(m_address);
140}
141
142#ifdef IPV6_ENABLE
143// ---------------------------------------------------------------------------
144// wxIPV6address
145// ---------------------------------------------------------------------------
146
147wxIPV6address::wxIPV6address()
148 : wxSockAddress()
149{
150}
151
152wxIPV6address::~wxIPV6address()
153{
154}
155
156bool wxIPV6address::Hostname(const wxString& name)
157{
158 return (GAddress_INET_SetHostName(m_address, name.fn_str()) == GSOCK_NOERROR);
159}
160
161bool wxIPV6address::Hostname(unsigned char addr[16])
162{
163 return TRUE;
164}
165
166bool wxIPV6address::Service(const char *name)
167{
168 return (GAddress_INET_SetPortName(m_address, name.fn_str()) == GSOCK_NOERROR);
169}
170
171bool wxIPV6address::Service(unsigned short port)
172{
173 return (GAddress_INET_SetPort(m_address, port) == GSOCK_NOERROR);
174}
175
176bool wxIPV6address::LocalHost()
177{
178 return (GAddress_INET_SetHostName(m_address, "localhost") == GSOCK_NOERROR);
179}
180
181const wxString& wxIPV6address::Hostname()
182{
183 return wxString(GAddress_INET_GetHostName(m_address));
184}
185
186unsigned short wxIPV6address::Service()
187{
188 return GAddress_INET_GetPort(m_address);
189}
190
191#endif
192
193#ifdef __UNIX__
194// ---------------------------------------------------------------------------
195// wxUNIXaddress
196// ---------------------------------------------------------------------------
197
198wxUNIXaddress::wxUNIXaddress()
199 : wxSockAddress()
200{
201}
202
203wxUNIXaddress::~wxUNIXaddress()
204{
205}
206
207void wxUNIXaddress::Filename(const wxString& fname)
208{
209 GAddress_UNIX_SetPath(m_address, fname.fn_str());
210}
211
212wxString wxUNIXaddress::Filename()
213{
214 char path[1024];
215
216 path[0] = 0;
217 GAddress_UNIX_GetPath(m_address, path, 1024);
218 return wxString(path);
219}
220
221#endif
222
223#endif
224 // wxUSE_SOCKETS