/* code to dissect fairly common sequence in NORM packets */ static guint dissect_grrtetc(proto_tree *tree, tvbuff_t *tvb, guint offset) { guint8 backoff; double gsizex; double grtt; proto_tree_add_item(tree, hf_instance_id, tvb, offset, 2, ENC_BIG_ENDIAN); offset+=2; grtt = UnquantizeRtt(tvb_get_guint8(tvb, offset)); proto_tree_add_double(tree, hf_grtt, tvb, offset, 1, grtt); offset += 1; backoff = hi_nibble(tvb_get_guint8(tvb, offset)); gsizex = UnquantizeGSize((guint8)lo_nibble(tvb_get_guint8(tvb, offset))); proto_tree_add_uint(tree, hf_backoff, tvb, offset, 1, backoff); proto_tree_add_double(tree, hf_gsize, tvb, offset, 1, gsizex); offset += 1; return offset; }
inline extended_reg<T> extended_add_unsigned(T lhs, T rhs) { QUAN_STATIC_ASSERT((std::is_unsigned<T>::value)); extended_reg<T> res; res.sign = extended_reg<T>::positive; static const T shift = quan::meta::asm_::nibble_shift<T>::value; static const T lo_mask = quan::meta::asm_::lo_nibble_mask<T>::value; res.lo = lo_nibble(lhs) + lo_nibble(rhs); T reg = hi_nibble(res.lo) + hi_nibble(lhs); res.lo = lo_nibble(res.lo) | ( lo_nibble(reg) << shift); res.hi = hi_nibble(reg); reg = hi_nibble(res.lo) + hi_nibble(rhs); res.lo = lo_nibble(res.lo) | ( lo_nibble(reg) << shift); res.hi += hi_nibble(reg); return res; }
static int dissect_ltp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { proto_item *ti = NULL; proto_tree *ltp_tree = NULL; int frame_offset; int header_offset; int segment_offset = 0; int hdr_extn_offset = 0; int trl_extn_offset = 0; guint8 ltp_hdr; gint ltp_type; guint8 ltp_extn_cnt; gint hdr_extn_cnt; gint trl_extn_cnt; guint64 engine_id; guint64 session_num; int engine_id_size; int session_num_size; proto_item *ltp_header_item = NULL; proto_item *ltp_session_item = NULL; proto_tree *ltp_header_tree = NULL; proto_tree *ltp_session_tree = NULL; /* Check that there's enough data */ if(tvb_length(tvb) < LTP_MIN_DATA_BUFFER){ return 0; } frame_offset = 0; header_offset = 0; col_set_str(pinfo->cinfo, COL_PROTOCOL, "LTP Segment"); /* Extract all the header info from the packet */ ltp_hdr = tvb_get_guint8(tvb, frame_offset); header_offset++; engine_id = evaluate_sdnv_64(tvb,frame_offset + header_offset,&engine_id_size); header_offset += engine_id_size; if((unsigned)header_offset >= tvb_length(tvb)){ col_set_str(pinfo->cinfo, COL_INFO, "Protocol Error"); return 0; } session_num = evaluate_sdnv_64(tvb,frame_offset + header_offset,&session_num_size); header_offset += session_num_size; if((unsigned)header_offset >= tvb_length(tvb)){ col_set_str(pinfo->cinfo, COL_INFO, "Protocol Error"); return 0; } ti = proto_tree_add_item(tree, proto_ltp, tvb, 0, -1, ENC_NA); ltp_tree = proto_item_add_subtree(ti, ett_ltp); /* Adding Header Subtree */ ltp_header_item = proto_tree_add_text(ltp_tree, tvb, frame_offset, header_offset+1, "LTP Header"); ltp_header_tree = proto_item_add_subtree(ltp_header_item, ett_ltp_hdr); proto_tree_add_uint(ltp_header_tree,hf_ltp_version,tvb,frame_offset,1,hi_nibble(ltp_hdr)); ltp_type = lo_nibble(ltp_hdr); proto_tree_add_uint_format_value(ltp_header_tree,hf_ltp_type,tvb,frame_offset,1,ltp_type,"%x (%s)", ltp_type,val_to_str(ltp_type,ltp_type_codes,"Invalid")); frame_offset++; /* Adding the session id subtree */ ltp_session_item = proto_tree_add_item(ltp_header_item,hf_ltp_session_id,tvb,frame_offset, engine_id_size + session_num_size,ENC_NA); ltp_session_tree = proto_item_add_subtree(ltp_session_item,ett_hdr_session); proto_tree_add_uint64(ltp_session_tree,hf_ltp_session_orig,tvb,frame_offset,engine_id_size,engine_id); frame_offset+=engine_id_size; proto_tree_add_uint64(ltp_session_tree,hf_ltp_session_no, tvb, frame_offset,session_num_size,session_num); frame_offset+=session_num_size; /* Adding Extension count to the header tree */ ltp_extn_cnt = tvb_get_guint8(tvb,frame_offset); hdr_extn_cnt = hi_nibble(ltp_extn_cnt); trl_extn_cnt = lo_nibble(ltp_extn_cnt); proto_tree_add_uint(ltp_header_tree,hf_ltp_hdr_extn_cnt,tvb,frame_offset,1,hdr_extn_cnt); proto_tree_add_uint(ltp_header_tree,hf_ltp_trl_extn_cnt,tvb,frame_offset,1,trl_extn_cnt); frame_offset++; col_add_str(pinfo->cinfo, COL_INFO, val_to_str_const(ltp_type,ltp_type_col_info,"Protocol Error")); if((unsigned)frame_offset >= tvb_length(tvb)){ col_set_str(pinfo->cinfo, COL_INFO, "Protocol Error"); return 0; } /* Check if there are any header extensions */ if(hdr_extn_cnt > 0){ hdr_extn_offset = dissect_header_extn(ltp_tree, tvb, frame_offset,hdr_extn_cnt); if(hdr_extn_offset == 0){ col_set_str(pinfo->cinfo, COL_INFO, "Protocol Error"); return 0; } frame_offset += hdr_extn_offset; } if((unsigned)frame_offset >= tvb_length(tvb)){ col_set_str(pinfo->cinfo, COL_INFO, "Protocol Error"); return 0; } /* Call sub routines to handle the segment content*/ if((ltp_type >= 0) && (ltp_type < 8)){ segment_offset = dissect_data_segment(ltp_tree,tvb,pinfo,frame_offset,ltp_type,session_num); if(segment_offset == 0){ col_set_str(pinfo->cinfo, COL_INFO, "Protocol Error"); return 0; } } else if(ltp_type == 8){ segment_offset = dissect_report_segment(tvb, pinfo, ltp_tree,frame_offset); if(segment_offset == 0){ col_set_str(pinfo->cinfo, COL_INFO, "Protocol Error"); return 0; } } else if(ltp_type == 9){ segment_offset = dissect_report_ack_segment(ltp_tree,tvb,frame_offset); if(segment_offset == 0){ col_set_str(pinfo->cinfo, COL_INFO, "Protocol Error"); return 0; } } else if(ltp_type == 12 || ltp_type == 14){ segment_offset = dissect_cancel_segment(ltp_tree,tvb,frame_offset); if(segment_offset == 0){ col_set_str(pinfo->cinfo, COL_INFO, "Protocol Error"); return 0; } } frame_offset += segment_offset; /* Check to see if there are any trailer extensions */ if(trl_extn_cnt > 0){ if((unsigned)frame_offset >= tvb_length(tvb)){ col_set_str(pinfo->cinfo, COL_INFO, "Protocol Error"); return 0; } trl_extn_offset = dissect_trailer_extn(ltp_tree, tvb, frame_offset,trl_extn_cnt); if(trl_extn_offset == 0){ col_set_str(pinfo->cinfo, COL_INFO, "Protocol Error"); return 0; } } /* Return the amount of data this dissector was able to dissect */ return tvb_length(tvb); }
/* Turn SYMBOLS into a string suitable for appending onto a URL. This means that we encode special characters, and write name value pairs into a new string. A newly allocated string is returned. */ char * forms_unparse_items (Symbol **symbols) { register int i; char *result = (char *)NULL; int result_index = 0; int result_size = 0; Symbol *symbol; if (symbols == (Symbol **)NULL) return ((char *)NULL); for (i = 0; (symbol = symbols[i]) != (Symbol *)NULL; i++) { register int j; char *name = symbol_full_name (symbol); int name_len = strlen (name); for (j = 0; j < symbol->values_index; j++) { register int from, to, c; char *pair; pair = (char *)xmalloc (1 + (3 * (name_len + strlen (symbol->values[j])))); for (from = 0, to = 0; (c = (name[from])) != '\0'; from++) { if ((isalnum (c)) || (strchr (".-_@:", c) != (char *)NULL)) pair[to++] = c; else if (c == ' ') pair[to++] = '+'; else { pair[to++] = '%'; pair[to++] = hi_nibble (c); pair[to++] = lo_nibble (c); } } pair[to++] = '='; for (from = 0; (c = symbol->values[j][from]) != '\0'; from++) { if ((isalnum (c)) || (strchr (".-_@:", c) != (char *)NULL)) pair[to++] = c; else if (c == ' ') pair[to++] = '+'; else { pair[to++] = '%'; pair[to++] = hi_nibble (c); pair[to++] = lo_nibble (c); } } pair[to] = '\0'; /* Add this pair to our string. */ if ((result_index + strlen (pair) + 2) > result_size) result = (char *)xrealloc (result, (result_size += 100 + strlen (pair))); /* If there is already a pair present, separate it from this one with an ampersand. */ if (result_index != 0) result[result_index++] = '&'; strcpy (result + result_index, pair); result_index += strlen (pair); result[result_index] = '\0'; free (pair); } free (name); } return (result); }
col_clear(pinfo->cinfo, COL_INFO); ver_type = tvb_get_guint8(tvb, 0); col_add_fstr(pinfo->cinfo, COL_INFO, "Announcement (v%u)", hi_nibble(ver_type)); ti = proto_tree_add_item(tree, proto_vrrp, tvb, 0, -1, ENC_NA); vrrp_tree = proto_item_add_subtree(ti, ett_vrrp); priority = tvb_get_guint8(tvb, 2); addr_count = tvb_get_guint8(tvb, 3); tv = proto_tree_add_uint_format(vrrp_tree, hf_vrrp_ver_type, tvb, offset, 1, ver_type, "Version %u, Packet type %u (%s)", hi_nibble(ver_type), lo_nibble(ver_type), val_to_str_const(lo_nibble(ver_type), vrrp_type_vals, "Unknown")); ver_type_tree = proto_item_add_subtree(tv, ett_vrrp_ver_type); if(ver_type_tree){ proto_tree_add_uint(ver_type_tree, hf_vrrp_version, tvb, offset, 1, ver_type); proto_tree_add_uint(ver_type_tree, hf_vrrp_type, tvb, offset, 1, ver_type); offset += 1; proto_tree_add_item(vrrp_tree, hf_vrrp_virt_rtr_id, tvb, offset, 1, ENC_BIG_ENDIAN); offset += 1; proto_tree_add_uint_format(vrrp_tree, hf_vrrp_prio, tvb, offset, 1, priority, "Priority: %u (%s)", priority, val_to_str_const(priority, vrrp_prio_vals, "Non-default backup priority"));
uint8_t hi_nibble(uint8_t val) { return (val & 0xF0) >> 4; } static inline uint8_t lo_nibble(uint8_t val) { return val & 0x0F; } uint8_t PreMods__compare(const PreMods *this, uint8_t mods) { uint8_t count = 0; uint8_t lo_mods = lo_nibble(mods); uint8_t hi_mods = hi_nibble(mods); uint8_t lo_std = lo_nibble(this->std); uint8_t hi_std = hi_nibble(this->std); count += bitcount[lo_mods&lo_std]; count += bitcount[hi_mods&hi_std]; count += bitcount[((lo_mods&~lo_std)|(hi_mods&~hi_std))&lo_nibble(this->any)]; return count; } bool PreMods__is_empty(const PreMods *this) { return this->std == NONE && this->any == NONE; }