Tvbuffify the DNS, NBNS, NBDS, and NBSS dissectors.

Add a "tvb_memeql()" routine, for doing "memcmp()"-style equality
comparisons.

svn path=/trunk/; revision=3631
This commit is contained in:
Guy Harris 2001-07-02 07:11:40 +00:00
parent e78964cea0
commit db5e1b8c85
6 changed files with 754 additions and 1313 deletions

View File

@ -9,7 +9,7 @@
* the data of a backing tvbuff, or can be a composite of
* other tvbuffs.
*
* $Id: tvbuff.c,v 1.17 2001/05/27 21:34:05 guy Exp $
* $Id: tvbuff.c,v 1.18 2001/07/02 07:11:40 guy Exp $
*
* Copyright (c) 2000 by Gilbert Ramirez <gram@xiexie.org>
*
@ -1217,7 +1217,10 @@ tvb_strnlen(tvbuff_t *tvb, gint offset, guint maxlength)
* Implement strneql etc
*/
/* Call strncmp after checking if enough chars left, otherwise return -1 */
/*
* Call strncmp after checking if enough chars left, returning 0 if
* it returns 0 (meaning "equal") and -1 otherwise, otherwise return -1.
*/
gint
tvb_strneql(tvbuff_t *tvb, gint offset, const guint8 *str, gint size)
{
@ -1241,7 +1244,10 @@ tvb_strneql(tvbuff_t *tvb, gint offset, const guint8 *str, gint size)
}
}
/* Call strncasecmp after checking if enough chars left, otherwise return -1 */
/*
* Call strncasecmp after checking if enough chars left, returning 0 if
* it returns 0 (meaning "equal") and -1 otherwise, otherwise return -1.
*/
gint
tvb_strncaseeql(tvbuff_t *tvb, gint offset, const guint8 *str, gint size)
{
@ -1265,6 +1271,33 @@ tvb_strncaseeql(tvbuff_t *tvb, gint offset, const guint8 *str, gint size)
}
}
/*
* Call memcmp after checking if enough chars left, returning 0 if
* it returns 0 (meaning "equal") and -1 otherwise, otherwise return -1.
*/
gint
tvb_memeql(tvbuff_t *tvb, gint offset, const guint8 *str, gint size)
{
guint8 *ptr;
ptr = ensure_contiguous(tvb, offset, size);
if (ptr) {
int cmp = memcmp(ptr, str, size);
/*
* Return 0 if equal, -1 otherwise.
*/
return (cmp == 0 ? 0 : -1);
} else {
/*
* Not enough characters in the tvbuff to match the
* string.
*/
return -1;
}
}
/*
* Format the data in the tvb from offset for length ...
*/

View File

