forked from osmocom/wireshark
Add get_ routines to get a guint32, and use them.
By analogy to get_natural_int() and get_positive_int(), add routines to get a guint32 and to get a non-zero guint32, doing all the necessary error checks, and use it. Change-Id: I65a9ac8a3d136886df3588806ae7af5bdc7b8cb6 Reviewed-on: https://code.wireshark.org/review/17586 Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
parent
132632bcd9
commit
e09b03e9b1
41
editcap.c
41
editcap.c
|
@ -286,10 +286,7 @@ add_selection(char *sel, guint* max_selection)
|
||||||
fprintf(stderr, "Not inclusive ...");
|
fprintf(stderr, "Not inclusive ...");
|
||||||
|
|
||||||
selectfrm[max_selected].inclusive = FALSE;
|
selectfrm[max_selected].inclusive = FALSE;
|
||||||
if (!ws_strtou32(sel, NULL, &selectfrm[max_selected].first)) {
|
selectfrm[max_selected].first = get_guint32(sel, "packet number");
|
||||||
fprintf(stderr, "editcap: invalid integer conversion: %s\n", sel);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
if (selectfrm[max_selected].first > *max_selection)
|
if (selectfrm[max_selected].first > *max_selection)
|
||||||
*max_selection = selectfrm[max_selected].first;
|
*max_selection = selectfrm[max_selected].first;
|
||||||
|
|
||||||
|
@ -301,14 +298,8 @@ add_selection(char *sel, guint* max_selection)
|
||||||
|
|
||||||
next = locn + 1;
|
next = locn + 1;
|
||||||
selectfrm[max_selected].inclusive = TRUE;
|
selectfrm[max_selected].inclusive = TRUE;
|
||||||
if (!ws_strtou32(sel, NULL, &selectfrm[max_selected].first)) {
|
selectfrm[max_selected].first = get_guint32(sel, "beginning of packet range");
|
||||||
fprintf(stderr, "editcap: invalid integer conversion: %s\n", sel);
|
selectfrm[max_selected].second = get_guint32(sel, "end of packet range");
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
if (!ws_strtou32(next, NULL, &selectfrm[max_selected].first)) {
|
|
||||||
fprintf(stderr, "editcap: invalid integer conversion: %s\n", sel);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selectfrm[max_selected].second == 0)
|
if (selectfrm[max_selected].second == 0)
|
||||||
{
|
{
|
||||||
|
@ -1113,11 +1104,7 @@ main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'c':
|
case 'c':
|
||||||
if (!ws_strtou32(optarg, NULL, &split_packet_count) || split_packet_count == 0) {
|
split_packet_count = get_nonzero_guint32(optarg, "packet count");
|
||||||
fprintf(stderr, "editcap: \"%s\" isn't a valid packet count\n",
|
|
||||||
optarg);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'C':
|
case 'C':
|
||||||
|
@ -1165,7 +1152,8 @@ main(int argc, char *argv[])
|
||||||
case 'D':
|
case 'D':
|
||||||
dup_detect = TRUE;
|
dup_detect = TRUE;
|
||||||
dup_detect_by_time = FALSE;
|
dup_detect_by_time = FALSE;
|
||||||
if (!ws_strtou32(optarg, NULL, &dup_window) || dup_window > MAX_DUP_DEPTH) {
|
dup_window = get_guint32(optarg, "duplicate window");
|
||||||
|
if (dup_window > MAX_DUP_DEPTH) {
|
||||||
fprintf(stderr, "editcap: \"%d\" duplicate window value must be between 0 and %d inclusive.\n",
|
fprintf(stderr, "editcap: \"%d\" duplicate window value must be between 0 and %d inclusive.\n",
|
||||||
dup_window, MAX_DUP_DEPTH);
|
dup_window, MAX_DUP_DEPTH);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -1214,10 +1202,7 @@ main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'o':
|
case 'o':
|
||||||
if (!ws_strtou32(optarg, NULL, &change_offset) || change_offset == 0) {
|
change_offset = get_nonzero_guint32(optarg, "change offset");
|
||||||
fprintf(stderr, "editcap: invalid offset %s\n", optarg);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r':
|
case 'r':
|
||||||
|
@ -1225,11 +1210,7 @@ main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
if (!ws_strtou32(optarg, NULL, &snaplen)) {
|
snaplen = get_nonzero_guint32(optarg, "snapshot length");
|
||||||
fprintf(stderr, "editcap: \"%s\" isn't a valid snapshot length\n",
|
|
||||||
optarg);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'S':
|
case 'S':
|
||||||
|
@ -1413,7 +1394,7 @@ main(int argc, char *argv[])
|
||||||
if (nstime_is_unset(&block_start)) {
|
if (nstime_is_unset(&block_start)) {
|
||||||
block_start = phdr->ts;
|
block_start = phdr->ts;
|
||||||
}
|
}
|
||||||
if (secs_per_block > 0) {
|
if (secs_per_block != 0) {
|
||||||
while ((phdr->ts.secs - block_start.secs > secs_per_block)
|
while ((phdr->ts.secs - block_start.secs > secs_per_block)
|
||||||
|| (phdr->ts.secs - block_start.secs == secs_per_block
|
|| (phdr->ts.secs - block_start.secs == secs_per_block
|
||||||
&& phdr->ts.nsecs >= block_start.nsecs )) { /* time for the next file */
|
&& phdr->ts.nsecs >= block_start.nsecs )) { /* time for the next file */
|
||||||
|
@ -1444,9 +1425,9 @@ main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
} /* time stamp handling */
|
} /* time stamp handling */
|
||||||
|
|
||||||
if (split_packet_count > 0) {
|
if (split_packet_count != 0) {
|
||||||
/* time for the next file? */
|
/* time for the next file? */
|
||||||
if (written_count > 0 && written_count % split_packet_count == 0) {
|
if (written_count > 0 && (written_count % split_packet_count) == 0) {
|
||||||
if (!wtap_dump_close(pdh, &write_err)) {
|
if (!wtap_dump_close(pdh, &write_err)) {
|
||||||
fprintf(stderr, "editcap: Error writing to %s: %s\n",
|
fprintf(stderr, "editcap: Error writing to %s: %s\n",
|
||||||
filename, wtap_strerror(write_err));
|
filename, wtap_strerror(write_err));
|
||||||
|
|
|
@ -56,7 +56,6 @@ get_natural_int(const char *string, const char *name)
|
||||||
return (int)number;
|
return (int)number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
get_positive_int(const char *string, const char *name)
|
get_positive_int(const char *string, const char *name)
|
||||||
{
|
{
|
||||||
|
@ -72,6 +71,39 @@ get_positive_int(const char *string, const char *name)
|
||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
guint32
|
||||||
|
get_guint32(const char *string, const char *name)
|
||||||
|
{
|
||||||
|
const char *end;
|
||||||
|
guint32 number;
|
||||||
|
|
||||||
|
if (!ws_strtou32(string, &end, &number)) {
|
||||||
|
if (errno == EINVAL || *end != '\0') {
|
||||||
|
cmdarg_err("The specified %s \"%s\" isn't a decimal number", name, string);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
cmdarg_err("The specified %s \"%s\" is too large (greater than %d)",
|
||||||
|
name, string, number);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
|
||||||
|
guint32
|
||||||
|
get_nonzero_guint32(const char *string, const char *name)
|
||||||
|
{
|
||||||
|
guint32 number;
|
||||||
|
|
||||||
|
number = get_guint32(string, name);
|
||||||
|
|
||||||
|
if (number == 0) {
|
||||||
|
cmdarg_err("The specified %s is zero", name);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
||||||
*
|
*
|
||||||
|
|
|
@ -35,6 +35,12 @@ get_natural_int(const char *string, const char *name);
|
||||||
WS_DLL_PUBLIC int
|
WS_DLL_PUBLIC int
|
||||||
get_positive_int(const char *string, const char *name);
|
get_positive_int(const char *string, const char *name);
|
||||||
|
|
||||||
|
WS_DLL_PUBLIC guint32
|
||||||
|
get_guint32(const char *string, const char *name);
|
||||||
|
|
||||||
|
WS_DLL_PUBLIC guint32
|
||||||
|
get_nonzero_guint32(const char *string, const char *name);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
Loading…
Reference in New Issue