예제 #1
0
void NetworkPacket::checkReadOffset(u32 from_offset, u32 field_size)
{
	if (from_offset + field_size > m_datasize) {
		std::stringstream ss;
		ss << "Reading outside packet (offset: " <<
				from_offset << ", packet size: " << getSize() << ")";
		throw PacketError(ss.str());
	}
}
예제 #2
0
InetPacket::InetPacket(shared_ptr<Packet> packet, Protocol datalink_protocol) :
		Packet(packet->getLength(), packet->getTimestamp(), packet->raw_data_begin(),
				packet->raw_data_length()) {
	if (!isValid(packet, datalink_protocol)) {
		throw PacketError("inet");
	}
	this->datalinkInfo = shared_ptr<DatalinkInfo>(new EthernetInfo(this->raw_data_begin()));
	this->datalink_header = this->start;
	this->datalink_data = this->start + this->datalinkInfo->getLength();
}
예제 #3
0
	string InPacket::readpadascii(int16_t count)
	{
		if (count > top - pos)
			throw PacketError("Stack underflow while reading string.");

		string ret;
		for (int16_t i = 0; i < count; i++)
		{
			char letter = bytes[pos];
			if (letter != '\0')
			{
				ret.push_back(letter);
			}
			pos++;
		}
		return ret;
	}
예제 #4
0
	void InPacket::skip(size_t count)
	{
		if (count > top - pos)
			throw PacketError("Stack underflow while using skip.");
		pos += count;
	}