Make FT_IPv4 a bit more like FT_IPv6.

FT_IPv6 doesn't expose the prefix, which is used only for values in
filter expressions, not values in protocol fields; do the same for
FT_IPv4, hiding the netmask, and using fvalue_get_integer() to get the
value, having it return a network-byte-order value for the address.

(This also makes it opaque whether the address and netmask are stored in
host or network byte order.)

Change-Id: I4285a87f6ccef2c0ccec040490ddcd15d787326e
Reviewed-on: https://code.wireshark.org/review/24177
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2017-10-29 18:39:41 -07:00
parent 734c5b35a5
commit dd1c18dd03
3 changed files with 12 additions and 17 deletions

View File

@ -34,10 +34,10 @@ set_uinteger(fvalue_t *fv, guint32 value)
fv->value.ipv4.nmask = ip_get_subnet_mask(32);
}
static gpointer
static guint32
value_get(fvalue_t *fv)
{
return &(fv->value.ipv4);
return g_htonl(fv->value.ipv4.addr);
}
static gboolean
@ -234,7 +234,7 @@ ftype_register_ipv4(void)
val_repr_len, /* len_string_repr */
{ .set_value_uinteger = set_uinteger }, /* union set_value */
{ .get_value_ptr = value_get }, /* union get_value */
{ .get_value_uinteger = value_get }, /* union get_value */
cmp_eq,
cmp_ne,

View File

@ -5622,10 +5622,9 @@ proto_custom_set(proto_tree* tree, GSList *field_ids, gint occurrence,
guint32 number;
guint64 number64;
guint8 *bytes;
ipv4_addr_and_mask *ipv4;
ws_in6_addr *ipv6;
guint32 ipv4;
ws_in6_addr *ipv6;
address addr;
guint32 n_addr; /* network-order IPv4 address */
const true_false_string *tfstring;
@ -5944,9 +5943,8 @@ proto_custom_set(proto_tree* tree, GSList *field_ids, gint occurrence,
break;
case FT_IPv4:
ipv4 = (ipv4_addr_and_mask *)fvalue_get(&finfo->value);
n_addr = g_ntohl(ipv4->addr);
set_address (&addr, AT_IPv4, 4, &n_addr);
ipv4 = fvalue_get_uinteger(&finfo->value);
set_address (&addr, AT_IPv4, 4, &ipv4);
address_to_str_buf(&addr, result+offset_r, size-offset_r);
offset_r = (int)strlen(result);
break;
@ -8130,9 +8128,8 @@ proto_item_fill_label(field_info *fi, gchar *label_str)
guint8 *bytes;
guint32 integer;
guint64 integer64;
ipv4_addr_and_mask *ipv4;
guint32 ipv4;
e_guid_t *guid;
guint32 n_addr; /* network-order IPv4 address */
gchar *name;
address addr;
char *addr_str;
@ -8365,12 +8362,11 @@ proto_item_fill_label(field_info *fi, gchar *label_str)
break;
case FT_IPv4:
ipv4 = (ipv4_addr_and_mask *)fvalue_get(&fi->value);
n_addr = g_htonl(ipv4->addr);
ipv4 = fvalue_get_uinteger(&fi->value);
addr.type = AT_IPv4;
addr.len = 4;
addr.data = &n_addr;
addr.data = &ipv4;
if (hfinfo->display == BASE_NETMASK)
{

View File

@ -615,14 +615,13 @@ new_finfo_window(GtkWidget *w, struct FieldinfoWinData *DataPtr)
g_signal_connect(fvalue_edit, "toggled", G_CALLBACK(finfo_boolean_changed), DataPtr);
} else if (finfo_type == FT_IPv4) {
ipv4_addr_and_mask *ipv4 = (ipv4_addr_and_mask *)fvalue_get(&finfo->value);
guint32 net_addr = g_htonl(ipv4->addr);
guint32 ipv4 = fvalue_get_uinteger(&finfo->value);
#if GTK_CHECK_VERSION(3,0,0)
GtkAdjustment *adj;
#else
GtkObject *adj;
#endif
adj = gtk_adjustment_new((double) (GUINT32_FROM_BE(net_addr)), 0.0, 4294967295.0 /* (2^32)-1 */, 1.0, 256.0, 0);
adj = gtk_adjustment_new((double) (GUINT32_FROM_BE(ipv4)), 0.0, 4294967295.0 /* (2^32)-1 */, 1.0, 256.0, 0);
/* XXX, create four gtk_spin_button_new which takes 0..255 */
fvalue_edit = gtk_spin_button_new(GTK_ADJUSTMENT(adj), 1.0, 0);