OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sandesh_util.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 //
6 // sandesh_util.cc
7 //
8 
9 #include <boost/tokenizer.hpp>
10 
11 #include <base/string_util.h>
12 #include <base/address_util.h>
13 
14 #include "sandesh_util.h"
15 
16 using boost::asio::ip::address;
17 
18 bool MakeEndpoint(TcpServer::Endpoint* ep, const std::string& epstr) {
19  typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
20  boost::char_separator<char> sep(":");
21 
22  tokenizer tokens(epstr, sep);
23  tokenizer::iterator it = tokens.begin();
24  std::string sip(*it);
25  ++it;
26  std::string sport(*it);
27  int port;
28  stringToInteger(sport, port);
29  boost::system::error_code ec;
30  address addr = AddressFromString(sip, &ec);
31  if (ec) {
32  return false;
33  }
34  *ep = TcpServer::Endpoint(addr, port);
35  return true;
36 }
37 
38 bool MakeEndpoint(UdpServer::Endpoint* ep, const std::string& epstr) {
39  typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
40  boost::char_separator<char> sep(":");
41 
42  tokenizer tokens(epstr, sep);
43  tokenizer::iterator it = tokens.begin();
44  std::string sip(*it);
45  ++it;
46  std::string sport(*it);
47  int port;
48  stringToInteger(sport, port);
49  boost::system::error_code ec;
50  address addr = AddressFromString(sip, &ec);
51  if (ec) {
52  return false;
53  }
54  *ep = UdpServer::Endpoint(addr, port);
55  return true;
56 }
bool MakeEndpoint(TcpServer::Endpoint *ep, const std::string &epstr)
Definition: sandesh_util.cc:18
boost::asio::ip::udp::endpoint Endpoint
Definition: udp_server.h:20
bool stringToInteger(const std::string &str, NumberType &num)
Definition: string_util.h:71
boost::tokenizer< boost::char_separator< char > > tokenizer
IpAddress AddressFromString(const std::string &ip_address_str, boost::system::error_code *ec)
boost::asio::ip::tcp::endpoint Endpoint
Definition: tcp_server.h:30