]>
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 #if !USE_SHARED_LIBRARY
41 IMPLEMENT_ABSTRACT_CLASS(wxSockAddress
, wxObject
)
42 IMPLEMENT_DYNAMIC_CLASS(wxIPV4address
, wxSockAddress
)
44 IMPLEMENT_DYNAMIC_CLASS(wxIPV6address
, wxSockAddress
)
47 IMPLEMENT_DYNAMIC_CLASS(wxUNIXaddress
, wxSockAddress
)
51 // ---------------------------------------------------------------------------
53 // ---------------------------------------------------------------------------
55 wxSockAddress::wxSockAddress()
57 m_address
= GAddress_new();
60 wxSockAddress::~wxSockAddress()
62 GAddress_destroy(m_address
);
65 void wxSockAddress::SetAddress(GAddress
*address
)
67 GAddress_destroy(m_address
);
68 m_address
= GAddress_copy(address
);
71 const wxSockAddress
& wxSockAddress::operator=(const wxSockAddress
& addr
)
73 SetAddress(addr
.GetAddress());
77 void wxSockAddress::CopyObject(wxObject
& dest
) const
79 wxSockAddress
*addr
= (wxSockAddress
*)&dest
;
81 wxObject::CopyObject(dest
);
82 addr
->SetAddress(GetAddress());
85 void wxSockAddress::Clear()
87 GAddress_destroy(m_address
);
88 m_address
= GAddress_new();
91 // ---------------------------------------------------------------------------
93 // ---------------------------------------------------------------------------
95 wxIPV4address::wxIPV4address()
100 wxIPV4address::~wxIPV4address()
104 bool wxIPV4address::Hostname(const wxString
& name
)
106 // Some people are sometimes fool.
109 wxLogWarning( _("Trying to solve a NULL hostname: giving up") );
113 return (GAddress_INET_SetHostName(m_address
, name
.fn_str()) == GSOCK_NOERROR
);
116 bool wxIPV4address::Hostname(unsigned long addr
)
118 return (GAddress_INET_SetHostAddress(m_address
, addr
) == GSOCK_NOERROR
);
121 bool wxIPV4address::Service(const wxString
& name
)
123 return (GAddress_INET_SetPortName(m_address
, name
.fn_str(), "tcp") == GSOCK_NOERROR
);
126 bool wxIPV4address::Service(unsigned short port
)
128 return (GAddress_INET_SetPort(m_address
, port
) == GSOCK_NOERROR
);
131 bool wxIPV4address::LocalHost()
133 return (GAddress_INET_SetHostName(m_address
, "localhost") == GSOCK_NOERROR
);
136 wxString
wxIPV4address::Hostname()
141 GAddress_INET_GetHostName(m_address
, hostname
, 1024);
142 return wxString(hostname
);
145 unsigned short wxIPV4address::Service()
147 return GAddress_INET_GetPort(m_address
);
151 // ---------------------------------------------------------------------------
153 // ---------------------------------------------------------------------------
155 wxIPV6address::wxIPV6address()
160 wxIPV6address::~wxIPV6address()
164 bool wxIPV6address::Hostname(const wxString
& name
)
166 return (GAddress_INET_SetHostName(m_address
, name
.fn_str()) == GSOCK_NOERROR
);
169 bool wxIPV6address::Hostname(unsigned char addr
[16])
174 bool wxIPV6address::Service(const char *name
)
176 return (GAddress_INET_SetPortName(m_address
, name
.fn_str()) == GSOCK_NOERROR
);
179 bool wxIPV6address::Service(unsigned short port
)
181 return (GAddress_INET_SetPort(m_address
, port
) == GSOCK_NOERROR
);
184 bool wxIPV6address::LocalHost()
186 return (GAddress_INET_SetHostName(m_address
, "localhost") == GSOCK_NOERROR
);
189 const wxString
& wxIPV6address::Hostname()
191 return wxString(GAddress_INET_GetHostName(m_address
));
194 unsigned short wxIPV6address::Service()
196 return GAddress_INET_GetPort(m_address
);
202 // ---------------------------------------------------------------------------
204 // ---------------------------------------------------------------------------
206 wxUNIXaddress::wxUNIXaddress()
211 wxUNIXaddress::~wxUNIXaddress()
215 void wxUNIXaddress::Filename(const wxString
& fname
)
217 GAddress_UNIX_SetPath(m_address
, fname
.fn_str());
220 wxString
wxUNIXaddress::Filename()
225 GAddress_UNIX_GetPath(m_address
, path
, 1024);
226 return wxString(path
);