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