aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-exec.c
diff options
context:
space:
mode:
authorStephen Fisher <steve@stephen-fisher.com>2012-02-17 17:22:12 +0000
committerStephen Fisher <steve@stephen-fisher.com>2012-02-17 17:22:12 +0000
commit7a5294707533166dc657a6e3373e2b30adcefefb (patch)
tree9f9cb2c3f20f77cd2cc2d854cb30cdc41102fb9b /epan/dissectors/packet-exec.c
parentd205085350663e7cb6b086226620151d8a3d868d (diff)
Move exec_isdigit_string() and exec_isprint_string() functions out of
the exec dissector and into wsutil/str_util.c. Rename them to isdigit_string() and isprint_string(). Also rename the variables they use for consistency: string -> str and position -> pos. svn path=/trunk/; revision=41053
Diffstat (limited to 'epan/dissectors/packet-exec.c')
-rw-r--r--epan/dissectors/packet-exec.c49
1 files changed, 5 insertions, 44 deletions
diff --git a/epan/dissectors/packet-exec.c b/epan/dissectors/packet-exec.c
index 9466293dd2..976d1a93e3 100644
--- a/epan/dissectors/packet-exec.c
+++ b/epan/dissectors/packet-exec.c
@@ -39,14 +39,11 @@
#include <epan/emem.h>
#include <epan/packet.h>
#include <epan/prefs.h>
+#include <wsutil/str_util.h>
/* The exec protocol uses TCP port 512 per its IANA assignment */
#define EXEC_PORT 512
-/* Forward declaration we need below */
-static gboolean exec_isprint_string(guchar *string);
-static gboolean exec_isdigit_string(guchar *string);
-
/* Variables for our preferences */
static gboolean preference_info_show_username = TRUE;
static gboolean preference_info_show_command = FALSE;
@@ -240,7 +237,7 @@ dissect_exec(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
* It is optional, so it may only be 1 character long
* (the NULL)
*/
- if(length == 1 || (exec_isdigit_string(field_stringz)
+ if(length == 1 || (isdigit_string(field_stringz)
&& length <= EXEC_STDERR_PORT_LEN)){
proto_tree_add_string(exec_tree, hf_exec_stderr_port, tvb, offset, length, (gchar*)field_stringz);
/* Next field we need */
@@ -261,7 +258,7 @@ dissect_exec(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
/* Check if this looks like the username field */
if(length != 1 && length <= EXEC_USERNAME_LEN
- && exec_isprint_string(field_stringz)){
+ && isprint_string(field_stringz)){
proto_tree_add_string(exec_tree, hf_exec_username, tvb, offset, length, (gchar*)field_stringz);
/* Store the username so we can display it in the
@@ -289,7 +286,7 @@ dissect_exec(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
/* Check if this looks like the password field */
if(length != 1 && length <= EXEC_PASSWORD_LEN
- && exec_isprint_string(field_stringz)){
+ && isprint_string(field_stringz)){
proto_tree_add_string(exec_tree, hf_exec_password, tvb, offset, length, (gchar*)field_stringz);
/* Next field we need */
@@ -312,7 +309,7 @@ dissect_exec(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
/* Check if this looks like the command field */
if(length != 1 && length <= EXEC_COMMAND_LEN
- && exec_isprint_string(field_stringz)){
+ && isprint_string(field_stringz)){
proto_tree_add_string(exec_tree, hf_exec_command, tvb, offset, length, (gchar*)field_stringz);
/* Store the username so we can display it in the
@@ -412,39 +409,3 @@ proto_reg_handoff_exec(void)
exec_handle = create_dissector_handle(dissect_exec, proto_exec);
dissector_add_uint("tcp.port", EXEC_PORT, exec_handle);
}
-
-/* Custom function to check if an entire string is printable. */
-static gboolean
-exec_isprint_string(guchar *string)
-{
- guint position;
-
- /* Loop until we reach the end of the string (a null) */
- for(position = 0; string[position] != '\0'; position++){
- if(!isprint(string[position])){
- /* The string contains a non-printable character */
- return FALSE;
- }
- }
-
- /* The string contains only printable characters */
- return TRUE;
-}
-
-/* Custom function to check if an entire string is digits. */
-static gboolean
-exec_isdigit_string(guchar *string)
-{
- guint position;
-
- /* Loop until we reach the end of the string (a null) */
- for(position = 0; string[position] != '\0'; position++){
- if(!isdigit(string[position])){
- /* The string contains a non-digit character */
- return FALSE;
- }
- }
-
- /* The string contains only digits */
- return TRUE;
-}