Ignore:
Timestamp:
01/07/19 10:35:07 (22 months ago)
Author:
Jacob Van Walraven <jcv9@…>
Branches:
develop
Children:
51276bd
Parents:
979ab1a0
git-author:
Jacob Van Walraven <jcv9@…> (12/14/18 09:31:48)
git-committer:
Jacob Van Walraven <jcv9@…> (01/07/19 10:35:07)
Message:

Added can_write functions to each output format, Fixed pcapng_get_header_type incorrectly flipping type bytes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_pcapfile.c

    rd439067 r9a6bdbc  
    6868#define MAGIC2_REV  0x4d3cb2a1
    6969
     70static bool pcapfile_can_write(libtrace_packet_t *packet) {
     71        /* Get the linktype */
     72        libtrace_linktype_t ltype = trace_get_link_type(packet);
     73
     74        if (ltype == TRACE_TYPE_PCAPNG_META
     75                || ltype == TRACE_TYPE_CONTENT_INVALID
     76                || ltype == TRACE_TYPE_UNKNOWN
     77                || ltype == TRACE_TYPE_ERF_META
     78                || ltype == TRACE_TYPE_NONDATA) {
     79
     80                return false;
     81        }
     82
     83        return true;
     84}
     85
    7086static inline int header_is_backwards_magic(pcapfile_header_t *header) {
    7187        return (header->magic_number == MAGIC1_REV || header->magic_number == MAGIC2_REV);
     
    175191        if (!DATA(libtrace))
    176192                return num;
    177        
     193
    178194        /* We can use the PCAP magic number to determine the byte order */
    179195        if (header_is_backwards_magic(&(DATA(libtrace)->header)))
     
    371387                        packet->buffer,
    372388                        sizeof(libtrace_pcapfile_pkt_hdr_t));
     389
    373390        if (err<0) {
    374391                trace_set_err(libtrace,TRACE_ERR_WANDIO_FAILED,"reading packet");
     
    432449                libtrace_packet_t *packet)
    433450{
     451
     452        /* Check pcapfile can write this type of packet */
     453        if (!pcapfile_can_write(packet)) {
     454                return 0;
     455        }
     456
    434457        struct libtrace_pcapfile_pkt_hdr_t hdr;
    435458        struct timeval tv = trace_get_timeval(packet);
     
    441464
    442465        ptr = trace_get_packet_buffer(packet,&linktype,&remaining);
    443        
    444         /* Silently discard RT metadata packets and packets with an
    445          * unknown linktype. */
    446         if (linktype == TRACE_TYPE_NONDATA || linktype == TRACE_TYPE_UNKNOWN || linktype == TRACE_TYPE_ERF_META || linktype == TRACE_TYPE_CONTENT_INVALID) {
    447                 return 0;
    448         }
    449466
    450467        /* If this packet cannot be converted to a pcap linktype then
Note: See TracChangeset for help on using the changeset viewer.