@ -9,7 +9,7 @@
* the data of a backing tvbuff, or can be a composite of
* other tvbuffs.
*
* $Id: tvbuff.h,v 1.13 2001/05/27 21:34:05 guy Exp $
* $Id: tvbuff.h,v 1.14 2001/07/02 07:11:40 guy Exp $
*
* Copyright (c) 2000 by Gilbert Ramirez <gram@xiexie.org>
*
@ -351,12 +351,24 @@ gint tvb_find_line_end(tvbuff_t *tvb, gint offset, int len, gint *eol);
gint tvb_find_line_end_unquoted(tvbuff_t *tvb, gint offset, int len,
gint *next_offset);
/* Call strncmp after checking if enough chars left, otherwise return -1 */
/*
* Call strncmp after checking if enough chars left, returning 0 if
* it returns 0 (meaning "equal") and -1 otherwise, otherwise return -1.
*/
gint tvb_strneql(tvbuff_t *tvb, gint offset, const guint8 *str, gint size);
/* Call strncasecmp after checking if enough chars left, otherwise return -1 */
/*
* Call strncasecmp after checking if enough chars left, returning 0 if
* it returns 0 (meaning "equal") and -1 otherwise, otherwise return -1.
*/
gint tvb_strncaseeql(tvbuff_t *tvb, gint offset, const guint8 *str, gint size);
/*
* Call memcmp after checking if enough chars left, returning 0 if
* it returns 0 (meaning "equal") and -1 otherwise, otherwise return -1.
*/
gint tvb_memeql(tvbuff_t *tvb, gint offset, const guint8 *str, gint size);
/*
* Format a bunch of data from a tvbuff as bytes, returning a pointer
* to the string with the formatted data.

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
* Definitions for packet disassembly structures and routines used both by
* DNS and NBNS.
*
* $Id: packet-dns.h,v 1.9 2000/08/22 08:28:45 itojun Exp $
* $Id: packet-dns.h,v 1.10 2001/07/02 07:11:39 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -30,12 +30,12 @@
char *dns_class_name(int class);
int get_dns_name(const u_char *, int, int, char *, int);
int get_dns_name(tvbuff_t *, int, int, char *, int);
#define MAXDNAME 1025 /* maximum domain name length */
proto_tree *
add_rr_to_tree(proto_item *, int, int, const char *,
add_rr_to_tree(proto_item *, int, tvbuff_t *, int, const char *,
int, const char *, const char *, u_int, u_short);
#endif /* packet-dns.h */

View File

@ -1,7 +1,7 @@
/* packet-icmpv6.c
* Routines for ICMPv6 packet disassembly
*
* $Id: packet-icmpv6.c,v 1.47 2001/06/18 02:17:46 guy Exp $
* $Id: packet-icmpv6.c,v 1.48 2001/07/02 07:11:39 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -472,8 +472,6 @@ dissect_nodeinfo(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree
guint16 flags;
char dname[MAXDNAME];
guint8 ipaddr[4];
const u_char *pd;
int top_level_offset;
ni = &icmp6_nodeinfo;
tvb_memcpy(tvb, (guint8 *)ni, offset, sizeof *ni);
@ -582,11 +580,8 @@ dissect_nodeinfo(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree
off = tvb_length_remaining(tvb, offset);
break;
case ICMP6_NI_SUBJ_FQDN:
/* XXXX - clean this up when packet-dns.c has been tvbuffified */
tvb_compat(tvb, &pd, &top_level_offset);
l = get_dns_name(pd, top_level_offset + offset + sizeof(*ni),
top_level_offset + offset + sizeof(*ni),
dname, sizeof(dname));
l = get_dns_name(tvb, offset + sizeof(*ni),
offset + sizeof(*ni), dname, sizeof(dname));
if (tvb_bytes_exist(tvb, offset + sizeof(*ni) + l, 1) &&
tvb_get_guint8(tvb, offset + sizeof(*ni) + l) == 0) {
l++;
@ -663,15 +658,13 @@ dissect_nodeinfo(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree
tvb_length_remaining(tvb, offset),
"DNS labels");
field_tree = proto_item_add_subtree(tf, ett_nodeinfo_nodedns);
/* XXXX - clean this up when packet-dns.c has been tvbuffified */
tvb_compat(tvb, &pd, &top_level_offset);
j = offset + sizeof (*ni) + sizeof(guint32);
while (j < tvb_length(tvb)) {
l = get_dns_name(pd, top_level_offset + j,
top_level_offset + offset + sizeof (*ni) + sizeof(guint32),
l = get_dns_name(tvb, j,
offset + sizeof (*ni) + sizeof(guint32),
dname,sizeof(dname));
if (tvb_bytes_exist(tvb, top_level_offset + j + l, 1) &&
tvb_get_guint8(tvb, top_level_offset + j + l) == 0) {
if (tvb_bytes_exist(tvb, j + l, 1) &&
tvb_get_guint8(tvb, j + l) == 0) {
l++;
proto_tree_add_text(field_tree, tvb, j, l,
"DNS label: %s (truncated)", dname);

File diff suppressed because it is too large Load Diff