Beispiel #1
0
 void masking_algorithm(char* ptr)
 {
   const char* mask = keymask();
   for (size_t i = 0; i < data_length(); i++)
   {
     ptr[i] = ptr[i] xor mask[i & 3];
   }
 }
 int total_data_length()
 {
   int len = data_length();
   PacketDataBuffer this_buf = next();
   while (this_buf.not_null()) {
     len += this_buf.data_length();
     this_buf = this_buf.next();
   }
   return len;
 }
Beispiel #3
0
static int
append_answer(DNS_query *query, DNS_rr *answer)
{
	size_t rdlength;
	unsigned offset;
	unsigned char *pkt, *eom;
	unsigned char ipv6[IPV6_BYTE_SIZE];

	rdlength = data_length(answer);
	if (UDP_PACKET_SIZE < query->packet.length + DNS_RR_MIN_LENGTH + rdlength)
		return -1;

	query->packet.header.bits = htons(BITS_QR | DNS_RCODE_OK);
	query->packet.header.ancount = ntohs(1);

	pkt = (unsigned char *) &query->packet.header;
	eom = pkt + query->packet.length;

	/* The answer has the same name as the query. Add pointer to query name. */
	offset = (unsigned char *) &query->packet.data - pkt;
	eom += networkSetShort(eom, 0xC000 | offset);

	eom += networkSetShort(eom, answer->type);
	eom += networkSetShort(eom, DNS_CLASS_IN);
	eom += networkSetLong(eom, 1L);
	eom += networkSetShort(eom, rdlength);

	switch (answer->type) {
	case DNS_TYPE_A:
		(void) parseIPv6((char *) answer->data, ipv6);
		memcpy(eom, ipv6+IPV6_OFFSET_IPV4, 4);
		break;

	case DNS_TYPE_AAAA:
		(void) parseIPv6((char *) answer->data, eom);
		break;

	case DNS_TYPE_TXT:
		*eom++ = (unsigned char) answer->data_length;
		/*@fallthrough@*/

	case DNS_TYPE_NULL:
		if (UDP_PACKET_SIZE < eom - pkt + answer->data_length)
			return -1;
		memcpy(eom, answer->data, answer->data_length);
		break;

	default:
		return -1;
	}

	query->packet.length = eom - pkt + rdlength;

	return 0;
}
bool Packet::length_valid() const {
	const size_t extra_bits = data_and_fcs_length() & 7;
	if( extra_bits != 0 ) {
		return false;
	}

	const PacketLengthValidator packet_length_valid;
	if( !packet_length_valid(message_id(), data_length()) ) {
		return false;
	}

	return true;
}
Beispiel #5
0
    void set_payload(const size_t len)
    {
      uint16_t pbits = len;
      if      (len > 65535) pbits = 127;
      else if (len > 125)   pbits = 126;
      bits &= 0x80ff;
      bits |= (pbits & 0x7f) << 8;

      if (is_ext())
          *(uint16_t*) vla = __builtin_bswap16(len);
      else if (is_ext2())
          *(uint64_t*) vla = __builtin_bswap64(len);
      assert(data_length() == len);
    }
//
//
//
/// @brief Build its identity form, if the current rank two array is square and
/// was previously initialized either by construction or the array::create()
/// member function. Otherwise nothing is done. Notice that the previous content,
/// if any, will be lost.
//
/// @return None.
//
void build_identity_form()
{
	if(is_square())
	{
		OMP_STATIC_LOOP_POLICY
		for(INIT_ITER(i, 1); i < first_rank(); ++i)
		{
			data[offset(i, i)] = data_type(1.0);
			for(unsigned int j(i + 1); j <= second_rank(); ++j)
			{
				data[offset(i, j)] = data[offset(j, i)] = data_type(0.0);
			}
		}
		data[data_length() - 1] = data_type(1.0);
	}
};