Changeset b535184 for examples/pcap2erf


Ignore:
Timestamp:
08/05/04 16:14:07 (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:
2137b49
Parents:
9729a8d
Message:

updated examples to use 1.1.0 api

Location:
examples/pcap2erf
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • examples/pcap2erf/Makefile

    r167adf2 rb535184  
    1 include= /usr/local/dag-2.4.11/include
    2 dagcdir= /usr/local/dag-2.4.11/utils/
     1include= /usr/local/dag/include
     2dagcdir= /usr/local/dag/utils/
    33
    44CC=g++-3.0
  • examples/pcap2erf/pcap2erf.c

    ra79ddbe rb535184  
    4646#include <linux/if_ether.h>
    4747
    48 extern "C" {
     48//extern "C" {
    4949#include "dagformat.h"
    5050#include "libtrace.h"
    51 }
     51//}
    5252
    5353struct libtrace_t *trace;
     
    6666int main(int argc, char *argv[]) {
    6767
    68     char *hostname;
     68    char *uri;
    6969    int psize = 0;
    70     int status = 0;
    7170    char *filename;
    7271    FILE* input;
    7372   
    7473    struct pcap_pkthdr *header;
     74    struct libtrace_packet_t packet;
    7575    unsigned long seconds, subseconds;
    7676    unsigned short rlen, lctr, wlen, offset, pad;
     
    8080    uint32_t netmask = 0;
    8181    int data_size;
    82     struct tcphdr *tcpptr = 0;
     82    struct libtrace_tcp *tcpptr = 0;
    8383    int octets[4];
    8484    int hlen;
    85     ip *ipptr;
     85    struct libtrace_ip *ipptr;
    8686
    8787   
    8888    // 2 parameters only, both neccessary
    8989    if (argc == 3) {
    90         hostname = strdup(argv[1]);
     90        uri = strdup(argv[1]);
    9191        filename = strdup(argv[2]);
    9292    }
     
    159159    //----------------------------------------------------------------------
    160160
    161     // create an trace to hostname, on the default port
    162     trace = create_trace(hostname);
     161    // create an trace to the given uri
     162    trace = trace_create(uri);
    163163
    164164    for (;;) {
    165         if ((psize = libtrace_read_packet(trace, buffer,SCANSIZE, &status))
     165        if ((psize = trace_read_packet(trace, &packet))
    166166                == -1) {
    167167            // terminate
     
    169169        }
    170170        // buffer returned is pcap-->ethernet-->upperlayers
    171         header = (struct pcap_pkthdr*) buffer;
     171        header = (struct pcap_pkthdr*)packet.buffer;
    172172
    173173        // if this isnt an ip packet, ignore it
    174         if(! ((buffer + sizeof(struct pcap_pkthdr))[12] == 8 &&
    175             (buffer + sizeof(struct pcap_pkthdr))[13] == 0))
     174        if(! ((packet.buffer + sizeof(struct pcap_pkthdr))[12] == 8 &&
     175            (packet.buffer + sizeof(struct pcap_pkthdr))[13] == 0))
    176176            continue;
    177177       
    178         ipptr = (ip *)(buffer + (sizeof(uint8_t)*30));// wtf is 30
     178
     179        ipptr = trace_get_ip(&packet);
    179180        hlen = ipptr->ip_hl*4;
    180181
     
    183184        {
    184185            case 1: data_size = 14 + hlen; break;
    185             case 6: tcpptr = (struct tcphdr *) ((uint8_t *)ipptr + hlen);
     186            case 6: tcpptr = (struct libtrace_tcp *) ((uint8_t *)ipptr + hlen);
    186187                    data_size = 14 + hlen + (tcpptr->doff*4); break;
    187188            case 17: data_size = 14 + hlen + 8; break;
     
    244245
    245246        // write as much of the packet as we need (just the headers)
    246         fwrite(buffer + sizeof(pcap_pkthdr), 1, data_size, stdout);
    247     }
    248 
    249     destroy_trace(trace);
     247        fwrite(packet.buffer + sizeof(pcap_pkthdr), 1, data_size, stdout);
     248    }
     249
     250    trace_destroy(trace);
    250251    return 0;
    251252}
Note: See TracChangeset for help on using the changeset viewer.