summaryrefslogtreecommitdiff
path: root/src/packetSource.cpp
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2009-03-05 23:47:47 +0000
committerChristian Pointner <equinox@anytun.org>2009-03-05 23:47:47 +0000
commit74f2885ade3fb44784e1fbc2fd0575f69728077c (patch)
tree6f4df7db14f646d277fe3853b887711d976c2230 /src/packetSource.cpp
parentfixed daemonizing and boost::thread problem (workaround) (diff)
changed packetSource to use gResolver
Diffstat (limited to 'src/packetSource.cpp')
-rw-r--r--src/packetSource.cpp28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/packetSource.cpp b/src/packetSource.cpp
index 2541894..5542ee9 100644
--- a/src/packetSource.cpp
+++ b/src/packetSource.cpp
@@ -30,29 +30,35 @@
*/
#include <boost/asio.hpp>
+#include <boost/bind.hpp>
#include "datatypes.h"
#include "packetSource.h"
#include "log.h"
+#include "resolver.h"
+#include "options.h"
+
+void PacketSource::waitUntilReady()
+{
+ ready_sem_.down();
+}
UDPPacketSource::UDPPacketSource(std::string port) : sock_(io_service_)
{
- proto::resolver resolver(io_service_);
- proto::resolver::query query(port);
- proto::endpoint e = *resolver.resolve(query);
- cLog.msg(Log::PRIO_NOTICE) << "openeing socket: " << e;
- sock_.open(e.protocol());
- sock_.bind(e);
+ gResolver.resolveUdp("", port, boost::bind(&UDPPacketSource::onResolve, this, _1), gOpt.getResolvAddrType());
}
UDPPacketSource::UDPPacketSource(std::string localaddr, std::string port) : sock_(io_service_)
{
- proto::resolver resolver(io_service_);
- proto::resolver::query query(localaddr, port);
- proto::endpoint e = *resolver.resolve(query);
- cLog.msg(Log::PRIO_NOTICE) << "openeing socket: " << e;
+ gResolver.resolveUdp(localaddr, port, boost::bind(&UDPPacketSource::onResolve, this, _1), gOpt.getResolvAddrType());
+}
+
+void UDPPacketSource::onResolve(const boost::asio::ip::udp::endpoint& e)
+{
+ cLog.msg(Log::PRIO_NOTICE) << "opening socket: " << e;
sock_.open(e.protocol());
- sock_.bind(e);
+ sock_.bind(e);
+ ready_sem_.up();
}
u_int32_t UDPPacketSource::recv(u_int8_t* buf, u_int32_t len, PacketSourceEndpoint& remote)