aboutsummaryrefslogtreecommitdiffstats
path: root/packet-ppp.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2003-06-12 08:33:32 +0000
committerGuy Harris <guy@alum.mit.edu>2003-06-12 08:33:32 +0000
commitee97ce31966f61de148ad85cb229e76a88801b02 (patch)
tree22f7363da150c57eb593a2e5871033e8b8585437 /packet-ppp.c
parent04a87185285865ae91f903662c4bc721f66c8d88 (diff)
downloadwireshark-ee97ce31966f61de148ad85cb229e76a88801b02.tar.gz
wireshark-ee97ce31966f61de148ad85cb229e76a88801b02.tar.bz2
wireshark-ee97ce31966f61de148ad85cb229e76a88801b02.zip
Add new routines:
tvb_get_string() - takes a tvbuff, an offset, and a length as arguments, allocates a buffer big enough to hold a string with the specified number of bytes plus an added null terminator (i.e., length+1), copies the specified number of bytes from the tvbuff, at the specified offset, to that buffer and puts in a null terminator, and returns a pointer to that buffer (or throws an exception before allocating the buffer if that many bytes aren't available in the tvbuff); tvb_get_stringz() - takes a tvbuff, an offset, and a pointer to a "gint" as arguments, gets the size of the null-terminated string starting at the specified offset in the tvbuff (throwing an exception if the null terminator isn't found), allocates a buffer big enough to hold that string, copies the string to that buffer, and returns a pointer to that buffer and stores the length of the string (including the terminating null) in the variable pointed to by the "gint" pointer. Replace many pieces of code allocating a buffer and copying a string with calls to "tvb_get_string()" (for one thing, "tvb_get_string()" doesn't require you to remember that the argument to "tvb_get_nstringz0()" is the size of the buffer into which you're copying the string, which might be the length of the string to be copied *plus 1*). Don't use fixed-length buffers for null-terminated strings (even if the code that generates those packets has a #define to limit the length of the string). Use "tvb_get_stringz()", instead. In some cases where a value is fetched but is only used to pass an argument to a "proto_tree_add_XXX" routine, use "proto_tree_add_item()" instead. svn path=/trunk/; revision=7859
Diffstat (limited to 'packet-ppp.c')
-rw-r--r--packet-ppp.c66
1 files changed, 46 insertions, 20 deletions
diff --git a/packet-ppp.c b/packet-ppp.c
index b94d9bf145..73d94f0ac8 100644
--- a/packet-ppp.c
+++ b/packet-ppp.c
@@ -1,7 +1,8 @@
/* packet-ppp.c
* Routines for ppp packet disassembly
+ * RFC 1661, RFC 1662
*
- * $Id: packet-ppp.c,v 1.111 2003/05/19 03:23:11 gerald Exp $
+ * $Id: packet-ppp.c,v 1.112 2003/06/12 08:33:29 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -295,7 +296,7 @@ const value_string ppp_vals[] = {
{PPP_SPAP, "Shiva Password Authentication Protocol" },
{PPP_CBCP, "Callback Control Protocol" },
{PPP_BACP, "Bandwidth Allocation Control Protocol" },
- {PPP_BAP, "Bandwitdh Allocation Protocol" },
+ {PPP_BAP, "Bandwidth Allocation Protocol" },
{PPP_CONTCP, "Container Control Protocol" },
{PPP_CHAP, "Challenge Handshake Authentication Protocol" },
{PPP_RSAAP, "RSA Authentication Protocol" },
@@ -2095,9 +2096,7 @@ dissect_cbcp_callback_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
proto_item *ta;
proto_tree *addr_tree;
guint8 addr_type;
- gint addr_len;
- guint8 buf[256]; /* Since length field in Callback Conf Option is
- 8 bits, 256-octet buf is large enough. */
+ guint addr_len;
tf = proto_tree_add_text(tree, tvb, offset, length, "%s", optp->name);
field_tree = proto_item_add_subtree(tf, *optp->subtree_index);
@@ -2117,9 +2116,12 @@ dissect_cbcp_callback_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
((addr_type == 1) ? "PSTN/ISDN" : "Other"), addr_type);
offset++;
length--;
- addr_len = tvb_get_nstringz0(tvb, offset, sizeof(buf), buf);
- proto_tree_add_text(addr_tree, tvb, offset, addr_len + 1,
- "Address: %s", buf);
+ addr_len = tvb_strsize(tvb, offset);
+ proto_tree_add_text(addr_tree, tvb, offset, addr_len,
+ "Address: %s",
+ addr_len == 1 ?
+ "" :
+ tvb_format_text(tvb, offset, addr_len - 1));
offset += (addr_len + 1);
length -= (addr_len + 1);
}
@@ -2171,8 +2173,6 @@ dissect_bap_phone_delta_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
proto_tree *suboption_tree;
guint8 subopt_type;
guint8 subopt_len;
- guint8 buf[256]; /* Since Sub-Option length field in BAP Phone-Delta
- Option is 8 bits, 256-octets buf is large enough */
tf = proto_tree_add_text(tree, tvb, offset, length, "%s", optp->name);
field_tree = proto_item_add_subtree(tf, *optp->subtree_index);
@@ -2203,9 +2203,9 @@ dissect_bap_phone_delta_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
break;
case BAP_PHONE_DELTA_SUBOPT_SUBSC_NUM:
if (subopt_len > 2) {
- tvb_get_nstringz0(tvb, offset + 2, subopt_len - 2, buf);
proto_tree_add_text(suboption_tree, tvb, offset + 2, subopt_len - 2,
- "Subscriber Number: %s", buf);
+ "Subscriber Number: %s",
+ tvb_format_text(tvb, offset + 2, subopt_len - 2));
} else {
proto_tree_add_text(suboption_tree, tvb, offset + 1, 1,
"Invalid suboption length: %u", subopt_len);
@@ -2213,9 +2213,9 @@ dissect_bap_phone_delta_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
break;
case BAP_PHONE_DELTA_SUBOPT_PHONENUM_SUBADDR:
if (subopt_len > 2) {
- tvb_get_nstringz0(tvb, offset + 2, subopt_len - 2, buf);
proto_tree_add_text(suboption_tree, tvb, offset + 2, subopt_len - 2,
- "Phone Number Sub Address: %s", buf);
+ "Phone Number Sub Address: %s",
+ tvb_format_text(tvb, offset + 2, subopt_len - 2));
}
break;
default:
@@ -2233,13 +2233,10 @@ dissect_bap_reason_opt(const ip_tcp_opt *optp, tvbuff_t *tvb,
int offset, guint length, packet_info *pinfo _U_,
proto_tree *tree)
{
- guint8 buf[256]; /* Since length field in BAP Reason Option is
- 8 bits, 256-octets buf is large enough */
-
if (length > 2) {
- tvb_get_nstringz0(tvb, offset + 2, length - 2, buf);
proto_tree_add_text(tree, tvb, offset, length, "%s: %s",
- optp->name, buf);
+ optp->name,
+ tvb_format_text(tvb, offset + 2, length - 2));
}
}
@@ -2474,6 +2471,9 @@ dissect_lcp_options(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
-1, pinfo, tree);
}
+/*
+ * RFC 1661.
+ */
static void
dissect_lcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
@@ -2481,6 +2481,9 @@ dissect_lcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
lcp_opts, N_LCP_OPTS, pinfo, tree);
}
+/*
+ * RFC 1332.
+ */
static void
dissect_ipcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
@@ -2488,6 +2491,9 @@ dissect_ipcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
ipcp_opts, N_IPCP_OPTS, pinfo, tree);
}
+/*
+ * RFC 1962.
+ */
static void
dissect_ccp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
@@ -2495,6 +2501,11 @@ dissect_ccp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
ccp_opts, N_CCP_OPTS, pinfo, tree);
}
+/*
+ * Callback Control Protocol - see
+ *
+ * http://www.linet.gr.jp/~manabe/PPxP/doc/Standards/draft-gidwani-ppp-callback-cp-00.txt
+ */
static void
dissect_cbcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
@@ -2502,6 +2513,9 @@ dissect_cbcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
cbcp_opts, N_CBCP_OPTS, pinfo, tree);
}
+/*
+ * RFC 2125 (BACP and BAP).
+ */
static void
dissect_bacp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
@@ -2512,7 +2526,6 @@ dissect_bacp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
static void
dissect_bap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
-
proto_item *ti;
proto_tree *fh_tree = NULL;
proto_item *tf;
@@ -2590,6 +2603,9 @@ dissect_comp_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
}
}
+/*
+ * RFC 3153 (both PPPMuxCP and PPPMux).
+ */
static void
dissect_pppmuxcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
@@ -2697,6 +2713,9 @@ dissect_pppmux(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
} /* if tree */
}
+/*
+ * RFC 3032.
+ */
static void
dissect_mplscp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
@@ -2704,6 +2723,10 @@ dissect_mplscp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
NULL, 0, pinfo, tree);
}
+/*
+ * Cisco Discovery Protocol Control Protocol.
+ * XXX - where is this documented?
+ */
static void
dissect_cdpcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
@@ -3193,6 +3216,9 @@ dissect_chap( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree ) {
}
}
+/*
+ * RFC 2472.
+ */
static void
dissect_ipv6cp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{