- /* If the time is greater than the specified window, rotate */
- if (t.tv_sec - Gflag_time >= Gflag) {
- /* Update the Gflag_time */
- Gflag_time = t.tv_sec;
- /* Update Gflag_count */
- Gflag_count++;
- /*
- * Close the current file and open a new one.
- */
- pcap_dump_close(dump_info->p);
-
- /* 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);
- (void)fflush(stderr);
- exit(0);
- /* NOTREACHED */
- }
- /* Allocate space for max filename + \0. */
- name = (char *)malloc(NAME_MAX + 1);
- if (name == 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(name, dump_info->WFileName, 0, WflagChars);
- else
- MakeFilename(name, dump_info->WFileName, 0, 0);
-
- dump_info->p = pcap_dump_open(dump_info->pd, name);
- free(name);
- if (dump_info->p == NULL)
- error("%s", pcap_geterr(pd));
+ /* 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);