]>
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>
36 #include <wx/gsocket.h>
37 #include <wx/sckaddr.h>
39 #if !USE_SHARED_LIBRARY
40 IMPLEMENT_ABSTRACT_CLASS(wxSockAddress
, wxObject
)
41 IMPLEMENT_DYNAMIC_CLASS(wxIPV4address
, wxSockAddress
)
43 IMPLEMENT_DYNAMIC_CLASS(wxIPV6address
, wxSockAddress
)
46 IMPLEMENT_DYNAMIC_CLASS(wxUNIXaddress
, wxSockAddress
)
50 // ---------------------------------------------------------------------------
52 // ---------------------------------------------------------------------------
54 wxSockAddress::wxSockAddress()
56 m_address
= GAddress_new();
59 wxSockAddress::~wxSockAddress()
61 GAddress_destroy(m_address
);
64 void wxSockAddress::SetAddress(GAddress
*address
)
66 GAddress_destroy(m_address
);
67 m_address
= GAddress_copy(address
);
70 const wxSockAddress
& wxSockAddress::operator=(const wxSockAddress
& addr
)
72 SetAddress(addr
.GetAddress());
76 void wxSockAddress::CopyObject(wxObject
& dest
) const
78 wxSockAddress
*addr
= (wxSockAddress
*)&dest
;
80 wxObject::CopyObject(dest
);
81 addr
->SetAddress(GetAddress());
84 void wxSockAddress::Clear()
86 GAddress_destroy(m_address
);
87 m_address
= GAddress_new();
90 // ---------------------------------------------------------------------------
92 // ---------------------------------------------------------------------------
94 wxIPV4address::wxIPV4address()
99 wxIPV4address::~wxIPV4address()
103 bool wxIPV4address::Hostname(const wxString
& name
)
105 // Some people are sometimes fool.
106 if (name
== _T("")) {
107 wxLogWarning( _T("Trying to solve a NULL hostname: giving up") );
111 return (GAddress_INET_SetHostName(m_address
, name
.fn_str()) == GSOCK_NOERROR
);
114 bool wxIPV4address::Hostname(unsigned long addr
)
116 return (GAddress_INET_SetHostAddress(m_address
, addr
) == GSOCK_NOERROR
);
119 bool wxIPV4address::Service(const wxString
& name
)
121 return (GAddress_INET_SetPortName(m_address
, name
.fn_str(), "tcp") == GSOCK_NOERROR
);
124 bool wxIPV4address::Service(unsigned short port
)
126 return (GAddress_INET_SetPort(m_address
, port
) == GSOCK_NOERROR
);
129 bool wxIPV4address::LocalHost()
131 return (GAddress_INET_SetHostName(m_address
, "localhost") == GSOCK_NOERROR
);
134 wxString
wxIPV4address::Hostname()
139 GAddress_INET_GetHostName(m_address
, hostname
, 1024);
140 return wxString(hostname
);
143 unsigned short wxIPV4address::Service()
145 return GAddress_INET_GetPort(m_address
);
149 // ---------------------------------------------------------------------------
151 // ---------------------------------------------------------------------------
153 wxIPV6address::wxIPV6address()
158 wxIPV6address::~wxIPV6address()
162 bool wxIPV6address::Hostname(const wxString
& name
)
164 return (GAddress_INET_SetHostName(m_address
, name
.fn_str()) == GSOCK_NOERROR
);
167 bool wxIPV6address::Hostname(unsigned char addr
[16])
172 bool wxIPV6address::Service(const char *name
)
174 return (GAddress_INET_SetPortName(m_address
, name
.fn_str()) == GSOCK_NOERROR
);
177 bool wxIPV6address::Service(unsigned short port
)
179 return (GAddress_INET_SetPort(m_address
, port
) == GSOCK_NOERROR
);
182 bool wxIPV6address::LocalHost()
184 return (GAddress_INET_SetHostName(m_address
, "localhost") == GSOCK_NOERROR
);
187 const wxString
& wxIPV6address::Hostname()
189 return wxString(GAddress_INET_GetHostName(m_address
));
192 unsigned short wxIPV6address::Service()
194 return GAddress_INET_GetPort(m_address
);
200 // ---------------------------------------------------------------------------
202 // ---------------------------------------------------------------------------
204 wxUNIXaddress::wxUNIXaddress()
209 wxUNIXaddress::~wxUNIXaddress()
213 void wxUNIXaddress::Filename(const wxString
& fname
)
215 GAddress_UNIX_SetPath(m_address
, fname
.fn_str());
218 wxString
wxUNIXaddress::Filename()
223 GAddress_UNIX_GetPath(m_address
, path
, 1024);
224 return wxString(path
);