]>
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>
35 #include <wx/gsocket.h>
36 #include <wx/sckaddr.h>
38 #if !USE_SHARED_LIBRARY
39 IMPLEMENT_ABSTRACT_CLASS(wxSockAddress
, wxObject
)
40 IMPLEMENT_DYNAMIC_CLASS(wxIPV4address
, wxSockAddress
)
42 IMPLEMENT_DYNAMIC_CLASS(wxIPV6address
, wxSockAddress
)
45 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::CopyObject(wxObject
& dest
) const
77 wxSockAddress
*addr
= (wxSockAddress
*)&dest
;
79 wxObject::CopyObject(dest
);
80 addr
->SetAddress(GetAddress());
83 void wxSockAddress::Clear()
85 GAddress_destroy(m_address
);
86 m_address
= GAddress_new();
89 // ---------------------------------------------------------------------------
91 // ---------------------------------------------------------------------------
93 wxIPV4address::wxIPV4address()
98 wxIPV4address::~wxIPV4address()
102 bool wxIPV4address::Hostname(const wxString
& name
)
104 return (GAddress_INET_SetHostName(m_address
, name
.fn_str()) == GSOCK_NOERROR
);
107 bool wxIPV4address::Hostname(unsigned long addr
)
109 return (GAddress_INET_SetHostAddress(m_address
, addr
) == GSOCK_NOERROR
);
112 bool wxIPV4address::Service(const wxString
& name
)
114 return (GAddress_INET_SetPortName(m_address
, name
.fn_str(), "tcp") == GSOCK_NOERROR
);
117 bool wxIPV4address::Service(unsigned short port
)
119 return (GAddress_INET_SetPort(m_address
, port
) == GSOCK_NOERROR
);
122 bool wxIPV4address::LocalHost()
124 return (GAddress_INET_SetHostName(m_address
, "localhost") == GSOCK_NOERROR
);
127 wxString
wxIPV4address::Hostname()
132 GAddress_INET_GetHostName(m_address
, hostname
, 1024);
133 return wxString(hostname
);
136 unsigned short wxIPV4address::Service()
138 return GAddress_INET_GetPort(m_address
);
142 // ---------------------------------------------------------------------------
144 // ---------------------------------------------------------------------------
146 wxIPV6address::wxIPV6address()
151 wxIPV6address::~wxIPV6address()
155 bool wxIPV6address::Hostname(const wxString
& name
)
157 return (GAddress_INET_SetHostName(m_address
, name
.fn_str()) == GSOCK_NOERROR
);
160 bool wxIPV6address::Hostname(unsigned char addr
[16])
165 bool wxIPV6address::Service(const char *name
)
167 return (GAddress_INET_SetPortName(m_address
, name
.fn_str()) == GSOCK_NOERROR
);
170 bool wxIPV6address::Service(unsigned short port
)
172 return (GAddress_INET_SetPort(m_address
, port
) == GSOCK_NOERROR
);
175 bool wxIPV6address::LocalHost()
177 return (GAddress_INET_SetHostName(m_address
, "localhost") == GSOCK_NOERROR
);
180 const wxString
& wxIPV6address::Hostname()
182 return wxString(GAddress_INET_GetHostName(m_address
));
185 unsigned short wxIPV6address::Service()
187 return GAddress_INET_GetPort(m_address
);
193 // ---------------------------------------------------------------------------
195 // ---------------------------------------------------------------------------
197 wxUNIXaddress::wxUNIXaddress()
202 wxUNIXaddress::~wxUNIXaddress()
206 void wxUNIXaddress::Filename(const wxString
& fname
)
208 GAddress_UNIX_SetPath(m_address
, fname
.fn_str());
211 wxString
wxUNIXaddress::Filename()
216 GAddress_UNIX_GetPath(m_address
, path
, 1024);
217 return wxString(path
);