]>
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()
60 GAddress_destroy(m_address
);
63 void wxSockAddress::SetAddress(GAddress
*address
)
65 GAddress_destroy(m_address
);
66 m_address
= GAddress_copy(address
);
69 const wxSockAddress
& wxSockAddress::operator=(const wxSockAddress
& addr
)
71 SetAddress(addr
.GetAddress());
75 void wxSockAddress::Clear()
77 GAddress_destroy(m_address
);
78 m_address
= GAddress_new();
81 // ---------------------------------------------------------------------------
83 // ---------------------------------------------------------------------------
85 wxIPV4address::wxIPV4address()
90 wxIPV4address::~wxIPV4address()
94 bool wxIPV4address::Hostname(const wxString
& name
)
96 // Some people are sometimes fool.
99 wxLogWarning( _("Trying to solve a NULL hostname: giving up") );
103 return (GAddress_INET_SetHostName(m_address
, name
.mb_str()) == GSOCK_NOERROR
);
106 bool wxIPV4address::Hostname(unsigned long addr
)
108 return (GAddress_INET_SetHostAddress(m_address
, addr
) == GSOCK_NOERROR
);
111 bool wxIPV4address::Service(const wxString
& name
)
113 return (GAddress_INET_SetPortName(m_address
, name
.mb_str(), "tcp") == GSOCK_NOERROR
);
116 bool wxIPV4address::Service(unsigned short port
)
118 return (GAddress_INET_SetPort(m_address
, port
) == GSOCK_NOERROR
);
121 bool wxIPV4address::LocalHost()
123 return (GAddress_INET_SetHostName(m_address
, "localhost") == GSOCK_NOERROR
);
126 bool wxIPV4address::AnyAddress()
128 return (GAddress_INET_SetAnyAddress(m_address
) == GSOCK_NOERROR
);
131 wxString
wxIPV4address::Hostname()
136 GAddress_INET_GetHostName(m_address
, hostname
, 1024);
137 return wxString(hostname
);
140 unsigned short wxIPV4address::Service()
142 return GAddress_INET_GetPort(m_address
);
146 // ---------------------------------------------------------------------------
148 // ---------------------------------------------------------------------------
150 wxIPV6address::wxIPV6address()
155 wxIPV6address::~wxIPV6address()
159 bool wxIPV6address::Hostname(const wxString
& name
)
161 return (GAddress_INET_SetHostName(m_address
, name
.fn_str()) == GSOCK_NOERROR
);
164 bool wxIPV6address::Hostname(unsigned char addr
[16])
169 bool wxIPV6address::Service(const char *name
)
171 return (GAddress_INET_SetPortName(m_address
, name
.fn_str()) == GSOCK_NOERROR
);
174 bool wxIPV6address::Service(unsigned short port
)
176 return (GAddress_INET_SetPort(m_address
, port
) == GSOCK_NOERROR
);
179 bool wxIPV6address::LocalHost()
181 return (GAddress_INET_SetHostName(m_address
, "localhost") == GSOCK_NOERROR
);
184 const wxString
& wxIPV6address::Hostname()
186 return wxString(GAddress_INET_GetHostName(m_address
));
189 unsigned short wxIPV6address::Service()
191 return GAddress_INET_GetPort(m_address
);
196 #if defined(__UNIX__) && !defined(__WXMAC__)
197 // ---------------------------------------------------------------------------
199 // ---------------------------------------------------------------------------
201 wxUNIXaddress::wxUNIXaddress()
206 wxUNIXaddress::~wxUNIXaddress()
210 void wxUNIXaddress::Filename(const wxString
& fname
)
212 GAddress_UNIX_SetPath(m_address
, fname
.fn_str());
215 wxString
wxUNIXaddress::Filename()
220 GAddress_UNIX_GetPath(m_address
, path
, 1024);
221 return wxString(path
);