2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
8 As a special exception, if other files instantiate templates or use macros
9 or inline functions from this file, or you compile this file and link it
10 with other works to produce a work based on this file, this file
11 does not by itself cause the resulting work to be covered
12 by the GNU General Public License.
14 However the source code for this file must still be made available
15 in accordance with section (3) of the GNU General Public License.
17 This exception does not invalidate any other reasons why a work based
18 on this file might be covered by the GNU General Public License.
21 #include "host/pingprotocol.h"
26 #include "boost_assert_handler.h"
30 static map<string, PingProtocol> protocol_string_map;
33 * @brief Transform the @a protocol_string into a @c PingProtocol.
35 * @param protocol_string The string to be parsed.
37 * @return The @c PingProtocol corresponding to the @a protocol_string.
39 PingProtocol get_ping_protocol_from_string( const string & protocol_string )
41 BOOST_ASSERT( !protocol_string.empty() );
43 // convert to uppercase to allow the protocol to be case insensitive
44 string protocol_uppercase_string( protocol_string );
45 transform( protocol_string.begin(), protocol_string.end(),
46 protocol_uppercase_string.begin(),
47 ::toupper ); //lint !e534
49 // TODO move to an init method
50 protocol_string_map[ "ICMP" ] = PingProtocol_ICMP;
51 protocol_string_map[ "ICMPV4" ] = PingProtocol_ICMP;
52 protocol_string_map[ "ICMPV6" ] = PingProtocol_ICMPv6;
53 protocol_string_map[ "TCP" ] = PingProtocol_TCP;
54 protocol_string_map[ "TCP_IPV4" ] = PingProtocol_TCP;
55 protocol_string_map[ "TCP_IPV6" ] = PingProtocol_TCP_IPv6;
56 protocol_string_map[ "TCPV4" ] = PingProtocol_TCP;
57 protocol_string_map[ "TCPV6" ] = PingProtocol_TCP_IPv6;
59 PingProtocol protocol = protocol_string_map[ protocol_uppercase_string ];
64 std::string ping_protocol_to_string( const PingProtocol &protocol)
68 case PingProtocol_ICMP: return "ICMPv4"; break;
69 case PingProtocol_ICMPv6: return "ICMPv6"; break;
70 case PingProtocol_TCP: return "TCPv4"; break;
71 case PingProtocol_TCP_IPv6: return "TCPv6"; break;
74 !"unexpected PingProtocol in ping_protocol_to_string!" );