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