]>
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") );
112 return (GAddress_INET_SetHostName(m_address
, name
.mb_str()) == GSOCK_NOERROR
);
115 bool wxIPV4address::Hostname(unsigned long addr
)
117 return (GAddress_INET_SetHostAddress(m_address
, addr
) == GSOCK_NOERROR
);
120 bool wxIPV4address::Service(const wxString
& name
)
122 return (GAddress_INET_SetPortName(m_address
, name
.mb_str(), "tcp") == GSOCK_NOERROR
);
125 bool wxIPV4address::Service(unsigned short port
)
127 return (GAddress_INET_SetPort(m_address
, port
) == GSOCK_NOERROR
);
130 bool wxIPV4address::LocalHost()
132 return (GAddress_INET_SetHostName(m_address
, "localhost") == GSOCK_NOERROR
);
135 bool wxIPV4address::AnyAddress()
137 return (GAddress_INET_SetAnyAddress(m_address
) == GSOCK_NOERROR
);
140 wxString
wxIPV4address::Hostname()
145 GAddress_INET_GetHostName(m_address
, hostname
, 1024);
146 return wxString(hostname
);
149 unsigned short wxIPV4address::Service()
151 return GAddress_INET_GetPort(m_address
);
155 // ---------------------------------------------------------------------------
157 // ---------------------------------------------------------------------------
159 wxIPV6address::wxIPV6address()
164 wxIPV6address::wxIPV6address(const wxIPV6address
& other
)
165 : wxSockAddress(other
)
169 wxIPV6address::~wxIPV6address()
173 bool wxIPV6address::Hostname(const wxString
& name
)
175 return (GAddress_INET_SetHostName(m_address
, name
.fn_str()) == GSOCK_NOERROR
);
178 bool wxIPV6address::Hostname(unsigned char addr
[16])
183 bool wxIPV6address::Service(const char *name
)
185 return (GAddress_INET_SetPortName(m_address
, name
.fn_str()) == GSOCK_NOERROR
);
188 bool wxIPV6address::Service(unsigned short port
)
190 return (GAddress_INET_SetPort(m_address
, port
) == GSOCK_NOERROR
);
193 bool wxIPV6address::LocalHost()
195 return (GAddress_INET_SetHostName(m_address
, "localhost") == GSOCK_NOERROR
);
198 const wxString
& wxIPV6address::Hostname()
200 return wxString(GAddress_INET_GetHostName(m_address
));
203 unsigned short wxIPV6address::Service()
205 return GAddress_INET_GetPort(m_address
);
210 #if defined(__UNIX__) && !defined(__WXMAC__)
212 // ---------------------------------------------------------------------------
214 // ---------------------------------------------------------------------------
216 wxUNIXaddress::wxUNIXaddress()
221 wxUNIXaddress::wxUNIXaddress(const wxUNIXaddress
& other
)
222 : wxSockAddress(other
)
226 wxUNIXaddress::~wxUNIXaddress()
230 void wxUNIXaddress::Filename(const wxString
& fname
)
232 GAddress_UNIX_SetPath(m_address
, fname
.fn_str());
235 wxString
wxUNIXaddress::Filename()
240 GAddress_UNIX_GetPath(m_address
, path
, 1024);
241 return wxString(path
);