Deleted Added
full compact
33c33
< "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.253.2.13 2007/09/12 19:48:51 guy Exp $ (LBL)";
---
> "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.271.2.11 2008-09-25 21:50:04 guy Exp $ (LBL)";
36c36
< /* $FreeBSD: head/contrib/tcpdump/tcpdump.c 173819 2007-11-21 12:52:26Z mlaier $ */
---
> /* $FreeBSD: head/contrib/tcpdump/tcpdump.c 190207 2009-03-21 18:30:25Z rpaulo $ */
69a70
> #include <limits.h>
70a72,73
> #include <sys/wait.h>
> #include <sys/resource.h>
75a79
>
83a88,91
> #ifndef NAME_MAX
> #define NAME_MAX 255
> #endif
>
87,94d94
< /*
< * Define the maximum number of files for the -C flag, and how many
< * characters can be added to a filename for the -C flag (which
< * should be enough to handle MAX_CFLAG - 1).
< */
< #define MAX_CFLAG 1000000
< #define MAX_CFLAG_CHARS 6
<
96a97
> char *zflag = NULL; /* compress each savefile using a specified command (like gzip or bzip2) */
106a108
> static RETSIGTYPE child_cleanup(int);
224a227,229
> #ifdef DLT_IEEE802_11_RADIO_AVS
> { ieee802_11_radio_avs_if_print, DLT_IEEE802_11_RADIO_AVS },
> #endif
272a278,280
> #if defined(DLT_BLUETOOTH_HCI_H4_WITH_PHDR) && defined(HAVE_PCAP_BLUETOOTH_H)
> { bt_if_print, DLT_BLUETOOTH_HCI_H4_WITH_PHDR},
> #endif
300a309
> char *CurrentFileName;
330c339
< (void) fprintf(stderr, " (not supported)");
---
> (void) fprintf(stderr, " (printing not supported)");
333c342
< (void) fprintf(stderr, " DLT %d (not supported)\n",
---
> (void) fprintf(stderr, " DLT %d (printing not supported)\n",
345c354
< #ifdef WIN32
---
> #if defined(HAVE_PCAP_CREATE) || defined(WIN32)
348c357
< #else /* WIN32 */
---
> #else /* defined(HAVE_PCAP_CREATE) || defined(WIN32) */
351c360
< #endif /* WIN32 */
---
> #endif /* defined(HAVE_PCAP_CREATE) || defined(WIN32) */
352a362,367
> #ifdef HAVE_PCAP_CREATE
> #define I_FLAG "I"
> #else /* HAVE_PCAP_CREATE */
> #define I_FLAG
> #endif /* HAVE_PCAP_CREATE */
>
427a443,461
> char *filename = malloc(NAME_MAX + 1);
>
> /* Process with strftime if Gflag is set. */
> if (Gflag != 0) {
> struct tm *local_tm;
>
> /* Convert Gflag_time to a usable format */
> if ((local_tm = localtime(&Gflag_time)) == NULL) {
> error("MakeTimedFilename: localtime");
> }
>
> /* There's no good way to detect an error in strftime since a return
> * value of 0 isn't necessarily failure.
> */
> strftime(filename, NAME_MAX, orig_name, local_tm);
> } else {
> strncpy(filename, orig_name, NAME_MAX);
> }
>
429c463
< strcpy(buffer, orig_name);
---
> strncpy(buffer, filename, NAME_MAX + 1);
431c465,468
< sprintf(buffer, "%s%0*d", orig_name, max_chars, cnt);
---
> if (snprintf(buffer, NAME_MAX + 1, "%s%0*d", filename, max_chars, cnt) > NAME_MAX)
> /* Report an error if the filename is too large */
> error("too many output files or filename is too long (> %d)", NAME_MAX);
> free(filename);
453c490
< register char *cp, *infile, *cmdbuf, *device, *RFileName, *WFileName, *WFileNameAlt;
---
> register char *cp, *infile, *cmdbuf, *device, *RFileName, *WFileName;
472d508
< u_int UserBufferSize = 1000000;
504c540
< (op = getopt(argc, argv, "aA" B_FLAG "c:C:d" D_FLAG "eE:fF:i:lLm:M:nNOpqr:Rs:StT:u" U_FLAG "vw:W:xXy:YZ:")) != -1)
---
> (op = getopt(argc, argv, "aA" B_FLAG "c:C:d" D_FLAG "eE:fF:G:i:" I_FLAG "KlLm:M:nNOpqr:Rs:StT:u" U_FLAG "vw:W:xXy:Yz:Z:")) != -1)
515c551
< #ifdef WIN32
---
> #if defined(HAVE_PCAP_CREATE) || defined(WIN32)
517,518c553,554
< UserBufferSize = atoi(optarg)*1024;
< if (UserBufferSize < 0)
---
> Bflag = atoi(optarg)*1024;
> if (Bflag <= 0)
521c557
< #endif /* WIN32 */
---
> #endif /* defined(HAVE_PCAP_CREATE) || defined(WIN32) */
577a614,628
> case 'G':
> Gflag = atoi(optarg);
> if (Gflag < 0)
> error("invalid number of seconds %s", optarg);
>
> /* We will create one file initially. */
> Gflag_count = 0;
>
> /* Grab the current time for rotation use. */
> if ((Gflag_time = time(NULL)) == (time_t)-1) {
> error("main: can't get current time: %s",
> pcap_strerror(errno));
> }
> break;
>
612a664,669
> #ifdef HAVE_PCAP_CREATE
> case 'I':
> ++Iflag;
> break;
> #endif /* HAVE_PCAP_CREATE */
>
634,635c691,692
< case 'n':
< ++nflag;
---
> case 'K':
> ++Kflag;
638,641d694
< case 'N':
< ++Nflag;
< break;
<
644c697
< if (smiLoadModule(optarg) == 0) {
---
> if (smiLoadModule(optarg) == 0) {
646c699
< }
---
> }
662a716,723
> case 'n':
> ++nflag;
> break;
>
> case 'N':
> ++Nflag;
> break;
>
783a845,853
> case 'z':
> if (optarg) {
> zflag = strdup(optarg);
> } else {
> usage();
> /* NOTREACHED */
> }
> break;
>
808a879
> case 5: /* Microseconds since first packet */
812c883
< error("only -t, -tt, -ttt, and -tttt are supported");
---
> error("only -t, -tt, -ttt, -tttt and -ttttt are supported");
886a958,1018
> #ifdef HAVE_PCAP_CREATE
> pd = pcap_create(device, ebuf);
> if (pd == NULL)
> error("%s", ebuf);
> status = pcap_set_snaplen(pd, snaplen);
> if (status != 0)
> error("%s: pcap_set_snaplen failed: %s",
> device, pcap_statustostr(status));
> status = pcap_set_promisc(pd, !pflag);
> if (status != 0)
> error("%s: pcap_set_promisc failed: %s",
> device, pcap_statustostr(status));
> if (Iflag) {
> status = pcap_set_rfmon(pd, 1);
> if (status != 0)
> error("%s: pcap_set_rfmon failed: %s",
> device, pcap_statustostr(status));
> }
> status = pcap_set_timeout(pd, 1000);
> if (status != 0)
> error("%s: pcap_set_timeout failed: %s",
> device, pcap_statustostr(status));
> if (Bflag != 0) {
> status = pcap_set_buffer_size(pd, Bflag);
> if (status != 0)
> error("%s: pcap_set_buffer_size failed: %s",
> device, pcap_statustostr(status));
> }
> status = pcap_activate(pd);
> if (status < 0) {
> /*
> * pcap_activate() failed.
> */
> cp = pcap_geterr(pd);
> if (status == PCAP_ERROR)
> error("%s", cp);
> else if ((status == PCAP_ERROR_NO_SUCH_DEVICE ||
> status == PCAP_ERROR_PERM_DENIED) &&
> *cp != '\0')
> error("%s: %s\n(%s)", device,
> pcap_statustostr(status), cp);
> else
> error("%s: %s", device,
> pcap_statustostr(status));
> } else if (status > 0) {
> /*
> * pcap_activate() succeeded, but it's warning us
> * of a problem it had.
> */
> cp = pcap_geterr(pd);
> if (status == PCAP_WARNING)
> warning("%s", cp);
> else if (status == PCAP_WARNING_PROMISC_NOTSUP &&
> *cp != '\0')
> warning("%s: %s\n(%s)", device,
> pcap_statustostr(status), cp);
> else
> warning("%s: %s", device,
> pcap_statustostr(status));
> }
> #else
892a1025
> #endif /* HAVE_PCAP_CREATE */
900,902c1033,1035
< #ifdef WIN32
< if(UserBufferSize != 1000000)
< if(pcap_setbuff(pd, UserBufferSize)==-1){
---
> #if !defined(HAVE_PCAP_CREATE) && defined(WIN32)
> if(Bflag != 0)
> if(pcap_setbuff(pd, Bflag)==-1){
905c1038
< #endif /* WIN32 */
---
> #endif /* !defined(HAVE_PCAP_CREATE) && defined(WIN32) */
924c1057
< program_name, gndo->ndo_dltname);
---
> program_name, gndo->ndo_dltname);
950a1084
> init_checksum();
954d1087
< #endif /* WIN32 */
956a1090,1091
> (void)setsignal(SIGCHLD, child_cleanup);
> #endif /* WIN32 */
966a1102,1103
> /* Do not exceed the default NAME_MAX for files. */
> dumpinfo.CurrentFileName = (char *)malloc(NAME_MAX + 1);
968,972c1105,1114
< WFileNameAlt = (char *)malloc(strlen(WFileName) + MAX_CFLAG_CHARS + 1);
< if (WFileNameAlt == NULL)
< error("malloc of WFileNameAlt");
< MakeFilename(WFileNameAlt, WFileName, 0, WflagChars);
< p = pcap_dump_open(pd, WFileNameAlt);
---
> if (dumpinfo.CurrentFileName == NULL)
> error("malloc of dumpinfo.CurrentFileName");
>
> /* We do not need numbering for dumpfiles if Cflag isn't set. */
> if (Cflag != 0)
> MakeFilename(dumpinfo.CurrentFileName, WFileName, 0, WflagChars);
> else
> MakeFilename(dumpinfo.CurrentFileName, WFileName, 0, 0);
>
> p = pcap_dump_open(pd, dumpinfo.CurrentFileName);
975c1117
< if (Cflag != 0) {
---
> if (Cflag != 0 || Gflag != 0) {
1010c1152,1157
< (void)setsignal(SIGINFO, requestinfo);
---
> /*
> * We can't get statistics when reading from a file rather
> * than capturing from a device.
> */
> if (RFileName == NULL)
> (void)setsignal(SIGINFO, requestinfo);
1127a1275,1286
> /*
> On windows, we do not use a fork, so we do not care less about
> waiting a child processes to die
> */
> #ifndef WIN32
> static RETSIGTYPE
> child_cleanup(int signo _U_)
> {
> wait(NULL);
> }
> #endif /* WIN32 */
>
1155a1315
> #ifndef WIN32
1156a1317,1345
> compress_savefile(const char *filename)
> {
> if (fork())
> return;
> /*
> * Set to lowest priority so that this doesn't disturb the capture
> */
> #ifdef NZERO
> setpriority(PRIO_PROCESS, 0, NZERO - 1);
> #else
> setpriority(PRIO_PROCESS, 0, 19);
> #endif
> if (execlp(zflag, zflag, filename, NULL) == -1)
> fprintf(stderr,
> "compress_savefile:execlp(%s, %s): %s\n",
> zflag,
> filename,
> strerror(errno));
> }
> #else /* WIN32 */
> static void
> compress_savefile(const char *filename)
> {
> fprintf(stderr,
> "compress_savefile failed. Functionality not implemented under windows\n");
> }
> #endif /* WIN32 */
>
> static void
1160d1348
< char *name;
1168a1357,1425
> * XXX - this won't force the file to rotate on the specified time
> * boundary, but it will rotate on the first packet received after the
> * specified Gflag number of seconds. Note: if a Gflag time boundary
> * and a Cflag size boundary coincide, the time rotation will occur
> * first thereby cancelling the Cflag boundary (since the file should
> * be 0).
> */
> if (Gflag != 0) {
> /* Check if it is time to rotate */
> time_t t;
>
> /* Get the current time */
> if ((t = time(NULL)) == (time_t)-1) {
> error("dump_and_trunc_packet: can't get current_time: %s",
> pcap_strerror(errno));
> }
>
>
> /* If the time is greater than the specified window, rotate */
> if (t - Gflag_time >= Gflag) {
> /* Update the Gflag_time */
> Gflag_time = t;
> /* Update Gflag_count */
> Gflag_count++;
> /*
> * Close the current file and open a new one.
> */
> pcap_dump_close(dump_info->p);
>
> /*
> * Compress the file we just closed, if the user asked for it
> */
> if (zflag != NULL)
> compress_savefile(dump_info->CurrentFileName);
>
> /*
> * Check to see if we've exceeded the Wflag (when
> * not using Cflag).
> */
> if (Cflag == 0 && Wflag > 0 && Gflag_count >= Wflag) {
> (void)fprintf(stderr, "Maximum file limit reached: %d\n",
> Wflag);
> exit(0);
> /* NOTREACHED */
> }
> if (dump_info->CurrentFileName != NULL)
> free(dump_info->CurrentFileName);
> /* Allocate space for max filename + \0. */
> dump_info->CurrentFileName = (char *)malloc(NAME_MAX + 1);
> if (dump_info->CurrentFileName == NULL)
> error("dump_packet_and_trunc: malloc");
> /*
> * This is always the first file in the Cflag
> * rotation: e.g. 0
> * We also don't need numbering if Cflag is not set.
> */
> if (Cflag != 0)
> MakeFilename(dump_info->CurrentFileName, dump_info->WFileName, 0,
> WflagChars);
> else
> MakeFilename(dump_info->CurrentFileName, dump_info->WFileName, 0, 0);
>
> dump_info->p = pcap_dump_open(dump_info->pd, dump_info->CurrentFileName);
> if (dump_info->p == NULL)
> error("%s", pcap_geterr(pd));
> }
> }
>
> /*
1173c1430
< if (pcap_dump_ftell(dump_info->p) > Cflag) {
---
> if (Cflag != 0 && pcap_dump_ftell(dump_info->p) > Cflag) {
1177a1435,1441
>
> /*
> * Compress the file we just closed, if the user asked for it
> */
> if (zflag != NULL)
> compress_savefile(dump_info->CurrentFileName);
>
1182,1184d1445
< } else {
< if (Cflag_count >= MAX_CFLAG)
< error("too many output files");
1186,1187c1447,1450
< name = (char *)malloc(strlen(dump_info->WFileName) + MAX_CFLAG_CHARS + 1);
< if (name == NULL)
---
> if (dump_info->CurrentFileName != NULL)
> free(dump_info->CurrentFileName);
> dump_info->CurrentFileName = (char *)malloc(NAME_MAX + 1);
> if (dump_info->CurrentFileName == NULL)
1189,1191c1452,1453
< MakeFilename(name, dump_info->WFileName, Cflag_count, WflagChars);
< dump_info->p = pcap_dump_open(dump_info->pd, name);
< free(name);
---
> MakeFilename(dump_info->CurrentFileName, dump_info->WFileName, Cflag_count, WflagChars);
> dump_info->p = pcap_dump_open(dump_info->pd, dump_info->CurrentFileName);
1368c1630
< DWORD_PTR dw1 _U_, DWORD_PTR dw2 _U_)
---
> DWORD_PTR dw1 _U_, DWORD_PTR dw2 _U_)
1415c1677
< "Usage: %s [-aAd" D_FLAG "eflLnNOpqRStu" U_FLAG "vxX]" B_FLAG_USAGE " [-c count] [ -C file_size ]\n", program_name);
---
> "Usage: %s [-aAd" D_FLAG "ef" I_FLAG "KlLnNOpqRStu" U_FLAG "vxX]" B_FLAG_USAGE " [ -c count ]\n", program_name);
1417c1679
< "\t\t[ -E algo:secret ] [ -F file ] [ -i interface ] [ -M secret ]\n");
---
> "\t\t[ -C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ]\n");
1419c1681
< "\t\t[ -r file ] [ -s snaplen ] [ -T type ] [ -w file ]\n");
---
> "\t\t[ -i interface ] [ -M secret ] [ -r file ]\n");
1421c1683
< "\t\t[ -W filecount ] [ -y datalinktype ] [ -Z user ]\n");
---
> "\t\t[ -s snaplen ] [ -T type ] [ -w file ] [ -W filecount ]\n");
1422a1685,1686
> "\t\t[ -y datalinktype ] [ -z command ] [ -Z user ]\n");
> (void)fprintf(stderr,
1464d1727
<