[ovs-dev] [PATCH] pcap-file: Add support for Linux SLL formatted PCAP files.

Ben Pfaff blp at ovn.org
Fri Nov 16 17:25:24 UTC 2018


On Fri, Nov 16, 2018 at 08:44:10AM -0800, Simon Horman wrote:
> On Sun, Nov 11, 2018 at 03:41:08PM -0800, Ben Pfaff wrote:
> > Someone sent me one of these and OVS couldn't read it.  This fixes the
> > problem.
> > 
> > Signed-off-by: Ben Pfaff <blp at ovn.org>
> > ---
> >  lib/pcap-file.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 54 insertions(+)
> > 
> > diff --git a/lib/pcap-file.c b/lib/pcap-file.c
> > index 81a094c2a01f..0f34c5e83cda 100644
> > --- a/lib/pcap-file.c
> > +++ b/lib/pcap-file.c
> > @@ -39,9 +39,15 @@ enum ts_resolution {
> >      PCAP_NSEC,
> >  };
> >  
> > +enum network_type {
> > +    PCAP_ETHERNET = 0,
> > +    PCAP_LINUX_SLL = 0x71
> > +};
> > +
> >  struct pcap_file {
> >      FILE *file;
> >      enum ts_resolution resolution;
> > +    enum network_type network;
> >  };
> >  
> >  struct pcap_hdr {
> > @@ -130,10 +136,13 @@ ovs_pcap_read_header(struct pcap_file *p_file)
> >          VLOG_WARN("failed to read pcap header: %s", ovs_retval_to_string(error));
> >          return error;
> >      }
> > +    bool byte_swap;
> >      if (ph.magic_number == 0xa1b2c3d4 || ph.magic_number == 0xd4c3b2a1) {
> > +        byte_swap = ph.magic_number == 0xd4c3b2a1;
> >          p_file->resolution = PCAP_USEC;
> >      } else if (ph.magic_number == 0xa1b23c4d ||
> >                 ph.magic_number == 0x4d3cb2a1) {
> > +        byte_swap = ph.magic_number == 0x4d3cb2a1;
> >          p_file->resolution = PCAP_NSEC;
> >      } else {
> >          VLOG_WARN("bad magic 0x%08"PRIx32" reading pcap file "
> > @@ -141,6 +150,13 @@ ovs_pcap_read_header(struct pcap_file *p_file)
> >                    "or 0x4d3cb2a1)", ph.magic_number);
> >          return EPROTO;
> >      }
> > +    p_file->network = byte_swap ? uint32_byteswap(ph.network) : ph.network;
> > +    if (p_file->network != PCAP_ETHERNET &&
> > +        p_file->network != PCAP_LINUX_SLL) {
> > +        VLOG_WARN("unknown network type %"PRIu16" reading pcap file",
> > +                  p_file->network);
> 
> Hi Ben,
> 
> the line above seems to produce an error in travis-ci.
> 
> As per https://travis-ci.org/openvswitch/ovs/jobs/456022920
> 
> lib/pcap-file.c:157:19: error: format specifies type 'unsigned short' but the argument has underlying type 'unsigned int' [-Werror,-Wformat]

Thanks for the report.  I sent a fix.


More information about the dev mailing list