Example #1
0
		bool is_allowed(const boost::asio::ip::address &address, std::list<std::string> &errors) {
			return (entries_v4.empty()&&entries_v6.empty())
				|| (address.is_v4() && is_allowed_v4(address.to_v4().to_bytes(), errors))
				|| (address.is_v6() && is_allowed_v6(address.to_v6().to_bytes(), errors))
				|| (address.is_v6() && address.to_v6().is_v4_compatible() && is_allowed_v4(address.to_v6().to_v4().to_bytes(), errors))
				|| (address.is_v6() && address.to_v6().is_v4_mapped() && is_allowed_v4(address.to_v6().to_v4().to_bytes(), errors))
				;
		}
Example #2
0
void PacketLog::LogPacket(WorldPacket const& packet, Direction direction, boost::asio::ip::address const& addr, uint16 port)
{
    std::lock_guard<std::mutex> lock(_logPacketLock);

    PacketHeader header;
    *reinterpret_cast<uint32*>(header.Direction) = direction == CLIENT_TO_SERVER ? 0x47534d43 : 0x47534d53;
    header.ConnectionId = 0;
    header.ArrivalTicks = getMSTime();

    header.OptionalDataSize = sizeof(header.OptionalData);
    memset(header.OptionalData.SocketIPBytes, 0, sizeof(header.OptionalData.SocketIPBytes));
    if (addr.is_v4())
    {
        auto bytes = addr.to_v4().to_bytes();
        memcpy(header.OptionalData.SocketIPBytes, bytes.data(), bytes.size());
    }
    else if (addr.is_v6())
    {
        auto bytes = addr.to_v6().to_bytes();
        memcpy(header.OptionalData.SocketIPBytes, bytes.data(), bytes.size());
    }

    header.OptionalData.SocketPort = port;
    header.Length = packet.size() + sizeof(header.Opcode);
    header.Opcode = packet.GetOpcode();

    fwrite(&header, sizeof(header), 1, _file);
    if (!packet.empty())
        fwrite(packet.contents(), 1, packet.size(), _file);

    fflush(_file);
}
Example #3
0
bool PeerID::Certificate::checkAltNames(boost::asio::ip::address& address) const
{
	GENERAL_NAMES* gens = static_cast<GENERAL_NAMES*>(
		X509_get_ext_d2i(x509_, NID_subject_alt_name, 0, 0));
	BOOST_SCOPE_EXIT(gens){
		GENERAL_NAMES_free(gens);
	}BOOST_SCOPE_EXIT_END;
	for (int i = 0; i < sk_GENERAL_NAME_num(gens); ++i)
	{
		GENERAL_NAME* gen = sk_GENERAL_NAME_value(gens, i);
		if (gen->type == GEN_IPADD)
		{			
			ASN1_OCTET_STRING* ip = gen->d.iPAddress;
			if (ip->type == V_ASN1_OCTET_STRING && ip->data)
			{
				return (
					(address.is_v4() && ip->length == 4 &&
						std::memcmp(address.to_v4().to_bytes().data(), ip->data, 4) == 0) ||
					(address.is_v6() && ip->length == 16 &&
						std::memcmp(address.to_v6().to_bytes().data(), ip->data, 16) == 0)
					);
			}
		}
	}
}
Example #4
0
bool IsLoopbackAddress(const boost::asio::ip::address& addr) {

	if (addr.is_v6()) {
		return addr.to_v6().is_loopback();
	} else {
		return (addr.to_v4() == boost::asio::ip::address_v4::loopback());
	}
}
Example #5
0
bool is_link_local(const boost::asio::ip::address& addr) {
    if (addr.is_v6() && addr.to_v6().is_link_local())
        return true;
    if (addr.is_v4() &&
        (mask_address(addr, 16) == address::from_string("169.254.0.0")))
        return true;
    return false;
}
Example #6
0
  bool subsumes( Entry other )
  {
    if ( addr.is_v6() != other.addr.is_v6() )
      {
        // jeden adres jest v6, drugi v4
        // zwracamy zawsze false
        return false;
      }

    if ( addr.is_v6() )
      {
        boost::asio::ip::address_v6::bytes_type a1 = addr.to_v6().to_bytes();
        boost::asio::ip::address_v6::bytes_type a2 = other.addr.to_v6().to_bytes();
        int mask_left = mask;
        for(unsigned int i = 0; i < a1.size(); i++)
          {
            int tmp = (1 << std::max(0,std::min(mask_left,8)))-1;
            unsigned char apply_mask = tmp;
            mask_left -= 8;
            a1[i] &= apply_mask;
            a2[i] &= apply_mask;
          }
        bool val = boost::asio::ip::address_v6(a1) == boost::asio::ip::address_v6(a2);
        return val;
      }
    else
      {
        boost::asio::ip::address_v4::bytes_type a1 = addr.to_v4().to_bytes();
        boost::asio::ip::address_v4::bytes_type a2 = other.addr.to_v4().to_bytes();
        int mask_left = mask;
        for(unsigned int i = 0; i < a1.size(); i++)
          {
            int tmp = (1 << std::max(0,std::min(mask_left,8)))-1;
            unsigned char apply_mask = tmp;
            mask_left -= 8;
            a1[i] &= apply_mask;
            a2[i] &= apply_mask;
          }
        bool val = boost::asio::ip::address_v4(a1) == boost::asio::ip::address_v4(a2);
        return val;
      }

    return false;
  }
