示例#1
0
static void
dissect_event_counter(tvbuff_t *tvb, proto_tree *tree)
{
	guint32 aa;
	aa 			= tvb_get_letohl(tvb, get_header_length());
	if (aa != adv_aa)
	{
		proto_tree_add_item(tree, hf_nordic_ble_event_counter, tvb, get_ec_index(), 2, ENC_LITTLE_ENDIAN);
	}
}
logical EB_RBHeader :: Reset ( )
{
  logical                 term = NO;
  EB_MBHeader::Reset();
  set_mb_count(1);
  get_work_spaces() = 0;

  set_next_position(get_header_length() + sizeof(EBRootBase));

  return(term);
}
void EB_extHeader :: ToPIF (logical pif )
{

  if ( pif )
  {
    set_mod_count(ShortToPIF(get_mod_count(),pif));
    set_header_length(ShortToPIF(get_header_length(),pif));
  }


}
void EB_extHeader :: FromPIF (logical pif )
{

  if ( pif )
  {
    set_mod_count(PIFToShort(get_mod_count(),pif));
    set_header_length(PIFToShort(get_header_length(),pif));
  }


}
示例#5
0
pcap_handler analyze_packets(unsigned char *p, struct pcap_pkthdr *h, unsigned char *packet)
{
  /*
    Assumption:  We are only worried about Ethernet
    Process:  Grab the packet headers, identify protocol
              and attach pointers to the headers.  Key the
	      packets using a hash of the IP port pairs.
	      Build a tree according to packet contents.
	      Nodes will hold value and count.  Top level
	      counts can be used to deduce frequency.
  */

  unsigned char *ip_header, *saddr, *daddr, *checksum, *chkptr, *data;
  unsigned int ip_words[64];
  unsigned int i, header_length, num_words, chksum;
  unsigned char chkflag;
  unsigned int hash_value;
  struct root_struct *ptr;

  packets++;
  DEBUG("Handling packet");
  ip_header = (packet + 14);
  header_length = get_header_length(ip_header);
  switch(ip_header[9])
    {
    case 0x01 : //ICMP
      data = ip_header + header_length + 4;
      break;
    case 0x06 : //TCP
      data = ip_header + header_length + 20;
      break;
    case 0x11: //UDP
      data = ip_header + header_length + 8;
      break;
    case 0x32: //ESP
      data = ip_header + header_length + 8;
      break;
    case 0x02: //IGMP
      data = ip_header + header_length + 8;
      break;
    default : 
      if(!(flags & QUIET))
	printf("\tUnknown: %x\n", (unsigned char)ip_header[9] );
      data = ip_header + header_length;
      break;
    }
  data = (flags & SRC_PORTS ? ip_header + header_length :
	  (flags & DST_PORTS ? ip_header + header_length + 2 :
	   (flags & IPIDS ? ip_header + 4 :
	    (flags & SEQ_NUMS ? ip_header + header_length + 4 :
	     (flags & SRC_HOSTS ? ip_header + 12 :
        (flags & CHECKSUM ? ip_header + 10 :
	     data))))));
  if((data + significant_bytes) > 
     (ip_header + ntohs(*((unsigned short int *)ip_header+1))))
    {
      if(!(flags & QUIET)) printf("Not enough data!\n");
      return 0;
    }
  ptr = find_root(data, root);
  DEBUG("Root found");
  if(ptr == NULL)
    {
      DEBUG("New root needed");
      ptr = new_root();
      DEBUG("New root allocated");
      sigs++;
      memcpy(ptr->key, data, significant_bytes);
      DEBUG("Completed memcpy");
      hash_value = hash(data);
      ptr -> hash_value = hash_value;
      if(root == NULL)
	{ 
	  hash_table[hash_value] = ptr;
	  root = ptr;
	  last = root;
	}
      else 
	{
	  insert(ptr);
	}
    }
  ptr->count ++;
  bzero(data, significant_bytes + 1);
}
eap_status_e asn1_der_type_c::initialize(
	const u32_t length,
	const u8_t * const data,
	const u16_t recursion,
	const u32_t index,
	eap_variable_data_c * const debug_buffer)
{
	EAP_UNREFERENCED_PARAMETER(debug_buffer);
	if (index > 0xffff)
	{
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
		return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter);
	}

	m_index = static_cast<u16_t>(index);

	m_recursion = recursion;

	m_input_data_length = length;

	if (m_input_data_length == 0)
	{
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
		return EAP_STATUS_RETURN(m_am_tools, eap_status_buffer_too_short);
	}

	m_input_data = data;

	if (m_input_data == 0)
	{
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
		return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter);
	}
	m_offset_of_length_field = get_offset_of_length_field();

	if (m_offset_of_length_field > m_input_data_length
		|| m_offset_of_length_field == 0)
	{
		ASN1_DEBUG_HEADER(this, debug_buffer);
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
		return EAP_STATUS_RETURN(m_am_tools, eap_status_buffer_too_short);
	}

	m_offset_of_contents_field = get_offset_of_contents_field();

	if (m_offset_of_contents_field > m_input_data_length
		|| m_offset_of_contents_field == 0)
	{
		ASN1_DEBUG_HEADER(this, debug_buffer);
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
		return EAP_STATUS_RETURN(m_am_tools, eap_status_buffer_too_short);
	}

	if ((m_offset_of_contents_field + get_content_length()) > m_input_data_length)
	{
		ASN1_DEBUG_HEADER(this, debug_buffer);
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
		return EAP_STATUS_RETURN(m_am_tools, eap_status_buffer_too_short);
	}

	u32_t data_length = get_header_length() + get_content_length();

	if (m_input_data_length >= data_length)
	{
		m_input_data_length = data_length;
	}
	else
	{
		ASN1_DEBUG_HEADER(this, debug_buffer);
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
		return EAP_STATUS_RETURN(m_am_tools, eap_status_buffer_too_short);
	}

	add_used_octets(get_header_length());

	ASN1_DEBUG_HEADER(this, debug_buffer);

	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
}
eap_status_e asn1_der_type_c::debug_data(eap_variable_data_c * const debug_buffer)
{
	if (debug_buffer == 0)
	{
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
		return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter);
	}

	const u32_t max_prefix_length((m_recursion + 1ul) * SIZE_OF_ONE_OCTET_STRING + COUNT_OF_OCTETS * SIZE_OF_ONE_OCTET_STRING + 1ul);
	const u32_t ascii_length(COUNT_OF_OCTETS + 5ul);

	if ((max_prefix_length + ascii_length) > debug_buffer->get_buffer_length())
	{
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
	}

	eap_status_e status = debug_buffer->set_data_length(max_prefix_length + ascii_length);
	if (status != eap_status_ok)
	{
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
		return EAP_STATUS_RETURN(m_am_tools, status);
	}

	u8_t * const prefix = reinterpret_cast<u8_t *>(debug_buffer->get_data(max_prefix_length));
	u8_t * const ascii = reinterpret_cast<u8_t *>(debug_buffer->get_data_offset(max_prefix_length, ascii_length));

	if (prefix == 0 || ascii == 0)
	{
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
	}

	u32_t ind(0ul);
	u32_t offset(0ul);

	status = debug_create_prefix(m_recursion + 1u, prefix, max_prefix_length, &offset);
	if (status != eap_status_ok)
	{
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
		return EAP_STATUS_RETURN(m_am_tools, status);
	}

	u32_t init_indentation_offset = offset;
	u32_t type_data_size = get_header_length() + get_content_length();
	u32_t data_ind(0ul);
	u32_t ascii_ind(0ul);
	u8_t octet(0);

	for (ind = m_offset_of_contents_field; ind < type_data_size && ind < m_input_data_length; ++ind)
	{
		offset += m_am_tools->snprintf(
			&prefix[offset],
			max_prefix_length - offset,
			"%02x \0",
			m_input_data[ind]);

		octet = m_input_data[ind];

		if (octet < 0x20 || 0x7e < octet)
		{
			octet = '.';
		}

		m_am_tools->snprintf(
			&ascii[ascii_ind],
			ascii_length - ascii_ind,
			"%c\0",
			octet);

		++data_ind;
		++ascii_ind;

		if ((ascii_ind % COUNT_OF_OCTETS) == 0)
		{
			prefix[offset] = 0;
			ascii[ascii_ind] = 0;

			offset = init_indentation_offset;
			ascii_ind = 0ul;

			EAP_TRACE_DEBUG(
				m_am_tools,
				TRACE_FLAGS_DEFAULT,
				(EAPL("%s |%s|\n"),
					prefix,
					ascii));
		}
	} // for()

	u32_t remainder(ascii_ind % COUNT_OF_OCTETS);

	if (remainder > 0ul)
	{
		for (; ascii_ind < COUNT_OF_OCTETS; ++ascii_ind)
		{
			offset += m_am_tools->snprintf(
				&prefix[offset],
				max_prefix_length - offset,
				"   \0");

			m_am_tools->snprintf(
				&ascii[ascii_ind],
				ascii_length - ascii_ind,
				" \0");
		} // for()

		prefix[offset] = 0;
		ascii[ascii_ind] = 0;

		EAP_TRACE_DEBUG(
			m_am_tools,
			TRACE_FLAGS_DEFAULT,
			(EAPL("%s |%s|\n"),
				prefix,
				ascii));
	}

	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
	return EAP_STATUS_RETURN(m_am_tools, status);
}