/* * tcpip_endpoint.cpp * * Created on: 26.03.2013 * Author: mario */ #include "tcpip_endpoint.hpp" // system #include #include using namespace std; using namespace boost::asio::ip; namespace ariba { namespace addressing2 { #define TCPIPv6_SIZE 18 #define TCPIPv4_SIZE 6 /// factories TcpIP_EndpointPtr tcpip_endpoint::create_TcpIP_Endpoint( const tcp::endpoint& asio_endpoint) { TcpIP_EndpointPtr ptr(new tcpip_endpoint(asio_endpoint)); return ptr; } /// constructors tcpip_endpoint::tcpip_endpoint(const std::string& ip_addr, const int port) { address addr = address::from_string(ip_addr); asio_endpoint = tcp::endpoint(addr, static_cast(port)); } tcpip_endpoint::tcpip_endpoint(const ENDPOINT_TYPE type, const uint8_t* const byte_array, const int read_max) { // IPv4 if ( type == endpoint_type::TCPIPv4 ) { // boundary check if ( read_max < TCPIPv4_SIZE ) throw invalid_argument("Not enough bytes to read an TCPIPv4 endpoint."); asio_endpoint = tcp::endpoint( address_v4( *((uint32_t*) byte_array) ), *((uint16_t*) (byte_array+sizeof(uint32_t))) ); } // IPv6 else if ( type == endpoint_type::TCPIPv6 ) { // boundary check if ( read_max < TCPIPv6_SIZE ) throw invalid_argument("Not enough bytes to read an TCPIPv6 endpoint."); address_v6::bytes_type bytes_; for (size_t i=0; iasio_endpoint; } }} /* namespace ariba::addressing2 */