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
This commit is contained in:
parent
d205085350
commit
7a52947075
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -88,6 +88,8 @@ strptime
|
|||
; str_util.c
|
||||
ascii_strdown_inplace
|
||||
ascii_strup_inplace
|
||||
isprint_string
|
||||
isdigit_string
|
||||
|
||||
; type_util.c
|
||||
type_util_gdouble_to_guint64
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#include <glib.h>
|
||||
#include "str_util.h"
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
/* Convert all ASCII letters to lower case, in place. */
|
||||
gchar *
|
||||
ascii_strdown_inplace(gchar *str)
|
||||
|
@ -52,3 +54,39 @@ ascii_strup_inplace(gchar *str)
|
|||
|
||||
return (str);
|
||||
}
|
||||
|
||||
/* Check if an entire string is printable. */
|
||||
gboolean
|
||||
isprint_string(guchar *str)
|
||||
{
|
||||
guint pos;
|
||||
|
||||
/* Loop until we reach the end of the string (a null) */
|
||||
for(pos = 0; str[pos] != '\0'; pos++){
|
||||
if(!isprint(str[pos])){
|
||||
/* The string contains a non-printable character */
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* The string contains only printable characters */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Check if an entire string is digits. */
|
||||
gboolean
|
||||
isdigit_string(guchar *str)
|
||||
{
|
||||
guint pos;
|
||||
|
||||
/* Loop until we reach the end of the string (a null) */
|
||||
for(pos = 0; str[pos] != '\0'; pos++){
|
||||
if(!isdigit(str[pos])){
|
||||
/* The string contains a non-digit character */
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* The string contains only digits */
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -59,4 +59,18 @@ gchar *ascii_strdown_inplace(gchar *str);
|
|||
*/
|
||||
gchar *ascii_strup_inplace(gchar *str);
|
||||
|
||||
/** Check if an entire string consists of printable characters
|
||||
*
|
||||
* @param str The string to be checked
|
||||
* @return TRUE if the entire string is printable, otherwise FALSE
|
||||
*/
|
||||
gboolean isprint_string(guchar *string);
|
||||
|
||||
/** Check if an entire string consists of digits
|
||||
*
|
||||
* @param str The string to be checked
|
||||
* @return TRUE if the entire string is digits, otherwise FALSE
|
||||
*/
|
||||
gboolean isdigit_string(guchar *string);
|
||||
|
||||
#endif /* __STR_UTIL_H__ */
|
||||
|
|
Loading…
Reference in New Issue