Example #7
0
static bool
isLoopback(const boost::asio::ip::address& addr)
{
  if (addr.is_loopback()) {
    return true;
  }
  // Workaround for loopback IPv4-mapped IPv6 addresses
  // see https://svn.boost.org/trac/boost/ticket/9084
  else if (addr.is_v6()) {
    auto addr6 = addr.to_v6();
    if (addr6.is_v4_mapped()) {
      return addr6.to_v4().is_loopback();
    }
  }

  return false;
}
Example #8
0
 /**
  * If true the address is private.
  */
 static bool address_is_private(
     const boost::asio::ip::address & addr
     )
 {
     if (addr.is_v6())
     {
         return addr.to_v6().is_link_local();
     }
     else
     {
         std::uint32_t ip = addr.to_v4().to_ulong();
         
         return (
             (ip & 0xff000000) == 0x0a000000 || 
             (ip & 0xfff00000) == 0xac100000 || 
             (ip & 0xffff0000) == 0xc0a80000
         );
     }
     
     return false;
 }
Example #9
0
bool ClientAllowed(const boost::asio::ip::address& address)
{
    // Make sure that IPv4-compatible and IPv4-mapped IPv6 addresses are treated as IPv4 addresses
    if (address.is_v6()
     && (address.to_v6().is_v4_compatible()
      || address.to_v6().is_v4_mapped()))
        return ClientAllowed(address.to_v6().to_v4());

    if (address == asio::ip::address_v4::loopback()
     || address == asio::ip::address_v6::loopback()
     || (address.is_v4()
         // Check whether IPv4 addresses match 127.0.0.0/8 (loopback subnet)
      && (address.to_v4().to_ulong() & 0xff000000) == 0x7f000000))
        return true;

    const string strAddress = address.to_string();
    const vector<string>& vAllow = SysCfg().GetMultiArgs("-rpcallowip");
    for (auto strAllow : vAllow)
        if (WildcardMatch(strAddress, strAllow))
            return true;
    return false;
}
Example #10
0
		bool is_allowed(const boost::asio::ip::address &address, std::list<std::string> &errors) {
			return (address.is_v4() && is_allowed_v4(address.to_v4().to_ulong(), errors))
				|| (address.is_v6() && address.to_v6().is_v4_compatible() && is_allowed_v4(address.to_v6().to_v4().to_ulong(), errors))
				|| (address.is_v6() && address.to_v6().is_v4_mapped() && is_allowed_v4(address.to_v6().to_v4().to_ulong(), errors));
		}
Example #11
0
 bool
 operator()(const boost::asio::ip::address& address)
 {
   return address.is_v6();
 }
Example #12
0
//	////////////////////////////////////////////////////////////////////////////
HostEntry HostAddressToEntry(const boost::asio::ip::address &host_address)
{
	return((host_address.is_v6()) ?
		HostAddressToEntry(host_address.to_v6()) :
		HostAddressToEntry(host_address.to_v4()));
}
Example #13
0
 Client::Client(const std::string& name, const boost::asio::ip::address& ip) :
   AbstractReceivable(2 + (ip.is_v6() ? 16 : 4) + name.size()),
   its_name(name),
   its_ip(ip)
 {
 }