]>
git.saurik.com Git - wxWidgets.git/blob - src/common/sckaddr.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Network address manager
4 // Author: Guilhem Lavaux
8 // Copyright: (c) 1997, 1998 Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "sckaddr.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
29 #if !defined(__MWERKS__) && !defined(__SALFORDC__)
34 #include "wx/object.h"
37 #include "wx/gsocket.h"
38 #include "wx/sckaddr.h"
40 IMPLEMENT_ABSTRACT_CLASS(wxSockAddress
, wxObject
)
41 IMPLEMENT_DYNAMIC_CLASS(wxIPV4address
, wxSockAddress
)
43 IMPLEMENT_DYNAMIC_CLASS(wxIPV6address
, wxSockAddress
)
45 #if defined(__UNIX__) && !defined(__WXMAC__)
46 IMPLEMENT_DYNAMIC_CLASS(wxUNIXaddress
, wxSockAddress
)
49 // ---------------------------------------------------------------------------
51 // ---------------------------------------------------------------------------
53 wxSockAddress::wxSockAddress()
55 m_address
= GAddress_new();
58 wxSockAddress::wxSockAddress(const wxSockAddress
& other
)
60 m_address
= GAddress_copy(other
.m_address
);
63 wxSockAddress::~wxSockAddress()
65 GAddress_destroy(m_address
);
68 void wxSockAddress::SetAddress(GAddress
*address
)
70 GAddress_destroy(m_address
);
71 m_address
= GAddress_copy(address
);
74 wxSockAddress
& wxSockAddress::operator=(const wxSockAddress
& addr
)
76 SetAddress(addr
.GetAddress());
80 void wxSockAddress::Clear()
82 GAddress_destroy(m_address
);
83 m_address
= GAddress_new();
86 // ---------------------------------------------------------------------------
88 // ---------------------------------------------------------------------------
90 wxIPV4address::wxIPV4address()
94 wxIPV4address::wxIPV4address(const wxIPV4address
& other
)
95 : wxSockAddress(other
)
99 wxIPV4address::~wxIPV4address()
103 bool wxIPV4address::Hostname(const wxString
& name
)
105 // Some people are sometimes fool.
108 wxLogWarning( _("Trying to solve a NULL hostname: giving up") );
111 m_origHostname
= name
;
112 return (GAddress_INET_SetHostName(m_address
, name
.mb_str()) == GSOCK_NOERROR
);
115 bool wxIPV4address::Hostname(unsigned long addr
)
117 bool rv
= (GAddress_INET_SetHostAddress(m_address
, addr
) == GSOCK_NOERROR
);
119 m_origHostname
= Hostname();
125 bool wxIPV4address::Service(const wxString
& name
)
127 return (GAddress_INET_SetPortName(m_address
, name
.mb_str(), "tcp") == GSOCK_NOERROR
);
130 bool wxIPV4address::Service(unsigned short port
)
132 return (GAddress_INET_SetPort(m_address
, port
) == GSOCK_NOERROR
);
135 bool wxIPV4address::LocalHost()
137 return (GAddress_INET_SetHostName(m_address
, "localhost") == GSOCK_NOERROR
);
140 bool wxIPV4address::AnyAddress()
142 return (GAddress_INET_SetAnyAddress(m_address
) == GSOCK_NOERROR
);
145 wxString
wxIPV4address::Hostname()
150 GAddress_INET_GetHostName(m_address
, hostname
, 1024);
151 return wxString(hostname
);
154 unsigned short wxIPV4address::Service()
156 return GAddress_INET_GetPort(m_address
);
159 wxSockAddress
*wxIPV4address::Clone() const
161 wxIPV4address
*addr
= new wxIPV4address(*this);
162 addr
->m_origHostname
= m_origHostname
;
167 // ---------------------------------------------------------------------------
169 // ---------------------------------------------------------------------------
171 wxIPV6address::wxIPV6address()
176 wxIPV6address::wxIPV6address(const wxIPV6address
& other
)
177 : wxSockAddress(other
)
181 wxIPV6address::~wxIPV6address()
185 bool wxIPV6address::Hostname(const wxString
& name
)
187 return (GAddress_INET_SetHostName(m_address
, name
.fn_str()) == GSOCK_NOERROR
);
190 bool wxIPV6address::Hostname(unsigned char addr
[16])
195 bool wxIPV6address::Service(const char *name
)
197 return (GAddress_INET_SetPortName(m_address
, name
.fn_str()) == GSOCK_NOERROR
);
200 bool wxIPV6address::Service(unsigned short port
)
202 return (GAddress_INET_SetPort(m_address
, port
) == GSOCK_NOERROR
);
205 bool wxIPV6address::LocalHost()
207 return (GAddress_INET_SetHostName(m_address
, "localhost") == GSOCK_NOERROR
);
210 const wxString
& wxIPV6address::Hostname()
212 return wxString(GAddress_INET_GetHostName(m_address
));
215 unsigned short wxIPV6address::Service()
217 return GAddress_INET_GetPort(m_address
);
222 #if defined(__UNIX__) && !defined(__WXMAC__)
224 // ---------------------------------------------------------------------------
226 // ---------------------------------------------------------------------------
228 wxUNIXaddress::wxUNIXaddress()
233 wxUNIXaddress::wxUNIXaddress(const wxUNIXaddress
& other
)
234 : wxSockAddress(other
)
238 wxUNIXaddress::~wxUNIXaddress()
242 void wxUNIXaddress::Filename(const wxString
& fname
)
244 GAddress_UNIX_SetPath(m_address
, fname
.fn_str());
247 wxString
wxUNIXaddress::Filename()
252 GAddress_UNIX_GetPath(m_address
, path
, 1024);
253 return wxString(path
);