Ejemplo n.º 1
0
IPAddress IPAddress::fromV4IPPort(const char* ipPortTuple)
{
  std::vector<std::string> tokens = OSS::string_tokenize(ipPortTuple, ":");
  IPAddress addr;
  if (tokens.size() == 1)
    addr = fromHost(tokens[0].c_str());
  else if(tokens.size() == 2)
  {
    addr = fromHost(tokens[0].c_str());
    addr.setPort(OSS::string_to_number<unsigned short>(tokens[1].c_str()));
  }
  return addr;
}
Ejemplo n.º 2
0
IPAddress Connection::getPeer() const {
  IPAddress peer;

  char *addr;
  ev_uint16_t port;
  evhttp_connection_get_peer(con, &addr, &port);
  if (addr) peer = IPAddress(addr, port);

  const sockaddr *sa = evhttp_connection_get_addr(con);
  if (sa && sa->sa_family == AF_INET) {
    peer.setPort(((sockaddr_in *)sa)->sin_port);
    peer.setIP(((sockaddr_in *)sa)->sin_addr.s_addr);
  }

  return peer;
}