3 * @brief endpoint serialize helper class
5 * L7VSD: Linux Virtual Server for Layer7 Load Balancing
6 * Copyright (C) 2009 NTT COMWARE Corporation.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
23 **********************************************************************/
28 #include <boost/serialization/nvp.hpp>
29 #include <boost/serialization/split_free.hpp>
32 namespace serialization {
34 template<class Archive, class T>
35 inline void serialize(
37 boost::asio::ip::basic_endpoint<T> & t,
38 const unsigned int file_version
40 boost::serialization::split_free( ar, t, file_version );
43 template<class Archive, class T>
46 boost::asio::ip::basic_endpoint<T> const& t,
47 const unsigned int /* file_version */
49 std::string addr = t.address().to_string();
50 unsigned short port = t.port();
51 unsigned long scope_id = 0;
52 if( addr.find_first_of( "%" ) != std::string::npos ){
53 std::string addr_ = addr.substr( 0, addr.find_first_of( "%" ) );
54 std::string ifname = addr.substr( addr.find_first_of( "%" ) + 1 );
55 scope_id = if_nametoindex( ifname.c_str() );
57 scope_id = atoi(ifname.c_str());
58 ar << boost::serialization::make_nvp( "addr", addr_ );
60 ar << boost::serialization::make_nvp( "addr", addr );
62 ar << boost::serialization::make_nvp( "port", port );
63 ar << boost::serialization::make_nvp( "scope_id", scope_id );
66 template<class Archive, class T>
69 boost::asio::ip::basic_endpoint<T>& t,
70 const unsigned int /* file_version */
74 unsigned long scope_id;
75 ar >> boost::serialization::make_nvp( "addr", addr );
76 ar >> boost::serialization::make_nvp( "port", port );
77 ar >> boost::serialization::make_nvp( "scope_id", scope_id );
78 boost::asio::ip::address tmp = boost::asio::ip::address::from_string( addr );
80 boost::asio::ip::address_v6 v6addr = boost::asio::ip::address_v6::from_string( addr );
81 v6addr.scope_id(scope_id);
82 t = boost::asio::ip::basic_endpoint<T>( v6addr, port );
84 t = boost::asio::ip::basic_endpoint<T>( boost::asio::ip::address_v4::from_string( addr ), port );
88 } // namespace serialization