diff options
author | Christian Pointner <equinox@anytun.org> | 2008-11-24 20:52:38 +0000 |
---|---|---|
committer | Christian Pointner <equinox@anytun.org> | 2008-11-24 20:52:38 +0000 |
commit | 84f11351fe5ab9fb2e8c7b7caecb4c7b5a26b595 (patch) | |
tree | cbbecc42f3f51b73dac3ac4c7fe9e99f8019d89e /src/packetSource.cpp | |
parent | ports int -> string (diff) |
PacketSource changed to use endpoint instead of port and address
Diffstat (limited to 'src/packetSource.cpp')
-rw-r--r-- | src/packetSource.cpp | 36 |
1 files changed, 8 insertions, 28 deletions
diff --git a/src/packetSource.cpp b/src/packetSource.cpp index b144e8c..ee8951e 100644 --- a/src/packetSource.cpp +++ b/src/packetSource.cpp @@ -30,56 +30,36 @@ */ #include <boost/asio.hpp> -#include <sstream> #include "datatypes.h" #include "packetSource.h" #include "buffer.h" -UDPPacketSource::UDPPacketSource(u_int16_t port) : sock_(io_service_) +UDPPacketSource::UDPPacketSource(std::string port) : sock_(io_service_) { - std::stringstream ps; - ps << port; - boost::asio::ip::udp::resolver resolver(io_service_); - boost::asio::ip::udp::resolver::query query(ps.str()); + boost::asio::ip::udp::resolver::query query(port); boost::asio::ip::udp::endpoint e = *resolver.resolve(query); sock_.open(e.protocol()); sock_.bind(e); } -UDPPacketSource::UDPPacketSource(std::string localaddr, u_int16_t port) : sock_(io_service_) +UDPPacketSource::UDPPacketSource(std::string localaddr, std::string port) : sock_(io_service_) { - std::stringstream ps; - ps << port; - boost::asio::ip::udp::resolver resolver(io_service_); - boost::asio::ip::udp::resolver::query query(localaddr, ps.str()); + boost::asio::ip::udp::resolver::query query(localaddr, port); boost::asio::ip::udp::endpoint e = *resolver.resolve(query); sock_.open(e.protocol()); sock_.bind(e); } -u_int32_t UDPPacketSource::recv(u_int8_t* buf, u_int32_t len, std::string& addr, u_int16_t &port) +u_int32_t UDPPacketSource::recv(u_int8_t* buf, u_int32_t len, PacketSourceEndpoint& remote) { - boost::asio::ip::udp::endpoint e; - u_int32_t rtn = sock_.receive_from(boost::asio::buffer(buf, len), e); - - addr = e.address().to_string(); - port = e.port(); - - return rtn; + return sock_.receive_from(boost::asio::buffer(buf, len), remote); } -void UDPPacketSource::send(u_int8_t* buf, u_int32_t len, std::string addr, u_int16_t port) +void UDPPacketSource::send(u_int8_t* buf, u_int32_t len, PacketSourceEndpoint remote) { - std::stringstream ps; - ps << port; - - boost::asio::ip::udp::resolver resolver(io_service_); - boost::asio::ip::udp::resolver::query query(addr, ps.str()); - boost::asio::ip::udp::endpoint e = *resolver.resolve(query); - - sock_.send_to(boost::asio::buffer(buf, len), e); + sock_.send_to(boost::asio::buffer(buf, len), remote); } |