Commit bd9a2ee9 authored by Yann Garcia's avatar Yann Garcia
Browse files

Bug fixed in ccsrc/Protocols/UDP/udp_layer.cc

parent 82952c8e
Loading
Loading
Loading
Loading
+4 −1
Changes for ccsrc/Protocols/UDP/udp_layer.cc: 4 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -37,6 +37,9 @@ void udp_layer::init() {
  loggers::get_instance().log(">>> udp_layer::init");

  params::const_iterator it = _params.find("src_ip");
  // An explicit src_ip is the local address to bind to (e.g. next to another process using the same port on another
  // address); without it, the socket is bound to all the addresses (INADDR_ANY), as before
  const bool bind_src_ip = (it != _params.cend());
  if (it == _params.cend()) {
    _params.insert(std::pair<std::string, std::string>(std::string("src_ip"), "127.0.0.1"));
  }
@@ -60,7 +63,7 @@ void udp_layer::init() {

  // Initialize the socket
  _saddr.sin_family      = AF_INET;
  _saddr.sin_addr.s_addr = htonl(INADDR_ANY);
  _saddr.sin_addr.s_addr = bind_src_ip ? htonl(get_host_id(_params["src_ip"])) : htonl(INADDR_ANY);
  loggers::get_instance().log("udp_layer::init: Port to listen=%d", std::atoi(_params["src_port"].c_str()));
  _saddr.sin_port = htons(std::atoi(_params["src_port"].c_str()));
  // Create socket