Eliminate an unneded member of a wtap_dumper.

The only place the time stamp precision is used is in the libpcap code,
where it determines whether to write out microsecond-precision or
nanosecond-precision time stamps; we can determine that by looking at
the type/subtype field, which is also part of that structure, so do
that.

We weren't setting it consistently - we were only setting it in libpcap
and a few other capture file writers, and not in other capture file
writers - and none of the writers other than libpcap used it.

Change-Id: If53779cf4823ca936b8bf3e8a7dbcfea5850e652
Reviewed-on: https://code.wireshark.org/review/21171
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2017-04-17 17:17:01 -07:00
parent c9bb6b8282
commit ce6430e35e
6 changed files with 17 additions and 63 deletions

View File

@ -346,8 +346,8 @@ WSLUA_METAMETHOD CaptureInfoConst__tostring(lua_State* L) {
lua_pushstring(L,"CaptureInfoConst pointer is NULL!");
} else {
wtap_dumper *wdh = fi->wdh;
lua_pushfstring(L, "CaptureInfoConst: file_type_subtype=%d, snaplen=%d, encap=%d, compressed=%d, file_tsprec='%s'",
wdh->file_type_subtype, wdh->snaplen, wdh->encap, wdh->compressed, wdh->tsprecision);
lua_pushfstring(L, "CaptureInfoConst: file_type_subtype=%d, snaplen=%d, encap=%d, compressed=%d",
wdh->file_type_subtype, wdh->snaplen, wdh->encap, wdh->compressed);
}
WSLUA_RETURN(1); /* String of debug information. */

View File

@ -402,19 +402,6 @@ gboolean btsnoop_dump_open_h1(wtap_dumper *wdh, int *err)
wdh->subtype_write = btsnoop_dump_h1;
/* Write the file header. */
switch (wdh->file_type_subtype) {
case WTAP_FILE_TYPE_SUBTYPE_BTSNOOP:
wdh->tsprecision = WTAP_TSPREC_USEC;
break;
default:
/* We should never get here - our open routine
should only get called for the types above. */
*err = WTAP_ERR_UNWRITABLE_FILE_TYPE;
return FALSE;
}
if (!wtap_dump_file_write(wdh, btsnoop_magic, sizeof btsnoop_magic, err))
return FALSE;
@ -443,19 +430,6 @@ gboolean btsnoop_dump_open_h4(wtap_dumper *wdh, int *err)
wdh->subtype_write = btsnoop_dump_h4;
/* Write the file header. */
switch (wdh->file_type_subtype) {
case WTAP_FILE_TYPE_SUBTYPE_BTSNOOP:
wdh->tsprecision = WTAP_TSPREC_USEC;
break;
default:
/* We should never get here - our open routine
should only get called for the types above. */
*err = WTAP_ERR_UNWRITABLE_FILE_TYPE;
return FALSE;
}
if (!wtap_dump_file_write(wdh, btsnoop_magic, sizeof btsnoop_magic, err))
return FALSE;

View File

@ -924,20 +924,10 @@ int erf_dump_can_write_encap(int encap)
return 0;
}
int erf_dump_open(wtap_dumper *wdh, int *err)
int erf_dump_open(wtap_dumper *wdh, int *err _U_)
{
wdh->subtype_write = erf_dump;
switch(wdh->file_type_subtype){
case WTAP_FILE_TYPE_SUBTYPE_ERF:
wdh->tsprecision = WTAP_TSPREC_NSEC;
break;
default:
*err = WTAP_ERR_UNWRITABLE_FILE_TYPE;
return FALSE;
break;
}
return TRUE;
}

View File

