]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
pcap/file: minor code cleanups
authorVictor Julien <victor@inliniac.net>
Thu, 5 Mar 2020 10:12:01 +0000 (11:12 +0100)
committerVictor Julien <victor@inliniac.net>
Thu, 5 Mar 2020 10:12:01 +0000 (11:12 +0100)
src/source-pcap-file-helper.c
src/source-pcap-file-helper.h

index 64ac2f7ac4fe029155f285586c9069bced11fd21..cbf4650b1dbadd84564a636beda1cb3225553df7 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2007-2016 Open Information Security Foundation
+/* Copyright (C) 2007-2020 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -120,16 +120,16 @@ TmEcode PcapFileDispatch(PcapFileFileVars *ptv)
 {
     SCEnter();
 
-    /* initialize all the threads initial timestamp */
+    /* initialize all the thread's initial timestamp */
     if (likely(ptv->first_pkt_hdr != NULL)) {
         TmThreadsInitThreadsTimestamp(&ptv->first_pkt_ts);
-        PcapFileCallbackLoop((char *)ptv, ptv->first_pkt_hdr, (u_char *)ptv->first_pkt_data);
+        PcapFileCallbackLoop((char *)ptv, ptv->first_pkt_hdr,
+                (u_char *)ptv->first_pkt_data);
         ptv->first_pkt_hdr = NULL;
         ptv->first_pkt_data = NULL;
     }
 
     int packet_q_len = 64;
-    int r;
     TmEcode loop_result = TM_ECODE_OK;
     strlcpy(pcap_filename, ptv->filename, sizeof(pcap_filename));
 
@@ -143,7 +143,7 @@ TmEcode PcapFileDispatch(PcapFileFileVars *ptv)
         PacketPoolWait();
 
         /* Right now we just support reading packets one at a time. */
-        r = pcap_dispatch(ptv->pcap_handle, packet_q_len,
+        int r = pcap_dispatch(ptv->pcap_handle, packet_q_len,
                           (pcap_handler)PcapFileCallbackLoop, (u_char *)ptv);
         if (unlikely(r == -1)) {
             SCLogError(SC_ERR_PCAP_DISPATCH, "error code %" PRId32 " %s for %s",
@@ -170,6 +170,7 @@ TmEcode PcapFileDispatch(PcapFileFileVars *ptv)
 
 /** \internal
  *  \brief get the timestamp of the first packet and rewind
+ *  \param pfv pcap file variables for storing the timestamp
  *  \retval bool true on success, false on error
  */
 static bool PeekFirstPacketTimestamp(PcapFileFileVars *pfv)
@@ -180,6 +181,8 @@ static bool PeekFirstPacketTimestamp(PcapFileFileVars *pfv)
                 "failed to get first packet timestamp. pcap_next_ex(): %d", r);
         return false;
     }
+    /* timestamp in pfv->first_pkt_hdr may not be 'struct timeval' so
+     * do a manual copy of the members. */
     pfv->first_pkt_ts.tv_sec = pfv->first_pkt_hdr->ts.tv_sec;
     pfv->first_pkt_ts.tv_usec = pfv->first_pkt_hdr->ts.tv_usec;
     return true;
@@ -224,8 +227,8 @@ TmEcode InitPcapFile(PcapFileFileVars *pfv)
     if (!PeekFirstPacketTimestamp(pfv))
         SCReturnInt(TM_ECODE_FAILED);
 
-    DecoderFunc temp;
-    TmEcode validated = ValidateLinkType(pfv->datalink, &temp);
+    DecoderFunc UnusedFnPtr;
+    TmEcode validated = ValidateLinkType(pfv->datalink, &UnusedFnPtr);
     SCReturnInt(validated);
 }
 
@@ -260,4 +263,3 @@ TmEcode ValidateLinkType(int datalink, DecoderFunc *DecoderFn)
 
     SCReturnInt(TM_ECODE_OK);
 }
-/* eof */
index 937e3e70ff0962d0e54c58f1179bf098cf02bcc5..2d98f4dc46fb151e7d5987d9fefb550946d10113 100644 (file)
@@ -75,7 +75,7 @@ typedef struct PcapFileFileVars_
 
     PcapFileSharedVars *shared;
 
-    /* fields used to get the first packets timestamp early,
+    /* fields used to get the first packet's timestamp early,
      * so it can be used to setup the time subsys. */
     const u_char *first_pkt_data;
     struct pcap_pkthdr *first_pkt_hdr;