/* packet-ip.c
* Routines for IP and miscellaneous IP protocol packet disassembly
*
- * $Id: packet-ip.c,v 1.197 2003/08/28 04:19:28 guy Exp $
+ * $Id: packet-ip.c,v 1.202 2004/02/18 06:43:00 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
static int hf_ip_src = -1;
static int hf_ip_addr = -1;
static int hf_ip_flags = -1;
+static int hf_ip_flags_rf = -1;
static int hf_ip_flags_df = -1;
static int hf_ip_flags_mf = -1;
static int hf_ip_frag_offset = -1;
static int hf_icmp_code = -1;
static int hf_icmp_checksum = -1;
static int hf_icmp_checksum_bad = -1;
+static int hf_icmp_ident = -1;
+static int hf_icmp_seq_num = -1;
+static int hf_icmp_mtu = -1;
+static int hf_icmp_redir_gw = -1;
+
/* Mobile ip */
static int hf_icmp_mip_type = -1;
#define IPH_MIN_LEN 20
/* IP flags. */
-#define IP_CE 0x8000 /* Flag: "Congestion" */
+#define IP_RF 0x8000 /* Flag: "Reserved bit" */
#define IP_DF 0x4000 /* Flag: "Don't Fragment" */
#define IP_MF 0x2000 /* Flag: "More Fragments" */
#define IP_OFFSET 0x1FFF /* "Fragment Offset" part */
{
proto_tree *ip_tree = NULL, *field_tree;
proto_item *ti = NULL, *tf;
+ guint32 addr;
int offset = 0;
guint hlen, optlen;
guint16 flags;
iph->ip_off = tvb_get_ntohs(tvb, offset + 6);
if (tree) {
- flags = (iph->ip_off & (IP_DF|IP_MF)) >> 12;
+ flags = (iph->ip_off & (IP_RF | IP_DF | IP_MF)) >> 12;
tf = proto_tree_add_uint(ip_tree, hf_ip_flags, tvb, offset + 6, 1, flags);
field_tree = proto_item_add_subtree(tf, ett_ip_off);
- proto_tree_add_boolean(field_tree, hf_ip_flags_df, tvb, offset + 6, 1, flags),
- proto_tree_add_boolean(field_tree, hf_ip_flags_mf, tvb, offset + 6, 1, flags),
+ proto_tree_add_boolean(field_tree, hf_ip_flags_rf, tvb, offset + 6, 1, flags);
+ proto_tree_add_boolean(field_tree, hf_ip_flags_df, tvb, offset + 6, 1, flags);
+ proto_tree_add_boolean(field_tree, hf_ip_flags_mf, tvb, offset + 6, 1, flags);
proto_tree_add_uint(ip_tree, hf_ip_frag_offset, tvb, offset + 6, 2,
(iph->ip_off & IP_OFFSET)*8);
SET_ADDRESS(&pinfo->src, AT_IPv4, 4, tvb_get_ptr(tvb, offset + IPH_SRC, 4));
SET_ADDRESS(&iph->ip_src, AT_IPv4, 4, tvb_get_ptr(tvb, offset + IPH_SRC, 4));
if (tree) {
+ memcpy(&addr, iph->ip_src.data, 4);
if (ip_summary_in_tree) {
proto_item_append_text(ti, ", Src Addr: %s (%s)",
- get_hostname((guint)(*((guint *)iph->ip_src.data))), ip_to_str((guint8 *) iph->ip_src.data));
+ get_hostname(addr), ip_to_str((guint8 *) iph->ip_src.data));
}
- proto_tree_add_ipv4(ip_tree, hf_ip_src, tvb, offset + 12, 4, (guint)(*((guint *)iph->ip_src.data)));
- proto_tree_add_ipv4_hidden(ip_tree, hf_ip_addr, tvb, offset + 12, 4, (guint)(*((guint *)iph->ip_src.data)));
+ proto_tree_add_ipv4(ip_tree, hf_ip_src, tvb, offset + 12, 4, addr);
+ proto_tree_add_ipv4_hidden(ip_tree, hf_ip_addr, tvb, offset + 12, 4, addr);
}
SET_ADDRESS(&pinfo->net_dst, AT_IPv4, 4, tvb_get_ptr(tvb, offset + IPH_DST, 4));
SET_ADDRESS(&iph->ip_dst, AT_IPv4, 4, tvb_get_ptr(tvb, offset + IPH_DST, 4));
if (tree) {
+ memcpy(&addr, iph->ip_dst.data, 4);
if (ip_summary_in_tree) {
proto_item_append_text(ti, ", Dst Addr: %s (%s)",
- get_hostname((guint)(*((guint *)iph->ip_dst.data))), ip_to_str((guint8 *) iph->ip_dst.data));
+ get_hostname(addr), ip_to_str((guint8 *) iph->ip_dst.data));
}
- proto_tree_add_ipv4(ip_tree, hf_ip_dst, tvb, offset + 16, 4, (guint)(*((guint *)iph->ip_dst.data)));
- proto_tree_add_ipv4_hidden(ip_tree, hf_ip_addr, tvb, offset + 16, 4, (guint)(*((guint *)iph->ip_dst.data)));
+ proto_tree_add_ipv4(ip_tree, hf_ip_dst, tvb, offset + 16, 4, addr);
+ proto_tree_add_ipv4_hidden(ip_tree, hf_ip_addr, tvb, offset + 16, 4, addr);
}
if (tree) {
#define N_REDIRECT (sizeof redir_str / sizeof redir_str[0])
-static const gchar *ttl_str[] = {"TTL equals 0 during transit",
- "TTL equals 0 during reassembly"};
+static const gchar *ttl_str[] = {"Time to live exceeded in transit",
+ "Fragment reassembly time exceeded"};
#define N_TIMXCEED (sizeof ttl_str / sizeof ttl_str[0])
case ICMP_IREQREPLY:
case ICMP_MASKREQ:
case ICMP_MASKREPLY:
- proto_tree_add_text(icmp_tree, tvb, 4, 2, "Identifier: 0x%04x",
- tvb_get_ntohs(tvb, 4));
- proto_tree_add_text(icmp_tree, tvb, 6, 2, "Sequence number: %02x:%02x",
- tvb_get_guint8(tvb, 6), tvb_get_guint8(tvb, 7));
+ proto_tree_add_item(icmp_tree, hf_icmp_ident, tvb, 4, 2, FALSE);
+ proto_tree_add_item(icmp_tree, hf_icmp_seq_num, tvb, 6, 2, FALSE);
break;
case ICMP_UNREACH:
switch (icmp_code) {
case ICMP_FRAG_NEEDED:
- proto_tree_add_text(icmp_tree, tvb, 6, 2, "MTU of next hop: %u",
- tvb_get_ntohs(tvb, 6));
+ proto_tree_add_item(icmp_tree, hf_icmp_mtu, tvb, 6, 2, FALSE);
break;
}
break;
break;
case ICMP_REDIRECT:
- proto_tree_add_text(icmp_tree, tvb, 4, 4, "Gateway address: %s",
- ip_to_str(tvb_get_ptr(tvb, 4, 4)));
+ proto_tree_add_item(icmp_tree, hf_icmp_redir_gw, tvb, 4, 4, FALSE);
break;
}
{ "Flags", "ip.flags", FT_UINT8, BASE_HEX, NULL, 0x0,
"", HFILL }},
+ { &hf_ip_flags_rf,
+ { "Reserved bit", "ip.flags.rb", FT_BOOLEAN, 4, TFS(&flags_set_truth), IP_RF >> 12,
+ "", HFILL }},
+
{ &hf_ip_flags_df,
- { "Don't fragment", "ip.flags.df", FT_BOOLEAN, 4, TFS(&flags_set_truth), IP_DF>>12,
+ { "Don't fragment", "ip.flags.df", FT_BOOLEAN, 4, TFS(&flags_set_truth), IP_DF >> 12,
"", HFILL }},
{ &hf_ip_flags_mf,
- { "More fragments", "ip.flags.mf", FT_BOOLEAN, 4, TFS(&flags_set_truth), IP_MF>>12,
+ { "More fragments", "ip.flags.mf", FT_BOOLEAN, 4, TFS(&flags_set_truth), IP_MF >> 12,
"", HFILL }},
{ &hf_ip_frag_offset,
{ "Bad Checksum", "icmp.checksum_bad", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
"", HFILL }},
+ { &hf_icmp_ident,
+ {"Identifier", "icmp.ident", FT_UINT16, BASE_HEX, NULL, 0x0,
+ "", HFILL }},
+
+ { &hf_icmp_seq_num,
+ {"Sequence number", "icmp.seq", FT_UINT16, BASE_HEX, NULL, 0x0,
+ "", HFILL }},
+
+ { &hf_icmp_mtu,
+ {"MTU of next hop", "icmp.mtu", FT_UINT16, BASE_DEC, NULL, 0x0,
+ "", HFILL}},
+
+ { &hf_icmp_redir_gw,
+ {"Gateway address", "icmp.redir_gw", FT_IPv4, BASE_NONE, NULL, 0x0,
+ "", HFILL }},
+
{ &hf_icmp_mip_type,
{ "Extension Type", "icmp.mip.type", FT_UINT8, BASE_DEC,
VALS(mip_extensions), 0x0,"", HFILL}},