diff --git a/doc/rawshark.pod b/doc/rawshark.pod index 6f04e2b078..c2c722a2bb 100644 --- a/doc/rawshark.pod +++ b/doc/rawshark.pod @@ -10,6 +10,7 @@ S<[ B<-d> Eencap:linktypeE|Eproto:protonameE ]> S<[ B<-F> Efield to displayE ]> S<[ B<-h> ]> S<[ B<-l> ]> +S<[ B<-m> EbytesE ]> S<[ B<-n> ]> S<[ B<-N> Ename resolving flagsE ]> S<[ B<-o> Epreference settingE ] ...> @@ -146,6 +147,11 @@ see the dissected data for a packet as soon as B sees the packet and generates that output, rather than seeing it only when the standard output buffer containing that data fills up. +=item -m Ememory limit bytesE + +Limit rawshark's memory usage to the specified number of bytes. POSIX +(non-Windows) only. + =item -n Disable network object name resolution (such as hostname, TCP and UDP port diff --git a/rawshark.c b/rawshark.c index af607044ac..df4a7b360d 100644 --- a/rawshark.c +++ b/rawshark.c @@ -40,6 +40,11 @@ #include #include +#ifndef _WIN32 +#include +#include +#endif + #ifdef HAVE_GETOPT_H #include #endif @@ -191,6 +196,9 @@ print_usage(FILE *output) fprintf(output, " -d |\n"); fprintf(output, " packet encapsulation or protocol\n"); fprintf(output, " -F 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 enable specific name resolution(s): \"mnNtd\"\n"); fprintf(output, " -p use the system's packet header format\n"); @@ -416,6 +424,8 @@ main(int argc, char *argv[]) #ifdef _WIN32 WSADATA wsaData; +#else + struct rlimit limit; #endif /* _WIN32 */ char *gpf_path, *pf_path; @@ -438,7 +448,7 @@ main(int argc, char *argv[]) {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; @@ -632,6 +642,18 @@ main(int argc, char *argv[]) and the output buffer is only flushed when it fills up). */ line_buffered = TRUE; 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 */ disable_name_resolution(); break;