Changeset 49babe0 for lib/format_wag.c


Ignore:
Timestamp:
02/15/06 15:18:38 (16 years ago)
Author:
Shane Alcock <salcock@…>
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:
643105b
Parents:
6eb91ff
Message:

Added initial format_rt and rt_protocol source files
Updated wag to be consistent with latest lt2 fixes and Dean's framing
Added a type field back into libtrace_packet
Fixed return value for trace_start

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_wag.c

    r6eb91ff r49babe0  
    267267static int wag_read(struct libtrace_t *libtrace, void *buffer, size_t len) {
    268268        int numbytes;
    269         size_t framesize;
    270         assert(libtrace);
    271 
    272         if (buffer == 0)
    273                 buffer = malloc(len);
    274 
    275         /* read in wag_frame_hdr */
    276         if ((numbytes = read(INPUT.fd,
    277                         buffer,
    278                         sizeof(struct wag_frame_hdr))) != sizeof(struct wag_frame_hdr)) {
    279                 return -1;
    280         }
    281          
    282         framesize = ntohs(((struct wag_frame_hdr *)buffer)->size);
    283 
    284         if (framesize > len) {
    285                 return -1;
    286         }
    287 
    288         /* read in remainder of packet */
    289         if((numbytes = read(INPUT.fd,
    290                         (char*)buffer + sizeof(struct wag_frame_hdr),
    291                         framesize - sizeof(struct wag_frame_hdr))) !=
    292                         (framesize - sizeof(struct wag_frame_hdr))) {
    293                
    294                 return -1;
    295          
    296         }
    297 
     269        int framesize;
     270        char *buf_ptr = (char *)buffer;
     271        int to_read = 0;
     272        uint16_t magic = 0;
     273        uint16_t lctr = 0;
     274
     275        assert(libtrace);
     276
     277        to_read = sizeof(struct frame_t);
     278
     279        while (to_read>0) {
     280          int ret=read(INPUT.fd,buf_ptr,to_read);
     281
     282          if (ret == -1) {
     283            if (errno == EINTR || errno==EAGAIN)
     284              continue;
     285            perror("read(frame)");
     286            return -1;
     287          }
     288
     289          assert(ret>0);
     290
     291          to_read = to_read - ret;
     292          buf_ptr = buf_ptr + ret;
     293        }
     294
     295        framesize = ntohs(((struct frame_t *)buffer)->size);
     296        magic = ntohs(((struct frame_t *)buffer)->magic);
     297
     298        if (magic != 0xdaa1) {
     299          printf("Magic number is BAD!\n");
     300          return -1;
     301        }
     302
     303        if (framesize > len) {
     304          printf("Framesize > len\n");
     305                return -1;
     306        }
     307
     308        buf_ptr = buffer + sizeof (struct frame_t);
     309        to_read = framesize - sizeof(struct frame_t);
     310       
     311        while (to_read>0) {
     312          int ret=read(INPUT.fd,buf_ptr,to_read);
     313
     314          if (ret == -1) {
     315            if (errno == EINTR || errno==EAGAIN)
     316              continue;
     317            perror("read(frame)");
     318            return -1;
     319          }
     320
     321          // assert(ret>0);
     322
     323          to_read = to_read - ret;
     324          buf_ptr = buf_ptr + ret;
     325        }
    298326        return framesize;
    299327}
     
    336364
    337365       
    338         if ((numbytes = LIBTRACE_READ(INPUT.file, buffer, sizeof(struct wag_frame_hdr))) == -1) {
     366        if ((numbytes = LIBTRACE_READ(INPUT.file, buffer, sizeof(struct frame_t))) == -1) {
    339367                perror("libtrace_read");
    340368                return -1;
     
    345373        }
    346374
    347         framesize = ntohs(((struct wag_frame_hdr *)buffer)->size);
    348         buffer2 = (char*)buffer + sizeof(struct wag_frame_hdr);
    349         size = framesize - sizeof(struct wag_frame_hdr);
     375        framesize = ntohs(((struct frame_t *)buffer)->size);
     376        buffer2 = (char*)buffer + sizeof(struct frame_t);
     377        size = framesize - sizeof(struct frame_t);
    350378        assert(size < LIBTRACE_PACKET_BUFSIZE);
    351379
     
    391419
    392420static int8_t wag_get_direction(const struct libtrace_packet_t *packet) {
    393         struct wag_data_frame *wagptr = (struct wag_data_frame *)packet->buffer;
     421        struct frame_data_rx_t *wagptr = (struct frame_data_rx_t *)packet->buffer;
    394422        if (wagptr->hdr.type == 0) {
    395423                return wagptr->hdr.subtype;
     
    399427
    400428static uint64_t wag_get_erf_timestamp(const struct libtrace_packet_t *packet) {
    401         struct wag_data_frame *wagptr = (struct wag_data_frame *)packet->buffer;
     429        struct frame_data_rx_t *wagptr = (struct frame_data_rx_t *)packet->buffer;
    402430        uint64_t timestamp = 0;
    403431        timestamp = ((uint64_t)(ntohl(wagptr->ts.secs)) << 32) | (uint64_t)(ntohl(wagptr->ts.subsecs));
     
    406434
    407435static int wag_get_capture_length(const struct libtrace_packet_t *packet) {
    408         struct wag_data_frame *wagptr = (struct wag_data_frame *)packet->buffer;
     436        struct frame_data_rx_t *wagptr = (struct frame_data_rx_t *)packet->buffer;
    409437        return ntohs(wagptr->hdr.size);
    410438}
    411439
    412440static int wag_get_wire_length(const struct libtrace_packet_t *packet) {
    413         struct wag_data_frame *wagptr = (struct wag_data_frame *)packet->buffer;
     441        struct frame_data_rx_t *wagptr = (struct frame_data_rx_t *)packet->buffer;
    414442        return ntohs(wagptr->hdr.size);
    415443}
    416444
    417445static int wag_get_framing_length(const struct libtrace_packet_t *packet) {
    418         return sizeof(struct wag_data_frame);
     446        return sizeof(struct frame_data_rx_t);
    419447}
    420448
Note: See TracChangeset for help on using the changeset viewer.