@ -838,18 +838,15 @@ gboolean libpcap_dump_open(wtap_dumper *wdh, int *err)
case WTAP_FILE_TYPE_SUBTYPE_PCAP_SS990417: /* modified, but with the old magic, sigh */
case WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA: /* Nokia libpcap of some sort */
magic = PCAP_MAGIC;
wdh->tsprecision = WTAP_TSPREC_USEC;
break;
case WTAP_FILE_TYPE_SUBTYPE_PCAP_SS990915: /* new magic, extra crap */
case WTAP_FILE_TYPE_SUBTYPE_PCAP_SS991029:
magic = PCAP_MODIFIED_MAGIC;
wdh->tsprecision = WTAP_TSPREC_USEC;
break;
case WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC: /* same as WTAP_FILE_TYPE_SUBTYPE_PCAP, but nsec precision */
magic = PCAP_NSEC_MAGIC;
wdh->tsprecision = WTAP_TSPREC_NSEC;
break;
default:
@ -914,12 +911,6 @@ static gboolean libpcap_dump(wtap_dumper *wdh,
return FALSE;
}
rec_hdr.hdr.ts_sec = (guint32) phdr->ts.secs;
if(wdh->tsprecision == WTAP_TSPREC_NSEC) {
rec_hdr.hdr.ts_usec = phdr->ts.nsecs;
} else {
rec_hdr.hdr.ts_usec = phdr->ts.nsecs / 1000;
}
rec_hdr.hdr.incl_len = phdr->caplen + phdrsize;
rec_hdr.hdr.orig_len = phdr->len + phdrsize;
@ -931,12 +922,21 @@ static gboolean libpcap_dump(wtap_dumper *wdh,
switch (wdh->file_type_subtype) {
case WTAP_FILE_TYPE_SUBTYPE_PCAP:
rec_hdr.hdr.ts_sec = (guint32) phdr->ts.secs;
rec_hdr.hdr.ts_usec = phdr->ts.nsecs / 1000;
hdr_size = sizeof (struct pcaprec_hdr);
break;
case WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC:
rec_hdr.hdr.ts_sec = (guint32) phdr->ts.secs;
rec_hdr.hdr.ts_usec = phdr->ts.nsecs;
hdr_size = sizeof (struct pcaprec_hdr);
break;
case WTAP_FILE_TYPE_SUBTYPE_PCAP_SS990417: /* modified, but with the old magic, sigh */
case WTAP_FILE_TYPE_SUBTYPE_PCAP_SS991029:
rec_hdr.hdr.ts_sec = (guint32) phdr->ts.secs;
rec_hdr.hdr.ts_usec = phdr->ts.nsecs / 1000;
/* XXX - what should we supply here?
Alexey's "libpcap" looks up the interface in the system's
@ -963,6 +963,8 @@ static gboolean libpcap_dump(wtap_dumper *wdh,
break;
case WTAP_FILE_TYPE_SUBTYPE_PCAP_SS990915: /* new magic, extra crap at the end */
rec_hdr.hdr.ts_sec = (guint32) phdr->ts.secs;
rec_hdr.hdr.ts_usec = phdr->ts.nsecs / 1000;
rec_hdr.ifindex = 0;
rec_hdr.protocol = 0;
rec_hdr.pkt_type = 0;
@ -972,6 +974,8 @@ static gboolean libpcap_dump(wtap_dumper *wdh,
break;
case WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA: /* old magic, extra crap at the end */
rec_hdr.hdr.ts_sec = (guint32) phdr->ts.secs;
rec_hdr.hdr.ts_usec = phdr->ts.nsecs / 1000;
/* restore the "mysterious stuff" that came with the packet */
memcpy(&rec_hdr.ifindex, pseudo_header->nokia.stuff, 4);
/* not written */

View File

@ -347,21 +347,10 @@ static gboolean logcat_binary_dump(wtap_dumper *wdh,
return TRUE;
}
gboolean logcat_binary_dump_open(wtap_dumper *wdh, int *err)
gboolean logcat_binary_dump_open(wtap_dumper *wdh, int *err _U_)
{
wdh->subtype_write = logcat_binary_dump;
switch (wdh->encap) {
case WTAP_ENCAP_LOGCAT:
case WTAP_ENCAP_WIRESHARK_UPPER_PDU:
wdh->tsprecision = WTAP_TSPREC_USEC;
break;
default:
*err = WTAP_ERR_UNWRITABLE_FILE_TYPE;
return FALSE;
}
return TRUE;
}

View File

@ -109,9 +109,6 @@ struct wtap_dumper {
subtype_write_func subtype_write; /* write out a record */
subtype_finish_func subtype_finish; /* write out information to finish writing file */
int tsprecision; /**< timestamp precision of the lower 32bits
* e.g. WTAP_TSPREC_USEC
*/
addrinfo_lists_t *addrinfo_lists; /**< Struct containing lists of resolved addresses */
GArray *shb_hdrs;
GArray *nrb_hdrs; /**< name resolution comment/custom_opt, or NULL */