Rawshark: Add a memory limit (-m) option.

Add an option to rawshark that lets the user set a maximum memory limit.

Change-Id: Ie102ee5f6ba5aec90a35bd63297184c7dc37662c
Reviewed-on: https://code.wireshark.org/review/19911
Reviewed-by: Gerald Combs <gerald@wireshark.org>
This commit is contained in:
Gianluca Borello 2017-01-23 08:57:32 -08:00 committed by Gerald Combs
parent c0d25e8a5d
commit 47ad059bd7
2 changed files with 29 additions and 1 deletions

View File

@ -10,6 +10,7 @@ S<[ B<-d> E<lt>encap:linktypeE<gt>|E<lt>proto:protonameE<gt> ]>
S<[ B<-F> E<lt>field to displayE<gt> ]> S<[ B<-F> E<lt>field to displayE<gt> ]>
S<[ B<-h> ]> S<[ B<-h> ]>
S<[ B<-l> ]> S<[ B<-l> ]>
S<[ B<-m> E<lt>bytesE<gt> ]>
S<[ B<-n> ]> S<[ B<-n> ]>
S<[ B<-N> E<lt>name resolving flagsE<gt> ]> S<[ B<-N> E<lt>name resolving flagsE<gt> ]>
S<[ B<-o> E<lt>preference settingE<gt> ] ...> S<[ B<-o> E<lt>preference settingE<gt> ] ...>
@ -146,6 +147,11 @@ see the dissected data for a packet as soon as B<TShark> sees the
packet and generates that output, rather than seeing it only when the packet and generates that output, rather than seeing it only when the
standard output buffer containing that data fills up. standard output buffer containing that data fills up.
=item -m E<lt>memory limit bytesE<gt>
Limit rawshark's memory usage to the specified number of bytes. POSIX
(non-Windows) only.
=item -n =item -n
Disable network object name resolution (such as hostname, TCP and UDP port Disable network object name resolution (such as hostname, TCP and UDP port

View File

@ -40,6 +40,11 @@
#include <locale.h> #include <locale.h>
#include <limits.h> #include <limits.h>
#ifndef _WIN32
#include <sys/time.h>
#include <sys/resource.h>
#endif
#ifdef HAVE_GETOPT_H #ifdef HAVE_GETOPT_H
#include <getopt.h> #include <getopt.h>
#endif #endif
@ -191,6 +196,9 @@ print_usage(FILE *output)
fprintf(output, " -d <encap:linktype>|<proto:protoname>\n"); fprintf(output, " -d <encap:linktype>|<proto:protoname>\n");
fprintf(output, " packet encapsulation or protocol\n"); fprintf(output, " packet encapsulation or protocol\n");
fprintf(output, " -F <field> field to display\n"); fprintf(output, " -F <field> field to display\n");
#ifndef _WIN32
fprintf(output, " -m virtual memory limit, in bytes \n");
#endif
fprintf(output, " -n disable all name resolution (def: all enabled)\n"); fprintf(output, " -n disable all name resolution (def: all enabled)\n");
fprintf(output, " -N <name resolve flags> enable specific name resolution(s): \"mnNtd\"\n"); fprintf(output, " -N <name resolve flags> enable specific name resolution(s): \"mnNtd\"\n");
fprintf(output, " -p use the system's packet header format\n"); fprintf(output, " -p use the system's packet header format\n");
@ -416,6 +424,8 @@ main(int argc, char *argv[])
#ifdef _WIN32 #ifdef _WIN32
WSADATA wsaData; WSADATA wsaData;
#else
struct rlimit limit;
#endif /* _WIN32 */ #endif /* _WIN32 */
char *gpf_path, *pf_path; char *gpf_path, *pf_path;
@ -438,7 +448,7 @@ main(int argc, char *argv[])
{0, 0, 0, 0 } {0, 0, 0, 0 }
}; };
#define OPTSTRING_INIT "d:F:hlnN:o:pr:R:sS:t:v" #define OPTSTRING_INIT "d:F:hlm:nN:o:pr:R:sS:t:v"
static const char optstring[] = OPTSTRING_INIT; static const char optstring[] = OPTSTRING_INIT;
@ -632,6 +642,18 @@ main(int argc, char *argv[])
and the output buffer is only flushed when it fills up). */ and the output buffer is only flushed when it fills up). */
line_buffered = TRUE; line_buffered = TRUE;
break; break;
#ifndef _WIN32
case 'm':
limit.rlim_cur = get_positive_int(optarg, "memory limit");
limit.rlim_max = get_positive_int(optarg, "memory limit");
if(setrlimit(RLIMIT_AS, &limit) != 0)
{
cmdarg_err("setrlimit() returned error");
exit(1);
}
break;
#endif
case 'n': /* No name resolution */ case 'n': /* No name resolution */
disable_name_resolution(); disable_name_resolution();
break; break;