2 // This file is part of the aMule Project.
4 // Copyright (c) 2004-2011 Stu Redman ( sturedman@amule.org )
5 // Copyright (c) 2004-2011 aMule Team ( admin@amule.org / http://www.amule.org )
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 // Implementation of amuleIPV4Address for wxWidgets sockets
28 // (Implementation for Asio is in LibSocketAsio.cpp
31 #include "LibSocket.h"
33 #include "amuleIPV4Address.h"
36 class CamuleIPV4Endpoint
: public wxIPV4address
{
38 CamuleIPV4Endpoint() {}
40 CamuleIPV4Endpoint(const CamuleIPV4Endpoint
& impl
) : wxIPV4address(impl
) {}
42 /// operator wxSockAddress& () { return * this; }
47 bool CLibSocket::Connect(amuleIPV4Address
& adr
, bool wait
)
49 return wxSocketClient::Connect(adr
.GetEndpoint(), wait
);
52 bool CLibSocket::GetPeer(amuleIPV4Address
& adr
)
54 return wxSocketClient::GetPeer(adr
.GetEndpoint());
57 void CLibSocket::SetLocal(amuleIPV4Address
& local
)
59 wxSocketClient::SetLocal(local
.GetEndpoint());
63 CLibSocketServer::CLibSocketServer(const amuleIPV4Address
&address
, wxSocketFlags flags
) : wxSocketServer(address
.GetEndpoint(), flags
)
67 CLibUDPSocket::CLibUDPSocket(amuleIPV4Address
&address
, wxSocketFlags flags
) : wxDatagramSocket(address
.GetEndpoint(), flags
)
71 uint32
CLibUDPSocket::RecvFrom(amuleIPV4Address
& addr
, void* buf
, uint32 nBytes
)
73 wxDatagramSocket::RecvFrom(addr
.GetEndpoint(), buf
, nBytes
);
74 return wxDatagramSocket::LastCount();
77 uint32
CLibUDPSocket::SendTo(const amuleIPV4Address
& addr
, const void* buf
, uint32 nBytes
)
79 wxDatagramSocket::SendTo(addr
.GetEndpoint(), buf
, nBytes
);
80 return wxDatagramSocket::LastCount();
84 amuleIPV4Address::amuleIPV4Address()
86 m_endpoint
= new CamuleIPV4Endpoint();
89 amuleIPV4Address::amuleIPV4Address(const amuleIPV4Address
&a
)
94 amuleIPV4Address::~amuleIPV4Address()
99 amuleIPV4Address
& amuleIPV4Address::operator=(const amuleIPV4Address
&a
)
101 m_endpoint
= new CamuleIPV4Endpoint(* a
.m_endpoint
);
105 bool amuleIPV4Address::Hostname(const wxString
& name
)
107 if (name
.IsEmpty()) {
110 return m_endpoint
->Hostname(name
);
113 bool amuleIPV4Address::Service(uint16 service
)
118 return m_endpoint
->Service(service
);
121 uint16
amuleIPV4Address::Service() const
123 return m_endpoint
->Service();
126 bool amuleIPV4Address::IsLocalHost() const
128 return m_endpoint
->IsLocalHost();
131 wxString
amuleIPV4Address::IPAddress() const
133 return m_endpoint
->IPAddress();
136 // Set address to any of the addresses of the current machine.
137 bool amuleIPV4Address::AnyAddress()
139 bool ret
= m_endpoint
->AnyAddress();
140 AddDebugLogLineN(logGeneral
, CFormat(wxT("AnyAddress() returned %s")) % IPAddress());
144 const CamuleIPV4Endpoint
& amuleIPV4Address::GetEndpoint() const
149 CamuleIPV4Endpoint
& amuleIPV4Address::GetEndpoint()