Exemplo n.º 1
0
/* Generate a string describing an enumerated bitfield (an N-bit field
   with various specific values having particular names). */
const char *
decode_enumerated_bitfield(guint32 val, guint32 mask, int width,
    const value_string *tab, const char *fmt)
{
  static char buf[1025];
  char *p;

  p = decode_bitfield_value(buf, val, mask, width);
  g_snprintf(p, (gulong) (1024-(p-buf)), fmt, val_to_str(val & mask, tab, "Unknown"));
  return buf;
}
Exemplo n.º 2
0
/*
 * Decode the SAP value as a bitfield into a string, skipping the GI/CR bit.
 * Ordinarily, this could be done easily by specifying a bitmask in the
 * corresponding hf_ entry for the DSAP/SSAP value and simply using a
 * proto_tree_add_... function to add the item into a proto tree. The
 * problem is that the proto_tree_add_... functions always bitshift the
 * value if a bitmask is specified. A SAP value always comprises the entire
 * octet, however, and must not be shifted. Therefore, using a simple
 * proto_tree_add_... function to display the topmost 7 bits of the SAP
 * value as a bitfield produces incorrect results (while the bitfield is
 * displayed correctly, Wireshark uses the bitshifted value to display the
 * associated name and for filtering purposes). This function calls the
 * Wireshark routine to decode the SAP value as a bitfield into a given
 * string without performing any bitshift of the original value.
 *
 * The string passed to this function must be of ITEM_LABEL_LENGTH size.
 * The SAP value passed to this function must be complete (not masked).
 *
 */
static gchar *
decode_sap_value_as_bitfield(gchar *buffer, guint32 sap)
{
	char *p;

	memset (buffer, '\0', ITEM_LABEL_LENGTH);
	p = decode_bitfield_value (buffer, sap, SAP_MASK, 8);
	g_snprintf(p, (gulong)(ITEM_LABEL_LENGTH-strlen(buffer)-1), "SAP: %s",
		val_to_str_const(sap, sap_vals, "Unknown"));

	return buffer;
}
Exemplo n.º 3
0
/* Generate a string describing an enumerated bitfield (an N-bit field
   with various specific values having particular names). */
const char *
decode_enumerated_bitfield_shifted(guint32 val, guint32 mask, int width,
    const value_string *tab, const char *fmt)
{
  static char buf[1025];
  char *p;
  int shift = 0;

  /* Compute the number of bits we have to shift the bitfield right
     to extract its value. */
  while ((mask & (1<<shift)) == 0)
    shift++;

  p = decode_bitfield_value(buf, val, mask, width);
  g_snprintf(p, (gulong) (1024-(p-buf)), fmt, val_to_str((val & mask) >> shift, tab, "Unknown"));
  return buf;
}