Changeset d3fd4d3


Ignore:
Timestamp:
06/23/06 12:01:36 (15 years ago)
Author:
Perry Lorier <perry@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
45dfddc
Parents:
c5ebbaa
Message:

Move pcapfile_pkt_hdr_t to be a global libtrace internal structure
Change the way detecting trace types works

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_pcapfile.c

    r5eeba76 rd3fd4d3  
    4444#define DATA(x) ((struct pcapfile_format_data_t*)((x)->format_data))
    4545
    46 struct pcapfile_format_data_t {
    47         libtrace_io_t *file;
    48         struct pcapfile_header_t {
     46typedef struct pcapfile_header_t {
    4947                uint32_t magic_number;   /* magic number */
    5048                uint16_t version_major;  /* major version number */
     
    5452                uint32_t snaplen;        /* aka "wirelen" */
    5553                uint32_t network;        /* data link type */
    56         } header;
     54} pcapfile_header_t;
     55
     56struct pcapfile_format_data_t {
     57        libtrace_io_t *file;
     58        pcapfile_header_t header;
     59};
     60
     61struct pcapfile_format_data_out_t {
     62        libtrace_io_t *file;
     63
    5764};
    5865
     
    147154}
    148155
    149 struct pcapfile_pkt_hdr_t {
    150         uint32_t ts_sec;
    151         uint32_t ts_usec;
    152         uint32_t caplen;
    153         uint32_t wirelen;
    154 };
    155 
    156156static int pcapfile_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) {
    157157        int err;
     
    169169        err=libtrace_io_read(DATA(libtrace)->file,
    170170                        packet->buffer,
    171                         sizeof(struct pcapfile_pkt_hdr_t));
     171                        sizeof(libtrace_pcapfile_pkt_hdr_t));
    172172
    173173        if (err<0) {
     
    184184
    185185        err=libtrace_io_read(DATA(libtrace)->file,
    186                         (char*)packet->buffer+sizeof(struct pcapfile_pkt_hdr_t),
    187                         swapl(libtrace,((struct pcapfile_pkt_hdr_t*)packet->buffer)->caplen)
     186                        (char*)packet->buffer+sizeof(libtrace_pcapfile_pkt_hdr_t),
     187                        swapl(libtrace,((libtrace_pcapfile_pkt_hdr_t*)packet->buffer)->caplen)
    188188                        );
    189189
     
    198198
    199199        packet->payload = (char*)packet->buffer
    200                 + sizeof(struct pcapfile_pkt_hdr_t);
     200                + sizeof(libtrace_pcapfile_pkt_hdr_t);
    201201       
    202         return sizeof(struct pcapfile_pkt_hdr_t)
    203                 +swapl(libtrace,((struct pcapfile_pkt_hdr_t*)packet->buffer)->caplen);
    204 }
     202        return sizeof(libtrace_pcapfile_pkt_hdr_t)
     203                +swapl(libtrace,((libtrace_pcapfile_pkt_hdr_t*)packet->buffer)->caplen);
     204}
     205
     206#if 0
     207static void pcapfile_write_packet(libtrace_out_t *out,
     208                const libtrace_packet_t *packet)
     209{
     210        struct pcapfile_pkt_hdr_t hdr;
     211
     212        tv = trace_get_timeval(packet);
     213        hdr.ts_sec = tv.tv_sec;
     214        hdr.ts_usec = tv.tv_usec;
     215        hdr.caplen = trace_get_capture_length(packet);
     216        hdr.wirelen = trace_get_wire_length(packet);
     217
     218        write(fd,&hdr,sizeof(hdr));
     219        write(fd,packet->payload,hdr.caplen);
     220       
     221}
     222#endif
    205223
    206224
     
    208226                const libtrace_packet_t *packet)
    209227{
    210 
     228#if 0
    211229        return pcap_dlt_to_libtrace(
    212230                        swapl(packet->trace,
     
    214232                             )
    215233                        );
     234#endif
     235        return pcap_dlt_to_libtrace(rt_to_pcap_dlt(packet->type));
    216236}
    217237
     
    279299                const libtrace_packet_t *packet)
    280300{
    281         struct pcapfile_pkt_hdr_t *hdr =
    282                 (struct pcapfile_pkt_hdr_t*)packet->header;
     301        libtrace_pcapfile_pkt_hdr_t *hdr =
     302                (libtrace_pcapfile_pkt_hdr_t*)packet->header;
    283303        struct timeval ts;
    284304        ts.tv_sec = swapl(packet->trace,hdr->ts_sec);
     
    289309
    290310static int pcapfile_get_capture_length(const libtrace_packet_t *packet) {
    291         struct pcapfile_pkt_hdr_t *pcapptr
    292                 = (struct pcapfile_pkt_hdr_t *)packet->header;
     311        libtrace_pcapfile_pkt_hdr_t *pcapptr
     312                = (libtrace_pcapfile_pkt_hdr_t *)packet->header;
    293313
    294314        return swapl(packet->trace,pcapptr->caplen);
     
    296316
    297317static int pcapfile_get_wire_length(const libtrace_packet_t *packet) {
    298         struct pcapfile_pkt_hdr_t *pcapptr
    299                 = (struct pcapfile_pkt_hdr_t *)packet->header;
     318        libtrace_pcapfile_pkt_hdr_t *pcapptr
     319                = (libtrace_pcapfile_pkt_hdr_t *)packet->header;
    300320        if (packet->type==pcap_dlt_to_rt(TRACE_DLT_EN10MB))
    301321                /* Include the missing FCS */
     
    306326
    307327static int pcapfile_get_framing_length(const libtrace_packet_t *packet UNUSED) {
    308         return sizeof(struct pcapfile_pkt_hdr_t);
     328        return sizeof(libtrace_pcapfile_pkt_hdr_t);
    309329}
    310330
    311331static size_t pcapfile_set_capture_length(libtrace_packet_t *packet,size_t size) {
    312         struct pcapfile_pkt_hdr_t *pcapptr = 0;
     332        libtrace_pcapfile_pkt_hdr_t *pcapptr = 0;
    313333        assert(packet);
    314334        if (size > trace_get_capture_length(packet)) {
     
    316336                return trace_get_capture_length(packet);
    317337        }
    318         pcapptr = (struct pcapfile_pkt_hdr_t *)packet->header;
     338        pcapptr = (libtrace_pcapfile_pkt_hdr_t *)packet->header;
    319339        pcapptr->caplen = swapl(packet->trace,size);
    320340        return trace_get_capture_length(packet);
Note: See TracChangeset for help on using the changeset viewer.