Changeset 14d8a63 for lib/format_pcap.c


Ignore:
Timestamp:
11/25/05 16:12:39 (16 years ago)
Author:
Daniel Lawson <dlawson@…>
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:
3840760
Parents:
e9fa643
Message:

update to version 3.0.0
zero-copy patch - trace.c updated with new trace_create_packet() etc
format_*.c updated with zero-copy codepath

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_pcap.c

    r187a6d6 r14d8a63  
    210210        int numbytes = 0;
    211211       
    212         memcpy(buffer,pcaphdr,sizeof(struct pcap_pkthdr));
     212        // This is ugly, but seems to be needed. We want both the
     213        // header and the payload in the same block of memory (packet->buffer)
     214        //memcpy(buffer,pcaphdr,sizeof(struct pcap_pkthdr));
    213215        numbytes = pcaphdr->len;
    214         memcpy(buffer + sizeof(struct pcap_pkthdr),pcappkt,numbytes);
     216        //memcpy(buffer + sizeof(struct pcap_pkthdr),pcappkt,numbytes);
     217
     218        //packet->header = packet->buffer;
     219        //packet->payload = packet->header + sizeof(struct pcap_pkthdr);
     220        packet->header = (void *)pcaphdr;
     221        packet->payload = (void *)pcappkt;
     222
    215223
    216224        packet->size = numbytes + sizeof(struct pcap_pkthdr);
     
    235243static int pcap_write_packet(struct libtrace_out_t *libtrace, const struct libtrace_packet_t *packet) {
    236244        struct pcap_pkthdr pcap_pkt_hdr;
    237         void *link = trace_get_link(packet);
    238245
    239246        if (!OUTPUT.trace.pcap) {
     
    247254                        packet->trace->format == &pcapint) {
    248255               
    249                 pcap_dump((u_char*)OUTPUT.trace.dump,(struct pcap_pkthdr *)packet->buffer,link);
     256                pcap_dump((u_char*)OUTPUT.trace.dump,(struct pcap_pkthdr *)packet->header,packet->payload);
    250257        } else {
    251258                // Leave the manual copy as it is, as it gets around
     
    257264                pcap_pkt_hdr.len = trace_get_wire_length(packet);
    258265
    259                 pcap_dump((u_char*)OUTPUT.trace.dump, &pcap_pkt_hdr, link);
     266                pcap_dump((u_char*)OUTPUT.trace.dump, &pcap_pkt_hdr, packet->payload);
    260267        }
    261268        return 0;
     
    269276
    270277static void *pcap_get_link(const struct libtrace_packet_t *packet) {
    271         return (void *) (packet->buffer + sizeof(struct pcap_pkthdr));
     278        return (void *) packet->payload;
    272279}
    273280
     
    275282        struct pcap_pkthdr *pcapptr = 0;
    276283        int linktype = 0;
    277         pcapptr = (struct pcap_pkthdr *)packet->buffer;
     284        pcapptr = (struct pcap_pkthdr *)packet->header;
    278285        linktype = pcap_datalink(packet->trace->format_data->input.pcap);
    279286        switch(linktype) {
     
    352359
    353360static struct timeval pcap_get_timeval(const struct libtrace_packet_t *packet) {
    354         struct pcap_pkthdr *pcapptr = (struct pcap_pkthdr *)packet->buffer;
     361        struct pcap_pkthdr *pcapptr = (struct pcap_pkthdr *)packet->header;
    355362        struct timeval ts;
    356363        ts.tv_sec = pcapptr->ts.tv_sec;
     
    362369static int pcap_get_capture_length(const struct libtrace_packet_t *packet) {
    363370        struct pcap_pkthdr *pcapptr = 0;
    364         pcapptr = (struct pcap_pkthdr *)packet->buffer;
     371        pcapptr = (struct pcap_pkthdr *)packet->header;
    365372        return pcapptr->caplen;
    366373}
     
    368375static int pcap_get_wire_length(const struct libtrace_packet_t *packet) {
    369376        struct pcap_pkthdr *pcapptr = 0;
    370         pcapptr = (struct pcap_pkthdr *)packet->buffer;
     377        pcapptr = (struct pcap_pkthdr *)packet->header;
    371378        return ntohs(pcapptr->len);
    372379}
     
    383390                return (packet->size - sizeof(struct pcap_pkthdr));
    384391        }
    385         pcapptr = (struct pcap_pkthdr *)packet->buffer;
     392        pcapptr = (struct pcap_pkthdr *)packet->header;
    386393        pcapptr->caplen = size;
    387394        packet->size = size + sizeof(struct pcap_pkthdr);
    388         return size;
     395        return packet->size;
    389396}
    390397
Note: See TracChangeset for help on using the changeset viewer.