Changeset 7068467


Ignore:
Timestamp:
02/10/06 18:02:32 (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:
6eb91ff
Parents:
7f32bb5
Message:

Major cleanup of libtrace3
Lots of documentation fixes
Lots of zerocopy fixes
Lots of config option fixes

Files:
18 edited

Legend:

Unmodified
Added
Removed
  • lib/Makefile.am

    r37195b4 r7068467  
    66                format_erf.c format_pcap.c format_wag.c format_legacy.c \
    77                format_helper.c format_helper.h \
    8                 parse_cmd.c parse_cmd.h libtrace_int.h lt_inttypes.h
     8                parse_cmd.c parse_cmd.h libtrace_int.h lt_inttypes.h \
     9                linktypes.c
    910if DAG2_4
    1011nodist_libtrace_la_SOURCES = dagopts.c dagapi.c
  • lib/common.h

    rf66a4933 r7068467  
    2525#endif
    2626
    27 #endif // COMMON_H
     27#endif /* COMMON_H */
  • lib/dagformat.h

    rd91dd4e r7068467  
    3838
    3939typedef struct flags {
    40         uint8_t   iface:2;
    41         uint8_t   vlen:1;
    42         uint8_t   trunc:1;
    43         uint8_t   rxerror:1;
    44         uint8_t   dserror:1;
    45         uint8_t   pad:2;
     40        unsigned int   iface:2;
     41        unsigned int   vlen:1;
     42        unsigned int   trunc:1;
     43        unsigned int   rxerror:1;
     44        unsigned int   dserror:1;
     45        unsigned int   pad:2;
    4646} __attribute__((packed)) flags_t;
    4747
     
    8787#define dag_record_size         16
    8888
    89 #endif // _DAGFORMAT_H_
     89#endif /* _DAGFORMAT_H_ */
  • lib/fifo.c

    r9c6aa95 r7068467  
    9898{
    9999        assert(fifo);
    100         //free(tracefifo_stat_buffer);
    101100        free(fifo->base);
    102101        free(fifo);
     
    116115
    117116void tracefifo_flush(struct tracefifo_t *fifo __attribute__((unused))) {
    118         // do nothing
     117        /* do nothing */
    119118        return;
    120119}
     
    220219                                size);
    221220                increment_pointer(fifo,which,size);
    222                 buffer += size;
     221                buffer = (char*)buffer+size;
    223222                lenleft -= size;
    224223        }
  • lib/fifo.h

    rb5cd711 r7068467  
    3232#ifndef _FIFO_H_
    3333#define _FIFO_H_
     34#include <inttypes.h>
    3435
    3536struct tracefifo_t;
    3637
    3738typedef struct tracefifo_state {
    38         long long int in;
    39         long long int out;
    40         long long int ack;
    41         long long int length;
    42         long long int used;
     39        uint64_t in;
     40        uint64_t out;
     41        uint64_t ack;
     42        uint64_t length;
     43        uint64_t used;
    4344} tracefifo_state_t;
    4445
     
    7071
    7172
    72 #endif // _FIFO_H_
     73#endif /* _FIFO_H_ */
  • lib/format_erf.c

    r37195b4 r7068467  
    3030#define _GNU_SOURCE
    3131
     32#define RT_MSG 2
     33#define RT_DATA 1
     34
    3235#include "config.h"
    3336#include "common.h"
     
    98101                gzFile *file;
    99102#else   
    100                 //FILE  *file;
    101103                int file;
    102104#endif
     
    129131                struct {
    130132                        int level;
    131                         int append;
     133                        int fileflag;
    132134                } erf;
    133135               
     
    140142                gzFile *file;
    141143#else
    142                 //FILE *file;
    143144                int file;
    144145#endif
    145146        } output;
    146147};
     148
     149/** Structure holding status information for a packet */
     150typedef struct libtrace_packet_status {
     151        uint8_t type;
     152        uint8_t reserved;
     153        uint16_t message;
     154} libtrace_packet_status_t;
     155
    147156
    148157#ifdef HAVE_DAG
     
    158167        }
    159168        if (S_ISCHR(buf.st_mode)) {
    160                 // DEVICE
     169                /* DEVICE */
    161170                libtrace->sourcetype = DEVICE;
    162171                if((INPUT.fd = dag_open(CONNINFO.path)) < 0) {
     
    209218        CONNINFO.path = libtrace->uridata;
    210219        if (!strncmp(CONNINFO.path,"-",1)) {
    211                 // STDIN
     220                /* STDIN */
    212221                libtrace->sourcetype = STDIN;
    213222                INPUT.file = LIBTRACE_FDOPEN(fileno(stdin), "r");
     
    242251                        libtrace->sourcetype = TRACE;
    243252
    244                         // we use an FDOPEN call to reopen an FD
    245                         // returned from open(), so that we can set
    246                         // O_LARGEFILE. This gets around gzopen not
    247                         // letting you do this...
     253                        /* we use an FDOPEN call to reopen an FD
     254                         * returned from open(), so that we can set
     255                         * O_LARGEFILE. This gets around gzopen not
     256                         * letting you do this...
     257                         */
    248258                        INPUT.file = LIBTRACE_FDOPEN(open(
    249259                                                CONNINFO.path,
     
    307317
    308318static int erf_init_output(struct libtrace_out_t *libtrace) {
    309         int fd;
    310319        libtrace->format_data = (struct libtrace_format_data_out_t *)
    311320                calloc(1,sizeof(struct libtrace_format_data_out_t));
    312321
    313322        OPTIONS.erf.level = 0;
    314         OPTIONS.erf.append = 0;
     323        OPTIONS.erf.fileflag = O_CREAT | O_LARGEFILE | O_WRONLY;
    315324        OUTPUT.file = 0;
    316325
     
    320329static int erf_open_output(struct libtrace_out_t *libtrace) {
    321330        char *filemode;
    322         int trunc_flag = O_TRUNC;
    323331        int fd;
    324332
     
    329337#endif
    330338
    331         if (OPTIONS.erf.append) {
    332                 trunc_flag = O_APPEND;
    333         }               
    334 
    335339        if (!strncmp(libtrace->uridata,"-",1)) {
    336                 // STDOUT
     340                /* STDOUT */
    337341                OUTPUT.file = LIBTRACE_FDOPEN(fileno(stdout),filemode);
    338342        }
    339343        else {
    340                 // TRACE
    341                 fd = open(libtrace->uridata, O_CREAT | O_LARGEFILE | O_WRONLY | trunc_flag,
     344                /* TRACE */
     345                fd = open(libtrace->uridata,
     346                                OPTIONS.erf.fileflag,
    342347                                S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
    343348                if (fd <= 0) {
     
    351356}
    352357
    353 static int erf_config_output(struct libtrace_out_t *libtrace, int argc, char *argv[]) {
    354         int opt;
    355         int level = OPTIONS.erf.level;
    356         optind = 1;
    357 
    358 
    359         while ((opt = getopt(argc, argv, "z:a")) != EOF) {
    360                 switch (opt) {
    361                         case 'z':
    362                                 level = atoi(optarg);
    363                                 break;
    364                         case 'a':
    365                                 OPTIONS.erf.append = 1;
    366                                 break;
    367                         default:
    368                                 printf("Bad argument to erf: %s\n", optarg);
    369                                 // maybe spit out some help here
    370                                 return -1;
    371                 }
    372         }
    373        
    374         return 0;
    375 
     358static int erf_config_output(struct libtrace_out_t *libtrace, trace_option_t option, void *value) {
     359
     360        switch (option) {
     361                case TRACE_OPTION_OUTPUT_COMPRESS:
     362                        OPTIONS.erf.level = *(int*)value;
     363                        return 0;
     364                case TRACE_OPTION_OUTPUT_FILEFLAGS:
     365                        OPTIONS.erf.fileflag = *(int*)value;
     366                        return 0;
     367                default:
     368                        /* Unknown option */
     369                        return -1;
     370        }
    376371}
    377372
     
    443438                return numbytes;
    444439
    445         //DAG always gives us whole packets
     440        /*DAG always gives us whole packets */
    446441        erfptr = (dag_record_t *) ((void *)DAG.buf +
    447442                        (DAG.bottom + DAG.offset));
     
    460455        }
    461456
    462        
    463         packet->status.type = RT_DATA;
    464         packet->status.message = 0;
    465457        packet->size = size;
    466458        DAG.offset += size;
     
    476468        int numbytes;
    477469        int size;
    478         void *buffer = packet->buffer;
    479         void *buffer2 = buffer;
     470        void *buffer2 = packet->buffer;
    480471        int rlen;
    481472        if (packet->buf_control == EXTERNAL) {
     
    483474                packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE);
    484475        }
    485         buffer = packet->buffer;
    486476        packet->header = packet->buffer;
    487477
     478        if (packet->buffer) {
     479                packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE);
     480                packet->buf_control = PACKET;
     481        }
     482
    488483
    489484        if ((numbytes=LIBTRACE_READ(INPUT.file,
    490                                         buffer,
     485                                        packet->buffer,
    491486                                        dag_record_size)) == -1) {
    492487                perror("libtrace_read");
     
    497492        }
    498493
    499         rlen = ntohs(((dag_record_t *)buffer)->rlen);
    500         buffer2 = buffer + dag_record_size;
     494        rlen = ntohs(((dag_record_t *)packet->buffer)->rlen);
     495        buffer2 = (char*)packet->buffer + dag_record_size;
    501496        size = rlen - dag_record_size;
    502497        assert(size < LIBTRACE_PACKET_BUFSIZE);
     
    509504        */
    510505        /* Unknown/corrupt */
    511         assert(((dag_record_t *)buffer)->type < 10);
    512        
    513         // read in the rest of the packet
     506        assert(((dag_record_t *)packet->buffer)->type < 10);
     507       
     508        /* read in the rest of the packet */
    514509        if ((numbytes=LIBTRACE_READ(INPUT.file,
    515510                                        buffer2,
     
    518513                return -1;
    519514        }
    520         packet->status.type = RT_DATA;
    521         packet->status.message = 0;
    522515        packet->size = rlen;
    523         if (((dag_record_t *)buffer)->flags.rxerror == 1) {
     516        if (((dag_record_t *)packet->buffer)->flags.rxerror == 1) {
    524517                packet->payload = NULL;
    525518        } else {
    526                 packet->payload = packet->buffer + erf_get_framing_length(packet);
     519                packet->payload = (char*)packet->buffer + erf_get_framing_length(packet);
    527520        }
    528521        return rlen;
     
    543536                                                MSG_NOSIGNAL)) == -1) {
    544537                        if (errno == EINTR) {
    545                                 //ignore EINTR in case
    546                                 // a caller is using signals
     538                                /*ignore EINTR in case
     539                                 *a caller is using signals
     540                                 */
    547541                                continue;
    548542                        }
     
    575569       
    576570        do {
     571                struct libtrace_packet_status status;
    577572                if (tracefifo_out_available(libtrace->fifo) == 0 || read_required) {
    578573                        if ((numbytes = rtclient_read(
     
    583578                        read_required = 0;
    584579                }
    585                 // Read status byte
     580                /* Read status byte */
    586581                if (tracefifo_out_read(libtrace->fifo,
    587                                 &packet->status, sizeof(uint32_t)) == 0) {
     582                                &status, sizeof(uint32_t)) == 0) {
    588583                        read_required = 1;
    589584                        continue;
    590585                }
    591586                tracefifo_out_update(libtrace->fifo,sizeof(uint32_t));
    592                 // Read in packet size
     587                /* Read in packet size */
    593588                if (tracefifo_out_read(libtrace->fifo,
    594589                                &packet->size, sizeof(uint32_t)) == 0) {
     
    608603                }
    609604                */
    610                 if (packet->status.type == RT_MSG) {
    611                         // Need to skip this packet as it is a message packet
     605                if (status.type == RT_MSG) {
     606                        /* Need to skip this packet as it is a message packet */
    612607                        tracefifo_out_update(libtrace->fifo, packet->size);
    613608                        tracefifo_ack_update(libtrace->fifo, packet->size +
     
    617612                }
    618613               
    619                 //size = ntohs(((dag_record_t *)buffer)->rlen);
    620                
    621                 // read in the full packet
     614                /* read in the full packet */
    622615                if ((numbytes = tracefifo_out_read(libtrace->fifo,
    623616                                                buffer, packet->size)) == 0) {
     
    627620                }
    628621
    629                 // got in our whole packet, so...
     622                /* got in our whole packet, so... */
    630623                tracefifo_out_update(libtrace->fifo,packet->size);
    631624
     
    634627                                sizeof(libtrace_packet_status_t));
    635628
    636                 //packet->size = numbytes;
    637629                if (((dag_record_t *)buffer)->flags.rxerror == 1) {
    638630                        packet->payload = NULL;
    639631                } else {
    640                         packet->payload = packet->buffer + erf_get_framing_length(packet);
     632                        packet->payload = (char*)packet->buffer + erf_get_framing_length(packet);
    641633                }
    642634                return numbytes;
     
    698690                                        (dag_record_size + pad));
    699691        } else {
    700                 // convert format - build up a new erf header
    701                 // Timestamp
     692                /* convert format - build up a new erf header */
     693                /* Timestamp */
    702694                erfhdr.ts = trace_get_erf_timestamp(packet);
    703                 // Flags. Can't do this
     695                erfhdr.type = libtrace_to_erf_type(trace_get_link_type(packet));
     696                /* Flags. Can't do this */
    704697                memset(&erfhdr.flags,1,1);
    705                 // Packet length (rlen includes format overhead)
     698                /* Packet length (rlen includes format overhead) */
    706699                erfhdr.rlen = trace_get_capture_length(packet) + erf_get_framing_length(packet);
    707                 // loss counter. Can't do this
     700                /* loss counter. Can't do this */
    708701                erfhdr.lctr = 0;
    709                 // Wire length
     702                /* Wire length */
    710703                erfhdr.wlen = trace_get_wire_length(packet);
    711704               
    712                 // Write it out
     705                /* Write it out */
    713706                numbytes = erf_dump_packet(libtrace,
    714707                                &erfhdr,
     
    720713}
    721714
    722 static void *erf_get_link(const struct libtrace_packet_t *packet) {
    723         return (void *)packet->payload;
    724 }
    725 
    726715static libtrace_linktype_t erf_get_link_type(const struct libtrace_packet_t *packet) {
    727716        dag_record_t *erfptr = 0;
    728717        erfptr = (dag_record_t *)packet->header;
    729         switch (erfptr->type) {
    730                 case TYPE_LEGACY:       return TRACE_TYPE_LEGACY;
    731                 case TYPE_ETH:          return TRACE_TYPE_ETH;
    732                 case TYPE_ATM:          return TRACE_TYPE_ATM;
    733                 default:
    734                                fprintf(stderr,"Unknown erf type %02x\n",erfptr->type);
    735                                assert(0);
    736         }
    737         return erfptr->type;
     718        return erf_type_to_libtrace(erfptr->type);
    738719}
    739720
     
    773754        assert(packet);
    774755        if((size + erf_get_framing_length(packet)) > packet->size) {
    775                 // can't make a packet larger
     756                /* can't make a packet larger */
    776757                return (packet->size - erf_get_framing_length(packet));
    777758        }
  • lib/format_helper.h

    r8184acc r7068467  
    3636struct libtrace_eventobj_t trace_event_device(struct libtrace_t *trace, struct libtrace_packet_t *packet);
    3737struct libtrace_eventobj_t trace_event_trace(struct libtrace_t *trace, struct libtrace_packet_t *packet);
    38 #endif // FORMAT_HELPER_H
     38#endif /* FORMAT_HELPER_H */
  • lib/format_legacy.c

    r37195b4 r7068467  
    193193                return -1;
    194194        }
    195         packet->status.type = RT_DATA;
    196         packet->status.message = 0;
    197195        packet->size = 64;
    198196       
  • lib/format_pcap.c

    r37195b4 r7068467  
    152152                }       
    153153        }
    154         //fprintf(stderr,       "Unsupported scheme (%s) for format pcap\n",
    155         //              CONNINFO.path);
    156154        return 1;
    157155       
     
    209207        int numbytes = 0;
    210208
     209        /*
    211210        // pcap provides us with the right bits, in it's own buffers.
    212211        // We hijack them.
     212        */
    213213        numbytes = pcaphdr->len;
    214214
     
    231231                return pcapbytes;
    232232        }
    233         packet->status.type = RT_DATA;
    234         packet->status.message = 0;
    235233        return (packet->size - sizeof(struct pcap_pkthdr));
    236234}
     
    251249                pcap_dump((u_char*)OUTPUT.trace.dump,(struct pcap_pkthdr *)packet->header,packet->payload);
    252250        } else {
    253                 // Leave the manual copy as it is, as it gets around
    254                 // some OS's having different structures in pcap_pkt_hdr
     251                /* Leave the manual copy as it is, as it gets around
     252                 * some OS's having different structures in pcap_pkt_hdr
     253                 */
    255254                struct timeval ts = trace_get_timeval(packet);
    256255                pcap_pkt_hdr.ts.tv_sec = ts.tv_sec;
     
    265264
    266265static int pcapint_write_packet(struct libtrace_out_t *libtrace __attribute__((unused)), const struct libtrace_packet_t *packet __attribute__((unused))) {
    267 //      void *link = trace_get_link(packet);
    268266
    269267        return 0;
    270 }
    271 
    272 static void *pcap_get_link(const struct libtrace_packet_t *packet) {
    273         return (void *) packet->payload;
    274268}
    275269
     
    382376        assert(packet);
    383377        if ((size + sizeof(struct pcap_pkthdr)) > packet->size) {
    384                 // can't make a packet larger
     378                /* can't make a packet larger */
    385379                return (packet->size - sizeof(struct pcap_pkthdr));
    386380        }
     
    478472};
    479473
    480 //pcap_ptr = &pcap;
    481 //pcapint_ptr = &pcapint;
    482 
    483474void __attribute__((constructor)) pcap_constructor() {
    484475        register_format(&pcap);
  • lib/format_wag.c

    r37195b4 r7068467  
    9999                gzFile *file;
    100100#else   
    101                 //FILE *file;
    102101                int file;
    103102#endif
     
    119118                gzFile *file;
    120119#else
    121                 //FILE *file;
    122120                int file;
    123121#endif
     
    127125static int wag_init_input(struct libtrace_t *libtrace) {
    128126        struct stat buf;
    129         //struct sockaddr_un unix_sock;
    130127        libtrace->format_data = (struct libtrace_format_data_t *)
    131128                calloc(1,sizeof(struct libtrace_format_data_t));
     
    151148
    152149static int wtf_init_input(struct libtrace_t *libtrace) {
    153         struct stat buf;
    154         struct sockaddr_un unix_sock;
    155150
    156151        libtrace->format_data = (struct libtrace_format_data_t *)
     
    159154
    160155        if (!strncmp(CONNINFO.path,"-",1)) {
    161                 // STDIN
     156                /* STDIN */
    162157                libtrace->sourcetype = STDIN;
    163158                INPUT.file = LIBTRACE_FDOPEN(fileno(stdin),"r");
    164159
    165160        } else {
    166 
    167 
    168                 // Do we need this socket stuff at all??
    169                 // If we do, put it into wag_init_input as it uses
    170                 // INPUT.fd
     161                /* Do we need this socket stuff at all??
     162                 * If we do, put it into wag_init_input as it uses
     163                 * INPUT.fd
     164                 */
    171165
    172166                /*
     
    197191                } else {
    198192                */
    199                         // TRACE
     193                        /* TRACE */
    200194                        libtrace->sourcetype = TRACE;
    201195                       
    202                         // we use an FDOPEN call to reopen an FD
    203                         // returned from open(), so that we can set
    204                         // O_LARGEFILE. This gets around gzopen not
    205                         // letting you do this...
     196                        /* we use an FDOPEN call to reopen an FD
     197                         * returned from open(), so that we can set
     198                         * O_LARGEFILE. This gets around gzopen not
     199                         * letting you do this...
     200                         */
    206201                        INPUT.file = LIBTRACE_FDOPEN(open(
    207202                                        CONNINFO.path,
    208203                                        O_LARGEFILE), "r");
    209204
    210                 //}
    211205        }
    212206        return 1;
     
    222216        asprintf(&filemode,"wb%d",OPTIONS.zlib.level);
    223217        if (!strncmp(libtrace->uridata,"-",1)) {
    224                 // STDOUT                               
     218                /* STDOUT */
    225219                OUTPUT.file = LIBTRACE_FDOPEN(dup(1), filemode);
    226220        } else {
    227                 // TRACE
     221                /* TRACE */
    228222                OUTPUT.file = LIBTRACE_FDOPEN(open(
    229223                                        libtrace->uridata,
     
    235229}
    236230
    237 static int wtf_config_output(struct libtrace_out_t *libtrace, int argc, char *argv[]) {
     231static int wtf_config_output(struct libtrace_out_t *libtrace,
     232                trace_option_output_t option,
     233                void *value) {
     234        switch(option) {
    238235#if HAVE_ZLIB
    239         int opt;
    240         int level = OPTIONS.zlib.level;
    241         optind = 1;
    242         while ((opt = getopt(argc, argv, "z:")) != EOF) {
    243                 switch (opt) {
    244                         case 'z':
    245                                 level = atoi(optarg);
    246                                 break;
    247                         default:
    248                                 printf("Bad argument to wag: %s\n", optarg);
    249                                 return -1;
    250                 }
    251         }
    252         if (level != OPTIONS.zlib.level) {
    253                 if (level > 9 || level < 0) {
    254                         // retarded level choice
    255                         printf("Compression level must be between 0 and 9 inclusive - you selected %i \n", level);
    256                 } else {
    257                         OPTIONS.zlib.level = level;
    258                         return gzsetparams(OUTPUT.file, level, Z_DEFAULT_STRATEGY);
    259                 }
    260         }
    261 #endif
    262         return 0;
     236                case TRACE_OPTION_OUTPUT_COMPRESS:
     237                        OPTIONS.zlib.level = *(int*)value;
     238                        assert(OPTIONS.zlib.level>=0
     239                                        && OPTIONS.zlib.level<=9);
     240                        break;
     241#else
     242                case TRACE_OPTION_OUTPUT_COMPRESS:
     243                        /* E feature unavailable */
     244                        return -1;
     245#endif
     246                default:
     247                        /* E unknown feature */
     248                        return -1;
     249        }
    263250}
    264251
     
    280267static int wag_read(struct libtrace_t *libtrace, void *buffer, size_t len) {
    281268        int numbytes;
    282         int framesize;
     269        size_t framesize;
    283270        assert(libtrace);
    284271
     
    286273                buffer = malloc(len);
    287274
    288         // read in wag_frame_hdr
     275        /* read in wag_frame_hdr */
    289276        if ((numbytes = read(INPUT.fd,
    290277                        buffer,
     
    299286        }
    300287
    301         // read in remainder of packet
     288        /* read in remainder of packet */
    302289        if((numbytes = read(INPUT.fd,
    303                         buffer + sizeof(struct wag_frame_hdr),
     290                        (char*)buffer + sizeof(struct wag_frame_hdr),
    304291                        framesize - sizeof(struct wag_frame_hdr))) !=
    305292                        (framesize - sizeof(struct wag_frame_hdr))) {
     
    316303        int numbytes;
    317304       
    318         char buf[RP_BUFSIZE];
    319305        if (packet->buf_control == EXTERNAL) {
    320306                packet->buf_control = PACKET;
     
    331317
    332318       
    333 //      memcpy(packet->buffer, buf, numbytes);
    334        
    335         packet->status.type = RT_DATA;
    336         packet->status.message = 0;
    337319        packet->size = numbytes;
    338320        packet->header = packet->buffer;
    339         packet->payload = packet->buffer + trace_get_framing_length(packet);
     321        packet->payload=(char*)packet->buffer+trace_get_framing_length(packet);
    340322        return numbytes;
    341323}
     
    364346
    365347        framesize = ntohs(((struct wag_frame_hdr *)buffer)->size);
    366         buffer2 = buffer + sizeof(struct wag_frame_hdr);
     348        buffer2 = (char*)buffer + sizeof(struct wag_frame_hdr);
    367349        size = framesize - sizeof(struct wag_frame_hdr);
    368350        assert(size < LIBTRACE_PACKET_BUFSIZE);
     
    374356        }
    375357
    376         packet->status.type = RT_DATA;
    377         packet->status.message = 0;
    378358        packet->size = framesize;
    379359        packet->header = packet->buffer;
    380         packet->payload = packet->buffer + trace_get_framing_length(packet);
     360        packet->payload=(char*)packet->buffer+trace_get_framing_length(packet);
    381361        return framesize;
    382362       
     
    406386}
    407387
    408 static void *wag_get_link(const struct libtrace_packet_t *packet) {
    409         /*
    410         struct wag_data_frame *wagptr = (struct wag_data_frame *)packet->buffer;
    411         void *payload = wagptr->data;
    412         return (void*)payload;
    413         */
    414         return (void *)packet->payload;
    415 }
    416 
    417388static libtrace_linktype_t wag_get_link_type(const struct libtrace_packet_t *packet __attribute__((unused))) {
    418389        return TRACE_TYPE_80211;
     
    436407static int wag_get_capture_length(const struct libtrace_packet_t *packet) {
    437408        struct wag_data_frame *wagptr = (struct wag_data_frame *)packet->buffer;
    438         //return (wagptr->hdr.size);
    439409        return ntohs(wagptr->hdr.size);
    440410}
     
    442412static int wag_get_wire_length(const struct libtrace_packet_t *packet) {
    443413        struct wag_data_frame *wagptr = (struct wag_data_frame *)packet->buffer;
    444         //return (wagptr->hdr.size);
    445414        return ntohs(wagptr->hdr.size);
    446415}
  • lib/libtrace.h

    r7f32bb5 r7068467  
    7171#  define SIMPLE_FUNCTION __attribute__((pure))
    7272#  define UNUSED __attribute__((unused))
     73#  define PACKED __attribute__((packed))
    7374#else
    7475#  define SIMPLE_FUNCTION
    7576#  define UNUSED
    7677#endif
    77        
    78 #define RT_DATA 1
    79 #define RT_MSG 2
    80 
    8178       
    8279/** Opaque structure holding information about an output trace */
     
    8986typedef struct libtrace_filter_t libtrace_filter_t;
    9087
    91 /** Structure holding status information for a packet */
    92 typedef struct libtrace_packet_status {
    93         uint8_t type;
    94         uint8_t reserved;
    95         uint16_t message;
    96 
    97 } libtrace_packet_status_t;
    98 
    9988typedef enum {PACKET, EXTERNAL } buf_control_t;
    10089/** Structure holding information about a packet */
     
    10695        void *buffer;
    10796        size_t size;
    108         libtrace_packet_status_t status;
    10997        buf_control_t buf_control;
    110 } __attribute__ ((packed)) libtrace_packet_t;
     98} libtrace_packet_t;
    11199                     
    112100
     
    114102enum {E_NOERROR, E_BAD_FORMAT, E_NO_INIT, E_NO_INIT_OUT, E_URI_LONG, E_URI_NOCOLON, E_INIT_FAILED };
    115103
     104/** @name Packet structures
     105 * These convenience structures are here as they are portable ways of dealing
     106 * with various protocols.
     107 * @{
     108 */
     109
    116110/** Structure for dealing with IP packets */
    117 typedef struct libtrace_ip
     111typedef PACKED struct libtrace_ip
    118112{
    119113#if BYTE_ORDER == LITTLE_ENDIAN
     
    129123    u_short ip_len;                     /**< total length */
    130124    u_short ip_id;                      /**< identification */
    131     u_short ip_off;                     /**< fragment offset field */
    132 #define IP_RF 0x8000                    /**< reserved fragment flag */
    133 #define IP_DF 0x4000                    /**< dont fragment flag */
    134 #define IP_MF 0x2000                    /**< more fragments flag */
    135 #define IP_OFFMASK 0x1fff               /**< mask for fragmenting bits */
     125#if BYTE_ORDER == LITTLE_ENDIAN
     126    unsigned int ip_off:12;             /**< fragment offset */
     127    unsigned int ip_mf:1;               /**< more fragments flag */
     128    unsigned int ip_df:1;               /**< dont fragment flag */
     129    unsigned int ip_rf:1;               /**< reserved fragment flag */
     130#elif BYTE_ORDER == BIG_ENDIAN
     131    unsigned int ip_rf:1;
     132    unsigned int ip_df:1;
     133    unsigned int ip_mf:1;
     134    unsigned int ip_off:12;
     135#else
     136#   error "Adjust your <bits/endian.h> defines"
     137#endif
    136138    u_int8_t ip_ttl;                    /**< time to live */
    137139    u_int8_t ip_p;                      /**< protocol */
     
    139141    struct in_addr ip_src;              /**< source address */
    140142    struct in_addr ip_dst;              /**< dest address */
    141 } __attribute__ ((packed)) libtrace_ip_t
     143} libtrace_ip_t
    142144;
    143145
     
    150152    u_int32_t ack_seq;          /**< Acknowledgement Number */
    151153#  if BYTE_ORDER == LITTLE_ENDIAN
    152     u_int16_t res1:4;           /**< Reserved bits */
    153     u_int16_t doff:4;          
    154     u_int16_t fin:1;            /**< FIN */
    155     u_int16_t syn:1;            /**< SYN flag */
    156     u_int16_t rst:1;            /**< RST flag */
    157     u_int16_t psh:1;            /**< PuSH flag */
    158     u_int16_t ack:1;            /**< ACK flag */
    159     u_int16_t urg:1;            /**< URG flag */
    160     u_int16_t res2:2;           /**< Reserved */
     154    unsigned int res1:4;        /**< Reserved bits */
     155    unsigned int doff:4;        /**< data offset */     
     156    unsigned int fin:1;         /**< FIN */
     157    unsigned int syn:1;         /**< SYN flag */
     158    unsigned int rst:1;         /**< RST flag */
     159    unsigned int psh:1;         /**< PuSH flag */
     160    unsigned int ack:1;         /**< ACK flag */
     161    unsigned int urg:1;         /**< URG flag */
     162    unsigned int res2:2;        /**< Reserved */
    161163#  elif BYTE_ORDER == BIG_ENDIAN
    162     u_int16_t doff:4;           
    163     u_int16_t res1:4;           /**< Reserved bits */
    164     u_int16_t res2:2;           /**< Reserved */
    165     u_int16_t urg:1;            /**< URG flag */
    166     u_int16_t ack:1;            /**< ACK flag */
    167     u_int16_t psh:1;            /**< PuSH flag */
    168     u_int16_t rst:1;            /**< RST flag */
    169     u_int16_t syn:1;            /**< SYN flag */
    170     u_int16_t fin:1;            /**< FIN flag */
     164    unsigned int doff:4;        /**< Data offset */
     165    unsigned int res1:4;        /**< Reserved bits */
     166    unsigned int res2:2;        /**< Reserved */
     167    unsigned int urg:1;         /**< URG flag */
     168    unsigned int ack:1;         /**< ACK flag */
     169    unsigned int psh:1;         /**< PuSH flag */
     170    unsigned int rst:1;         /**< RST flag */
     171    unsigned int syn:1;         /**< SYN flag */
     172    unsigned int fin:1;         /**< FIN flag */
    171173#  else
    172174#   error "Adjust your <bits/endian.h> defines"
     
    231233  u_int8_t  ether_shost[6];      /* source ether addr    */
    232234  u_int16_t ether_type;          /* packet type ID field , 0x8100 for VLAN */
    233   u_int16_t vlan_pri:3;          /* vlan user priority */
    234   u_int16_t vlan_cfi:1;          /* vlan format indicator, 0 for ethernet, 1 for token ring */
    235   u_int16_t vlan_id:12;          /* vlan id */
     235  unsigned int vlan_pri:3;       /* vlan user priority */
     236  unsigned int vlan_cfi:1;       /* vlan format indicator, 0 for ethernet, 1 for token ring */
     237  unsigned int vlan_id:12;       /* vlan id */
    236238  u_int16_t vlan_ether_type;     /* vlan sub-packet type ID field (next-header)*/
    237239} __attribute__ ((packed)) libtrace_8021q_t;
     
    240242typedef struct libtrace_atm_cell
    241243{
    242   u_int8_t gfc:4;
     244  unsigned int gfc:4;
    243245  u_int8_t vpi;
    244246  u_int16_t vci;
    245   u_int8_t pt:3;
    246   u_int8_t clp:1;
    247   u_int8_t hec;
     247  unsigned int pt:3;
     248  unsigned int clp:1;
     249  unsigned int hec;
    248250} __attribute__ ((packed)) libtrace_atm_cell;
    249251
     
    254256 u_int16_t ether_type;
    255257} __attribute__ ((packed)) libtrace_pos;
     258/*@}*/
    256259
    257260/** Prints help information for libtrace
     
    265268 *
    266269 * @param libtrace      the output trace to get the name of the format fo
    267  * @returns callee-owned null-terminated char* containing the output format
    268  *
    269  */
    270 SIMPLE_FUNCTION
    271 char *trace_get_output_format(const struct libtrace_out_t *libtrace);
     270 * @return callee-owned null-terminated char* containing the output format
     271 *
     272 */
     273SIMPLE_FUNCTION
     274char *trace_get_output_format(const libtrace_out_t *libtrace);
    272275
    273276/** Prints error information
     
    279282/** @name Creation and destruction of traces
    280283 * These members deal with creating, configuring and cleaning up a trace object
    281  */
    282 //@{
     284 *@{
     285 */
    283286
    284287/** Create a trace file from a URI
    285288 *
    286289 * @param uri containing a valid libtrace URI
    287  * @returns opaque pointer to a libtrace_t
     290 * @return opaque pointer to a libtrace_t
    288291 *
    289292 * Valid URI's are:
     
    310313/** Creates a "dummy" trace file that has only the format type set.
    311314 *
    312  * @returns opaque pointer to a (sparsely initialised) libtrace_t
     315 * @return opaque pointer to a (sparsely initialised) libtrace_t
    313316 *
    314317 * IMPORTANT: Do not attempt to call trace_read_packet or other such functions with
     
    321324 *
    322325 * @param uri   the uri string describing the output format and destination
    323  * @returns opaque pointer to a libtrace_output_t
     326 * @return opaque pointer to a libtrace_output_t
    324327 * @author Shane Alcock
    325328 *
     
    333336 *  and trace_errno is set. Use trace_perror() to get more information
    334337 */
    335 struct libtrace_out_t *trace_create_output(const char *uri);
    336 
    337 /** Parses an output options string and calls the appropriate function to deal with output options.
    338  *
    339  * @param libtrace      the output trace object to apply the options to
    340  * @param options       the options string
    341  * @returns -1 if option configuration failed, 0 otherwise
    342  *
    343  * @author Shane Alcock
    344  */
    345 int trace_config_output(struct libtrace_out_t *libtrace, char *options);
     338libtrace_out_t *trace_create_output(const char *uri);
     339
     340/** Start the capture
     341 * @param libtrace      The trace to start
     342 * @return 0 on success
     343 *
     344 * This does the actual work with starting the trace capture, and applying
     345 * all the config options.  This may fail.
     346 */
     347int trace_start(libtrace_t *libtrace);
     348
     349/** Start an output trace
     350 * @param libtrace      The trace to start
     351 * @return 0 on success
     352 *
     353 * This does the actual work with starting a trace for write.  This generally
     354 * creates the file.
     355 */
     356int trace_start_output(libtrace_out_t *libtrace);
     357
     358/** Valid trace capture options */
     359typedef enum {
     360        TRACE_OPTION_SNAPLEN, /**< Number of bytes captured */
     361        TRACE_OPTION_PROMISC, /**< Capture packets to other hosts */
     362        TRACE_OPTION_FILTER   /**< Apply this filter to all packets recieved */
     363} trace_option_t;
     364
     365/** Sets an input config option
     366 * @param libtrace      the trace object to apply the option to
     367 * @param option        the option to set
     368 * @param value         the value to set the option to
     369 * @return -1 if option configuration failed, 0 otherwise
     370 * This should be called after trace_create, and before trace_start
     371 */
     372int trace_config(libtrace_t *libtrace,
     373                trace_option_t option,
     374                void *value);
     375
     376typedef enum {
     377        TRACE_OPTION_OUTPUT_FILEFLAGS, /**< File flags to open the trace file
     378                                        * with.  eg O_APPEND
     379                                        */
     380        TRACE_OPTION_OUTPUT_COMPRESS   /**< Compression level, eg 6. */
     381} trace_option_output_t;
     382
     383/** Sets an output config option
     384 *
     385 * @param libtrace      the output trace object to apply the option to
     386 * @param option        the option to set
     387 * @param value         the value to set the option to
     388 * @return -1 if option configuration failed, 0 otherwise
     389 * This should be called after trace_create_output, and before
     390 * trace_start_output
     391 */
     392int trace_config_output(libtrace_out_t *libtrace,
     393                trace_option_output_t option,
     394                void *value
     395                );
    346396
    347397/** Close a trace file, freeing up any resources it may have been using
    348398 *
    349399 */
    350 void trace_destroy(struct libtrace_t *trace);
     400void trace_destroy(libtrace_t *trace);
    351401
    352402/** Close a trace file, freeing up any resources it may have been using
    353403 * @param trace         trace file to be destroyed
    354404 */
    355 void trace_destroy_dead(struct libtrace_t *trace);
     405void trace_destroy_dead(libtrace_t *trace);
    356406
    357407/** Close a trace output file, freeing up any resources it may have been using
     
    361411 * @author Shane Alcock
    362412 */
    363 void trace_destroy_output(struct libtrace_out_t *trace);
    364 //@}
     413void trace_destroy_output(libtrace_out_t *trace);
     414/*@}*/
    365415
    366416/** @name Reading/Writing packets
    367417 * These members deal with creating, reading and writing packets
    368  */
    369 //@{
     418 *
     419 * @{
     420 */
    370421
    371422/** Create a new packet object
     
    373424 * @return a pointer to an initialised libtrace_packet_t object
    374425 */
    375 struct libtrace_packet_t *trace_create_packet();
     426libtrace_packet_t *trace_create_packet();
    376427
    377428/** Destroy a packet object
     
    379430 * sideeffect: sets packet to NULL
    380431 */
    381 void trace_destroy_packet(struct libtrace_packet_t **packet);
     432void trace_destroy_packet(libtrace_packet_t **packet);
    382433
    383434
     
    386437 * @param trace         the libtrace opaque pointer
    387438 * @param packet        the packet opaque pointer
    388  * @returns 0 on EOF, negative value on error
    389  *
    390  */
    391 int trace_read_packet(struct libtrace_t *trace, struct libtrace_packet_t *packet);
     439 * @return 0 on EOF, negative value on error
     440 *
     441 * @note the trace must have been started with trace_start before calling
     442 * this function
     443 */
     444int trace_read_packet(libtrace_t *trace, libtrace_packet_t *packet);
     445
     446/** Event types
     447 * see \ref libtrace_eventobj_t and \ref trace_event
     448 */
     449typedef enum {
     450        TRACE_EVENT_IOWAIT,     /**< Need to block on fd */
     451        TRACE_EVENT_SLEEP,      /**< Sleep for some time */
     452        TRACE_EVENT_PACKET,     /**< packet has arrived */
     453        TRACE_EVENT_TERMINATE   /**< End of trace */
     454} libtrace_event_t;
     455
     456/** structure returned by libtrace_event explaining what the current event is */
     457typedef struct libtrace_eventobj_t {
     458        libtrace_event_t type; /**< event type (iowait,sleep,packet) */
     459        int fd;                /**< if IOWAIT, the fd to sleep on */
     460        double seconds;        /**< if SLEEP, the amount of time to sleep for */
     461        int size;              /**< if PACKET, the value returned from trace_read_packet */
     462} libtrace_eventobj_t;
     463
     464/** process a libtrace event
     465 * @param trace the libtrace opaque pointer
     466 * @param packet the libtrace_packet opaque pointer
     467 * @return libtrace_event struct containing the type, and potential
     468 *      fd or seconds to sleep on
     469 *
     470 * Type can be:
     471 *  TRACE_EVENT_IOWAIT  Waiting on I/O on fd
     472 *  TRACE_EVENT_SLEEP   Next event in seconds
     473 *  TRACE_EVENT_PACKET  Packet arrived in buffer with size size
     474 *  TRACE_EVENT_TERMINATE Trace terminated (perhaps with an error condition)
     475 */
     476libtrace_eventobj_t trace_event(libtrace_t *trace,
     477                libtrace_packet_t *packet);
     478
    392479
    393480/** Write one packet out to the output trace
     
    395482 * @param trace         the libtrace_out opaque pointer
    396483 * @param packet        the packet opaque pointer
    397  * @returns the number of bytes written out, if zero or negative then an error has occured.
    398  */
    399 int trace_write_packet(struct libtrace_out_t *trace, const struct libtrace_packet_t *packet);
    400 //@}
     484 * @return the number of bytes written out, if zero or negative then an error has occured.
     485 */
     486int trace_write_packet(libtrace_out_t *trace, const libtrace_packet_t *packet);
     487/*@}*/
    401488
    402489/** @name Headers
    403490 * These functions locate and return a pointer to various headers inside a packet
    404  */
    405 //@{
     491 * @{
     492 */
    406493
    407494/** get a pointer to the link layer
    408495 * @param packet        the packet opaque pointer
    409496 *
    410  * @returns a pointer to the link layer, or NULL if there is no link layer
     497 * @return a pointer to the link layer, or NULL if there is no link layer
    411498 *
    412499 * @note you should call getLinkType() to find out what type of link layer
     
    414501 */
    415502SIMPLE_FUNCTION
    416 void *trace_get_link(const struct libtrace_packet_t *packet);
     503void *trace_get_link(const libtrace_packet_t *packet);
    417504
    418505/** get a pointer to the IP header (if any)
    419506 * @param packet        the packet opaque pointer
    420507 *
    421  * @returns a pointer to the IP header, or NULL if there is not an IP packet
    422  */
    423 SIMPLE_FUNCTION
    424 struct libtrace_ip *trace_get_ip(const struct libtrace_packet_t *packet);
     508 * @return a pointer to the IP header, or NULL if there is not an IP packet
     509 */
     510SIMPLE_FUNCTION
     511libtrace_ip_t *trace_get_ip(const libtrace_packet_t *packet);
    425512
    426513/** Gets a pointer to the transport layer header (if any)
    427514 * @param packet        a pointer to a libtrace_packet structure
    428515 *
    429  * @returns a pointer to the transport layer header, or NULL if there is no header
    430  */
    431 void *trace_get_transport(const struct libtrace_packet_t *packet);
     516 * @return a pointer to the transport layer header, or NULL if there is no header
     517 */
     518void *trace_get_transport(const libtrace_packet_t *packet);
    432519
    433520/** Gets a pointer to the transport layer header (if any) given a pointer to the
     
    436523 * @param[out] skipped  An output variable of the number of bytes skipped
    437524 *
    438  * @returns a pointer to the transport layer header, or NULL if there is no header
     525 * @return a pointer to the transport layer header, or NULL if there is no header
    439526 *
    440527 * Skipped can be NULL, in which case it will be ignored
    441528 */
    442 void *trace_get_transport_from_ip(const struct libtrace_ip *ip, int *skipped);
     529void *trace_get_transport_from_ip(const libtrace_ip_t *ip, int *skipped);
    443530
    444531/** get a pointer to the TCP header (if any)
    445532 * @param packet        the packet opaque pointer
    446533 *
    447  * @returns a pointer to the TCP header, or NULL if there is not a TCP packet
    448  */
    449 SIMPLE_FUNCTION
    450 struct libtrace_tcp *trace_get_tcp(const struct libtrace_packet_t *packet);
     534 * @return a pointer to the TCP header, or NULL if there is not a TCP packet
     535 */
     536SIMPLE_FUNCTION
     537libtrace_tcp_t *trace_get_tcp(const libtrace_packet_t *packet);
    451538
    452539/** get a pointer to the TCP header (if any) given a pointer to the IP header
     
    454541 * @param[out] skipped  An output variable of the number of bytes skipped
    455542 *
    456  * @returns a pointer to the TCP header, or NULL if this is not a TCP packet
     543 * @return a pointer to the TCP header, or NULL if this is not a TCP packet
    457544 *
    458545 * Skipped can be NULL, in which case it will be ignored by the program.
     
    461548 */
    462549SIMPLE_FUNCTION
    463 struct libtrace_tcp *trace_get_tcp_from_ip(const struct libtrace_ip *ip,int *skipped);
     550libtrace_tcp_t *trace_get_tcp_from_ip(const libtrace_ip_t *ip,int *skipped);
    464551
    465552/** get a pointer to the UDP header (if any)
    466553 * @param packet        the packet opaque pointer
    467554 *
    468  * @returns a pointer to the UDP header, or NULL if this is not a UDP packet
    469  */
    470 SIMPLE_FUNCTION
    471 struct libtrace_udp *trace_get_udp(const struct libtrace_packet_t *packet);
     555 * @return a pointer to the UDP header, or NULL if this is not a UDP packet
     556 */
     557SIMPLE_FUNCTION
     558libtrace_udp_t *trace_get_udp(const libtrace_packet_t *packet);
    472559
    473560/** get a pointer to the UDP header (if any) given a pointer to the IP header
     
    475562 * @param[out]  skipped An output variable of the number of bytes skipped
    476563 *
    477  * @returns a pointer to the UDP header, or NULL if this is not an UDP packet
     564 * @return a pointer to the UDP header, or NULL if this is not an UDP packet
    478565 *
    479566 * Skipped may be NULL, in which case it will be ignored by this function.
    480567 */
    481568SIMPLE_FUNCTION
    482 struct libtrace_udp *trace_get_udp_from_ip(const struct libtrace_ip *ip,int *skipped);
     569libtrace_udp_t *trace_get_udp_from_ip(const libtrace_ip_t *ip,int *skipped);
    483570
    484571/** get a pointer to the ICMP header (if any)
    485572 * @param packet        the packet opaque pointer
    486573 *
    487  * @returns a pointer to the ICMP header, or NULL if this is not a ICMP packet
    488  */
    489 SIMPLE_FUNCTION
    490 struct libtrace_icmp *trace_get_icmp(const struct libtrace_packet_t *packet);
     574 * @return a pointer to the ICMP header, or NULL if this is not a ICMP packet
     575 */
     576SIMPLE_FUNCTION
     577libtrace_icmp_t *trace_get_icmp(const libtrace_packet_t *packet);
    491578
    492579/** get a pointer to the ICMP header (if any) given a pointer to the IP header
     
    494581 * @param[out] skipped  An output variable of the number of bytes skipped
    495582 *
    496  * @returns a pointer to the ICMP header, or NULL if this is not an ICMP packet
     583 * @return a pointer to the ICMP header, or NULL if this is not an ICMP packet
    497584 *
    498585 * Skipped may be NULL, in which case it will be ignored by this function
    499586 */
    500587SIMPLE_FUNCTION
    501 struct libtrace_icmp *trace_get_icmp_from_ip(const struct libtrace_ip *ip,int *skipped);
    502 //@}
     588libtrace_icmp_t *trace_get_icmp_from_ip(const libtrace_ip_t *ip,int *skipped);
     589/*@}*/
    503590
    504591/** parse an ip or tcp option
     
    509596 * @param[out] data     the data of the option
    510597 *
    511  * @returns bool true if there is another option (and the fields are filled in)
     598 * @return bool true if there is another option (and the fields are filled in)
    512599 *               or false if this was the last option.
    513600 *
     
    528615 * These functions deal with time that a packet arrived and return it
    529616 * in various formats
    530  */
    531 //@{
     617 * @{
     618 */
    532619/** Get the current time in DAG time format
    533620 * @param packet        the packet opaque pointer
    534621 *
    535  * @returns a 64 bit timestamp in DAG ERF format (upper 32 bits are the seconds
     622 * @return a 64 bit timestamp in DAG ERF format (upper 32 bits are the seconds
    536623 * past 1970-01-01, the lower 32bits are partial seconds)
    537624 * @author Daniel Lawson
    538625 */
    539626SIMPLE_FUNCTION
    540 uint64_t trace_get_erf_timestamp(const struct libtrace_packet_t *packet);
     627uint64_t trace_get_erf_timestamp(const libtrace_packet_t *packet);
    541628
    542629/** Get the current time in struct timeval
    543630 * @param packet        the packet opaque pointer
    544631 *
    545  * @returns time that this packet was seen in a struct timeval
     632 * @return time that this packet was seen in a struct timeval
    546633 * @author Daniel Lawson
    547634 * @author Perry Lorier
    548635 */
    549636SIMPLE_FUNCTION
    550 struct timeval trace_get_timeval(const struct libtrace_packet_t *packet);
     637struct timeval trace_get_timeval(const libtrace_packet_t *packet);
    551638
    552639/** Get the current time in floating point seconds
    553640 * @param packet        the packet opaque pointer
    554641 *
    555  * @returns time that this packet was seen in 64bit floating point seconds
    556  * @author Daniel Lawson
    557  * @author Perry Lorier
    558  */
    559 SIMPLE_FUNCTION
    560 double trace_get_seconds(const struct libtrace_packet_t *packet);
    561 //@}
     642 * @return time that this packet was seen in 64bit floating point seconds
     643 * @author Daniel Lawson
     644 * @author Perry Lorier
     645 */
     646SIMPLE_FUNCTION
     647double trace_get_seconds(const libtrace_packet_t *packet);
     648/*@}*/
    562649
    563650/** @name Sizes
    564651 * This section deals with finding or setting the various different lengths
    565652 * a packet can have
    566  */
    567 //@{
     653 * @{
     654 */
    568655/** Get the size of the packet in the trace
    569656 * @param packet        the packet opaque pointer
    570  * @returns the size of the packet in the trace
     657 * @return the size of the packet in the trace
    571658 * @author Perry Lorier
    572659 * @note Due to this being a header capture, or anonymisation, this may not
     
    578665 */
    579666SIMPLE_FUNCTION
    580 int trace_get_capture_length(const struct libtrace_packet_t *packet);
     667int trace_get_capture_length(const libtrace_packet_t *packet);
    581668
    582669/** Get the size of the packet as it was seen on the wire.
    583670 * @param packet        the packet opaque pointer
    584  * @returns the size of the packet as it was on the wire.
     671 * @return the size of the packet as it was on the wire.
    585672 * @author Perry Lorier
    586673 * @author Daniel Lawson
     
    589676 */
    590677SIMPLE_FUNCTION
    591 int trace_get_wire_length(const struct libtrace_packet_t *packet);
     678int trace_get_wire_length(const libtrace_packet_t *packet);
    592679
    593680/** Get the length of the capture framing headers.
    594681 * @param packet        the packet opaque pointer
    595  * @returns the size of the packet as it was on the wire.
     682 * @return the size of the packet as it was on the wire.
    596683 * @author Perry Lorier
    597684 * @author Daniel Lawson
     
    600687 */
    601688SIMPLE_FUNCTION
    602 int trace_get_framing_length(const struct libtrace_packet_t *packet);
     689int trace_get_framing_length(const libtrace_packet_t *packet);
    603690
    604691/** Truncate the packet at the suggested length
    605692 * @param packet        the packet opaque pointer
    606693 * @param size          the new length of the packet
    607  * @returns the new length of the packet, or the original length of the
     694 * @return the new length of the packet, or the original length of the
    608695 * packet if unchanged
    609696 * @author Daniel Lawson
    610697 */
    611 size_t trace_set_capture_length(struct libtrace_packet_t *packet, size_t size);
    612 
    613 //@}
     698size_t trace_set_capture_length(libtrace_packet_t *packet, size_t size);
     699
     700/*@}*/
    614701
    615702
     
    635722/** Get the type of the link layer
    636723 * @param packet        the packet opaque pointer
    637  * @returns libtrace_linktype_t
    638  * @author Perry Lorier
    639  * @author Daniel Lawson
    640  */
    641 SIMPLE_FUNCTION
    642 inline libtrace_linktype_t trace_get_link_type(const struct libtrace_packet_t *packet);
     724 * @return libtrace_linktype_t
     725 * @author Perry Lorier
     726 * @author Daniel Lawson
     727 */
     728SIMPLE_FUNCTION
     729inline libtrace_linktype_t trace_get_link_type(const libtrace_packet_t *packet);
    643730
    644731/** Get the destination MAC addres
    645732 * @param packet        the packet opaque pointer
    646  * @returns a pointer to the destination mac, (or NULL if there is no
     733 * @return a pointer to the destination mac, (or NULL if there is no
    647734 * destination MAC)
    648735 * @author Perry Lorier
    649736 */
    650737SIMPLE_FUNCTION
    651 uint8_t *trace_get_destination_mac(const struct libtrace_packet_t *packet);
     738uint8_t *trace_get_destination_mac(const libtrace_packet_t *packet);
    652739
    653740/** Get the source MAC addres
    654741 * @param packet        the packet opaque pointer
    655  * @returns a pointer to the source mac, (or NULL if there is no source MAC)
    656  * @author Perry Lorier
    657  */
    658 SIMPLE_FUNCTION
    659 uint8_t *trace_get_source_mac(const struct libtrace_packet_t *packet);
     742 * @return a pointer to the source mac, (or NULL if there is no source MAC)
     743 * @author Perry Lorier
     744 */
     745SIMPLE_FUNCTION
     746uint8_t *trace_get_source_mac(const libtrace_packet_t *packet);
    660747
    661748/** Set the direction flag, if it has one
    662749 * @param packet        the packet opaque pointer
    663750 * @param direction     the new direction (0,1,2,3)
    664  * @returns a signed value containing the direction flag, or -1 if this is not supported
    665  * @author Daniel Lawson
    666  */
    667 int8_t trace_set_direction(struct libtrace_packet_t *packet, int8_t direction);
     751 * @return a signed value containing the direction flag, or -1 if this is not supported
     752 * @author Daniel Lawson
     753 */
     754int8_t trace_set_direction(libtrace_packet_t *packet, int8_t direction);
    668755
    669756/** Get the direction flag, if it has one
    670757 * @param packet        the packet opaque pointer
    671  * @returns a signed value containing the direction flag, or -1 if this is not supported
     758 * @return a signed value containing the direction flag, or -1 if this is not supported
    672759 * The direction is defined as 0 for packets originating locally (ie, outbound)
    673760 * and 1 for packets originating remotely (ie, inbound).
     
    677764 */
    678765SIMPLE_FUNCTION
    679 int8_t trace_get_direction(const struct libtrace_packet_t *packet);
    680 
    681 /** Event types
    682  * see \ref libtrace_eventobj_t and \ref trace_event
    683  */
    684 typedef enum {
    685         TRACE_EVENT_IOWAIT,     /**< Need to block on fd */
    686         TRACE_EVENT_SLEEP,      /**< Sleep for some time */
    687         TRACE_EVENT_PACKET,     /**< packet has arrived */
    688         TRACE_EVENT_TERMINATE   /**< End of trace */
    689 } libtrace_event_t;
    690 
    691 /** structure returned by libtrace_event explaining what the current event is */
    692 struct libtrace_eventobj_t {
    693         libtrace_event_t type; /**< event type (iowait,sleep,packet) */
    694         int fd;                /**< if IOWAIT, the fd to sleep on */
    695         double seconds;        /**< if SLEEP, the amount of time to sleep for */
    696         int size;              /**< if PACKET, the value returned from trace_read_packet */
    697 };
    698 
    699 /** process a libtrace event
    700  * @param trace the libtrace opaque pointer
    701  * @param packet the libtrace_packet opaque pointer
    702  * @returns libtrace_event struct containing the type, and potential
    703  *      fd or seconds to sleep on
    704  *
    705  * Type can be:
    706  *  TRACE_EVENT_IOWAIT  Waiting on I/O on fd
    707  *  TRACE_EVENT_SLEEP   Next event in seconds
    708  *  TRACE_EVENT_PACKET  Packet arrived in buffer with size size
    709  *  TRACE_EVENT_TERMINATE Trace terminated (perhaps with an error condition)
    710  */
    711 struct libtrace_eventobj_t trace_event(struct libtrace_t *trace,
    712                 struct libtrace_packet_t *packet);
     766int8_t trace_get_direction(const libtrace_packet_t *packet);
    713767
    714768/** @name BPF
    715769 * This section deals with using Berkley Packet Filters
    716  */
    717 //@{
     770 * @{
     771 */
    718772/** setup a BPF filter
    719773 * @param filterstring a char * containing the bpf filter string
    720  * @returns opaque pointer pointer to a libtrace_filter_t object
     774 * @return opaque pointer pointer to a libtrace_filter_t object
    721775 * @author Daniel Lawson
    722776 * @note The filter is not actually compiled at this point, so no correctness
     
    726780 */
    727781SIMPLE_FUNCTION
    728 struct libtrace_filter_t *trace_bpf_setfilter(const char *filterstring);
     782libtrace_filter_t *trace_bpf_setfilter(const char *filterstring);
    729783
    730784/** apply a BPF filter
    731785 * @param filter        the filter opaque pointer
    732786 * @param packet        the packet opaque pointer
    733  * @returns 0 if the filter fails, 1 if it succeeds
     787 * @return 0 if the filter fails, 1 if it succeeds
    734788 * @author Daniel Lawson
    735789 * @note Due to the way BPF filters are built, the filter is not actually compiled
    736790 * until the first time trace_bpf_filter is called. If your filter is incorrect, it will generate an error message and assert, exiting the program. This behaviour may change to more graceful handling of this error in the future.
    737791 */
    738 int trace_bpf_filter(struct libtrace_filter_t *filter,
    739                 const struct libtrace_packet_t *packet);
    740 //@}
     792int trace_bpf_filter(libtrace_filter_t *filter,
     793                const libtrace_packet_t *packet);
     794/*@}*/
    741795
    742796/** Which port is the server port */
     
    748802/** Get the source port
    749803 * @param packet        the packet to read from
    750  * @returns a port in \em HOST byte order, or equivilent to ports for this
     804 * @return a port in \em HOST byte order, or equivilent to ports for this
    751805 * protocol, or 0 if this protocol has no ports.
    752806 * @author Perry Lorier
    753807 */
    754808SIMPLE_FUNCTION
    755 uint16_t trace_get_source_port(const struct libtrace_packet_t *packet);
     809uint16_t trace_get_source_port(const libtrace_packet_t *packet);
    756810
    757811/** Get the destination port
    758812 * @param packet        the packet to read from
    759  * @returns a port in \em HOST byte order, or equivilent to ports for this
     813 * @return a port in \em HOST byte order, or equivilent to ports for this
    760814 * protocol, or 0 if this protocol has no ports.
    761815 * @author Perry Lorier
    762816 */
    763817SIMPLE_FUNCTION
    764 uint16_t trace_get_destination_port(const struct libtrace_packet_t *packet);
     818uint16_t trace_get_destination_port(const libtrace_packet_t *packet);
    765819
    766820/** hint at the server port in specified protocol
     
    768822 * @param source        the source port from the packet
    769823 * @param dest          the destination port from the packet
    770  * @returns one of USE_SOURCE or USE_DEST depending on which one you should use
     824 * @return one of USE_SOURCE or USE_DEST depending on which one you should use
    771825 * @note ports must be in \em HOST byte order!
    772826 * @author Daniel Lawson
     
    779833 * @param uri           the uri to be parsed
    780834 * @param format        destination location for the format component of the uri
    781  * @returns 0 if an error occured, otherwise returns the uridata component
     835 * @return 0 if an error occured, otherwise return the uridata component
    782836 * @author Shane Alcock
    783837 */
    784838const char *trace_parse_uri(const char *uri, char **format);
    785839#ifdef __cplusplus
    786 } // extern "C"
    787 #endif // #ifdef __cplusplus
    788 #endif // LIBTRACE_H_
     840} /* extern "C" */
     841#endif /* #ifdef __cplusplus */
     842#endif /* LIBTRACE_H_ */
  • lib/libtrace_int.h

    r37195b4 r7068467  
    7777
    7878extern struct trace_err_t{
    79         int err_num;    // error code
    80         char problem[255];      // the format, uri etc that caused the error for reporting purposes
     79        int err_num;            /* error code */
     80        char problem[255];      /* the format, uri etc that caused the error for reporting purposes */
    8181} trace_err;
    8282
     
    153153        char *type;
    154154        int (*init_input)(struct libtrace_t *libtrace);
    155         int (*config_input)(struct libtrace_t *libtrace,char *option,void *value);
     155        int (*config_input)(struct libtrace_t *libtrace,trace_option_t option,void *value);
    156156        int (*start_input)(struct libtrace_t *libtrace);
    157157        int (*init_output)(struct libtrace_out_t *libtrace);
    158         int (*config_output)(struct libtrace_out_t *libtrace, int argc, char *argv[]);
     158        int (*config_output)(struct libtrace_out_t *libtrace, trace_option_output_t, void *);
    159159        int (*start_output)(struct libtrace_out_t *libtrace);
    160160        int (*fin_input)(struct libtrace_t *libtrace);
     
    180180
    181181void register_format(struct libtrace_format_t *format);
     182
     183libtrace_linktype_t pcap_dlt_to_libtrace(int dlt);
     184char libtrace_to_pcap_dlt(libtrace_linktype_t type);
     185libtrace_linktype_t erf_type_to_libtrace(char erf);
     186char libtrace_to_erf_type(libtrace_linktype_t linktype);
     187
    182188       
    183189#ifdef __cplusplus
     
    185191#endif
    186192
    187 #endif // LIBTRACE_INT_H
     193#endif /* LIBTRACE_INT_H */
  • lib/parse_cmd.h

    r283acce r7068467  
    55
    66
    7 #endif // PARSE_CMD_H
     7#endif /* PARSE_CMD_H */
  • lib/trace.c

    r37195b4 r7068467  
    264264        trace_err.err_num = E_NOERROR;
    265265       
    266         // parse the URI to determine what sort of event we are dealing with
     266        /* parse the URI to determine what sort of event we are dealing with */
    267267        if ((uridata = trace_parse_uri(uri, &scan)) == 0) {
    268268                return 0;
     
    284284                trace_err.err_num = E_BAD_FORMAT;
    285285                strcpy(trace_err.problem, scan);
    286                 //trace_err.problem = scan;
    287286                return 0;
    288287        }
    289288
    290289        libtrace->uridata = strdup(uridata);
    291         // libtrace->format now contains the type of uri
    292         // libtrace->uridata contains the appropriate data for this
     290        /* libtrace->format now contains the type of uri
     291         * libtrace->uridata contains the appropriate data for this
     292         */
    293293       
    294294        if (libtrace->format->init_input) {
     
    296296                        trace_err.err_num = E_INIT_FAILED;
    297297                        strcpy(trace_err.problem, scan);
    298                         //trace_err.problem = scan;
    299298                        return 0;
    300299                }
     
    302301                trace_err.err_num = E_NO_INIT;
    303302                strcpy(trace_err.problem, scan);
    304                 //trace_err.problem = scan;
    305303                return 0;
    306304        }
     
    350348                trace_err.err_num = E_BAD_FORMAT;
    351349                strcpy(trace_err.problem, scan);
    352                 //trace_err.problem = scan;
    353350                return 0;
    354351        }
     
    383380
    384381        trace_err.err_num = E_NOERROR;
    385         // parse the URI to determine what sort of event we are dealing with
     382        /* parse the URI to determine what sort of event we are dealing with */
    386383
    387384        if ((uridata = trace_parse_uri(uri, &scan)) == 0) {
     
    403400                trace_err.err_num = E_BAD_FORMAT;
    404401                strcpy(trace_err.problem, scan);
    405                 //trace_err.problem = scan;     
    406402                return 0;
    407403        }
     
    409405
    410406
    411         // libtrace->format now contains the type of uri
    412         // libtrace->uridata contains the appropriate data for this
     407        /* libtrace->format now contains the type of uri
     408         * libtrace->uridata contains the appropriate data for this
     409         */
    413410
    414411        if (libtrace->format->init_output) {
     
    419416                trace_err.err_num = E_NO_INIT_OUT;
    420417                strcpy(trace_err.problem, scan);
    421                 //trace_err.problem = scan;
    422418                return 0;
    423419        }
     
    458454 * @author Shane Alcock
    459455 */
    460 int trace_config_output(struct libtrace_out_t *libtrace, char *options) {
    461         char *opt_string = 0;
    462         char *opt_argv[MAXOPTS];
    463         int opt_argc = 0;
    464        
    465         assert(libtrace);
    466        
    467         if (!options) {
    468                 return 0;
    469         }
    470         asprintf(&opt_string, "%s %s", libtrace->format->name, options);
    471         parse_cmd(opt_string, &opt_argc, opt_argv, MAXOPTS);
    472        
     456int trace_config_output(struct libtrace_out_t *libtrace,
     457                trace_option_output_t option,
     458                void *value) {
    473459        if (libtrace->format->config_output) {
    474                 return libtrace->format->config_output(libtrace, opt_argc, opt_argv);
     460                return libtrace->format->config_output(libtrace, option, value);
    475461        }
    476462        return -1;
     
    483469        assert(libtrace);
    484470        libtrace->format->fin_input(libtrace);
    485         // need to free things!
     471        /* need to free things! */
    486472        free(libtrace->uridata);
    487473        destroy_tracefifo(libtrace->fifo);
     
    508494}
    509495
    510 /** Create a new packet object
    511  *
    512  * @ return a pointer to an initialised libtrace_packet_t structure
    513  */
    514 struct libtrace_packet_t *trace_create_packet() {
    515         struct libtrace_packet_t *packet = calloc(1,sizeof(struct libtrace_packet_t));
    516         packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE);
    517         packet->buf_control = PACKET;
     496libtrace_packet_t *trace_create_packet() {
     497        libtrace_packet_t *packet = calloc(1,sizeof(libtrace_packet_t));
     498        /* This used to malloc a packet!  Why do we need to malloc a packet
     499         * if we're doing zero copy?
     500         */
    518501        return packet;
    519502}
     
    607590                case TRACE_TYPE_80211_PRISM:
    608591                        {
    609                                 struct ieee_802_11_header *wifi = trace_get_link(packet)+144;
     592                                struct ieee_802_11_header *wifi = (char*)trace_get_link(packet)+144;
    610593                                if (!wifi) {
    611594                                        ipptr = NULL;
     
    613596                                }
    614597
    615                                 // Data packet?
     598                                /* Data packet? */
    616599                                if (wifi->type != 2) {
    617600                                        ipptr = NULL;
     
    644627                                }
    645628
    646                                 // Data packet?
     629                                /* Data packet? */
    647630                                if (wifi->type != 2) {
    648631                                        ipptr = NULL;
     
    727710                case TRACE_TYPE_LEGACY_POS:
    728711                        {
    729                                 // 64 byte capture.
     712                                /* 64 byte capture. */
    730713                                struct libtrace_pos *pos =
    731714                                        trace_get_link(packet);
     
    741724                case TRACE_TYPE_ATM:
    742725                        {
    743                                 // 64 byte capture.
     726                                /* 64 byte capture. */
    744727                                struct libtrace_llcsnap *llc =
    745728                                        trace_get_link(packet);
    746729
    747                                 // advance the llc ptr +4 into the link layer.
    748                                 // need to check what is in these 4 bytes.
    749                                 // don't have time!
     730                                /* advance the llc ptr +4 into the link layer.
     731                                 * need to check what is in these 4 bytes.
     732                                 * don't have time!
     733                                 */
    750734                                llc = (void *)llc + 4;
    751735                                if (ntohs(llc->type) == 0x0800) {
     
    796780 * Skipped can be NULL, in which case it will be ignored
    797781 */
    798 void *trace_get_transport_from_ip(const struct libtrace_ip *ip, int *skipped) {
     782void *trace_get_transport_from_ip(const libtrace_ip_t *ip, int *skipped) {
    799783        void *trans_ptr = 0;   
    800784
     
    814798 * @returns a pointer to the TCP header, or NULL if there is not a TCP packet
    815799 */
    816 struct libtrace_tcp *trace_get_tcp(const struct libtrace_packet_t *packet) {
     800libtrace_tcp_t *trace_get_tcp(const libtrace_packet_t *packet) {
    817801        struct libtrace_tcp *tcpptr = 0;
    818802        struct libtrace_ip *ipptr = 0;
     
    835819 * Skipped can be NULL, in which case it will be ignored by the program.
    836820 */
    837 struct libtrace_tcp *trace_get_tcp_from_ip(const struct libtrace_ip *ip, int *skipped)
     821libtrace_tcp_t *trace_get_tcp_from_ip(const libtrace_ip_t *ip, int *skipped)
    838822{
    839 #define SW_IP_OFFMASK 0xff1f
    840823        struct libtrace_tcp *tcpptr = 0;
    841824
     
    958941                        *optlen = *(*ptr+1);
    959942                        if (*optlen<2)
    960                                 return 0; // I have no idea wtf is going on
    961                                           // with these packets
     943                                return 0; /* I have no idea wtf is going on
     944                                           * with these packets
     945                                           */
    962946                        (*len)-=*optlen;
    963947                        (*data)=(*ptr+2);
     
    985969
    986970        if (packet->trace->format->get_erf_timestamp) {
    987                 // timestamp -> timestamp
     971                /* timestamp -> timestamp */
    988972                timestamp = packet->trace->format->get_erf_timestamp(packet);
    989973        } else if (packet->trace->format->get_timeval) {
    990                 // timeval -> timestamp
     974                /* timeval -> timestamp */
    991975                ts = packet->trace->format->get_timeval(packet);
    992976                timestamp = ((((uint64_t)ts.tv_sec) << 32) + \
    993977                                (((uint64_t)ts.tv_usec * UINT_MAX)/1000000));
    994978        } else if (packet->trace->format->get_seconds) {
    995                 // seconds -> timestamp
     979                /* seconds -> timestamp */
    996980                seconds = packet->trace->format->get_seconds(packet);
    997981                timestamp = ((uint64_t)((uint32_t)seconds) << 32) + \
     
    1014998        assert(packet->size>0 && packet->size<65536);
    1015999        if (packet->trace->format->get_timeval) {
    1016                 // timeval -> timeval
     1000                /* timeval -> timeval */
    10171001                tv = packet->trace->format->get_timeval(packet);
    10181002        } else if (packet->trace->format->get_erf_timestamp) {
    1019                 // timestamp -> timeval
     1003                /* timestamp -> timeval */
    10201004                ts = packet->trace->format->get_erf_timestamp(packet);
    10211005#if __BYTE_ORDER == __BIG_ENDIAN
     
    10341018                }
    10351019        } else if (packet->trace->format->get_seconds) {
    1036                 // seconds -> timeval
     1020                /* seconds -> timeval */
    10371021                seconds = packet->trace->format->get_seconds(packet);
    10381022                tv.tv_sec = (uint32_t)seconds;
     
    10561040       
    10571041        if (packet->trace->format->get_seconds) {
    1058                 // seconds->seconds
     1042                /* seconds->seconds */
    10591043                seconds = packet->trace->format->get_seconds(packet);
    10601044        } else if (packet->trace->format->get_erf_timestamp) {
    1061                 // timestamp -> seconds
     1045                /* timestamp -> seconds */
    10621046                ts = packet->trace->format->get_erf_timestamp(packet);
    10631047                seconds =  (ts>>32) + ((ts & UINT_MAX)*1.0 / UINT_MAX);
    10641048        } else if (packet->trace->format->get_timeval) {
    1065                 // timeval -> seconds
     1049                /* timeval -> seconds */
    10661050                tv = packet->trace->format->get_timeval(packet);
    10671051                seconds = tv.tv_sec + ((tv.tv_usec * UINT_MAX * 1.0)/1000000);
     
    12651249                pcap_t *pcap;
    12661250                struct bpf_program bpfprog;
    1267 
    1268                 switch (trace_get_link_type(packet)) {
    1269                         case TRACE_TYPE_ETH:
    1270                                 pcap = (pcap_t *)pcap_open_dead(DLT_EN10MB, 1500);
    1271                                 break;
    1272 #ifdef DLT_LINUX_SLL
    1273                         case TRACE_TYPE_LINUX_SLL:
    1274                                 pcap = (pcap_t *)pcap_open_dead(DLT_LINUX_SLL, 1500);
    1275                                 break;
    1276 #endif
    1277 #ifdef DLT_PFLOG
    1278                         case TRACE_TYPE_PFLOG:
    1279                                 pcap = (pcap_t *)pcap_open_dead(DLT_PFLOG, 1500);
    1280                                 break;
    1281 #endif
    1282                         default:
    1283                                 printf("only works for ETH and LINUX_SLL (ppp) at the moment\n");
    1284                                 assert(0);
    1285                 }               
    1286 
    1287                 // build filter
     1251                pcap=(pcap_t *)pcap_open_dead(
     1252                                libtrace_to_pcap_dlt(trace_get_link_type(packet)),
     1253                                1500);
     1254                /* build filter */
    12881255                if (pcap_compile( pcap, &bpfprog, filter->filterstring, 1, 0)) {
    12891256                        printf("bpf compilation error: %s: %s\n",
     
    14811448                return USE_DEST;
    14821449        */
    1483         // failing that test...
     1450        /* failing that test... */
    14841451        if (source < dest) {
    14851452                return USE_SOURCE;
     
    15161483       
    15171484        if((uridata = strchr(uri,':')) == NULL) {
    1518                 // badly formed URI - needs a :
     1485                /* badly formed URI - needs a : */
    15191486                trace_err.err_num = E_URI_NOCOLON;
    15201487                return 0;
     
    15221489
    15231490        if ((uridata - uri) > URI_PROTO_LINE) {
    1524                 // badly formed URI - uri type is too long
     1491                /* badly formed URI - uri type is too long */
    15251492                trace_err.err_num = E_URI_LONG;
    15261493                return 0;
     
    15291496        *format=xstrndup(uri, (uridata - uri));
    15301497
    1531         // push uridata past the delimiter
     1498        /* push uridata past the delimiter */
    15321499        uridata++;
    15331500       
  • lib/wag.h

    r9a36e6d r7068467  
    3131#define _WAG_H_
    3232
    33 // Generic field breakdowns
     33/* Generic field breakdowns */
    3434struct wag_frame_hdr {
    3535  uint16_t magic;
     
    4444};
    4545
    46 // Received packet frame fields
     46/* Received packet frame fields */
    4747struct wag_stream_info {
    4848  uint16_t unused_1;
     
    7373};
    7474
    75 // Transmit packet frame fields
     75/* Transmit packet frame fields */
    7676struct wag_txparams {
    7777  uint8_t         gain;
     
    9090
    9191struct ieee_802_11_header {
    92         uint8_t      protocol:2;
    93         uint8_t      type:2;
    94         uint8_t      subtype:4;
    95         uint8_t      to_ds:1;
    96         uint8_t      from_ds:1;
    97         uint8_t      more_frag:1;
    98         uint8_t      retry:1;
    99         uint8_t      power:1;
    100         uint8_t      more_data:1;
    101         uint8_t      wep:1;
    102         uint8_t      order:1;
     92        unsigned int protocol:2;
     93        unsigned int type:2;
     94        unsigned int subtype:4;
     95        unsigned int to_ds:1;
     96        unsigned int from_ds:1;
     97        unsigned int more_frag:1;
     98        unsigned int retry:1;
     99        unsigned int power:1;
     100        unsigned int more_data:1;
     101        unsigned int wep:1;
     102        unsigned int order:1;
    103103        uint16_t     duration;
    104104        uint8_t      mac1[6];
  • test/Makefile

    r06b2bcf r7068467  
    99LDLIBS = -L$(libdir) -ltrace
    1010
    11 BINS = test1
     11BINS = test1 test2
    1212.PHONY: all clean distclean install depend
    1313
  • test/test1.c

    r06b2bcf r7068467  
    5454       
    5555        trace = trace_create(uri);
     56
     57        trace_start(trace);
    5658       
    5759        if (trace) {
  • test/test2.c

    r06b2bcf r7068467  
    5959
    6060        trace = trace_create(uri);
     61
     62        trace_start(trace);
    6163       
    6264        for (;;) {
Note: See TracChangeset for help on using the changeset viewer.