Changeset 4c365fa


Ignore:
Timestamp:
11/02/15 14:21:46 (6 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
pfring
Children:
274770a
Parents:
1598c46
Message:

Wrote a useful pfring_event function

PF_RING should now work with the event API.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_pfring.c

    r1598c46 r4c365fa  
    338338}
    339339
    340 static int pfring_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet)
     340static int pfring_read_generic(libtrace_t *libtrace, libtrace_packet_t *packet,
     341                uint8_t block)
    341342{
    342343
     
    357358        hdr = (struct libtrace_pfring_header *)packet->buffer;
    358359        if ((rc = pfring_recv(stream->pd, (u_char **)&packet->payload,
    359                         0, (struct pfring_pkthdr *)&local, 1)) == -1)
     360                        0, (struct pfring_pkthdr *)&local, block)) == -1)
    360361        {
    361362                trace_set_err(libtrace, errno, "Failed to read packet from pfring:");
    362363                return -1;
    363364        }
     365
     366        /* We were asked not to block and there are no packets available */
     367        if (rc == 0)
     368                return 0;
    364369
    365370        /* Convert the header fields to network byte order so we can
     
    393398}
    394399
     400static int pfring_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet)
     401{
     402        return pfring_read_generic(libtrace, packet, 1);
     403}
     404
    395405static libtrace_linktype_t pfring_get_link_type(const libtrace_packet_t *packet UNUSED)
    396406{
     
    481491}
    482492
    483 static libtrace_eventobj_t pfring_event(libtrace_t *libtrace UNUSED
    484                 libtrace_packet_t *packet UNUSED) {
     493static libtrace_eventobj_t pfring_event(libtrace_t *libtrace
     494                libtrace_packet_t *packet) {
    485495
    486496        libtrace_eventobj_t event = {0,0,0.0,0};
    487 
    488         /* TODO */
    489         event.type = TRACE_EVENT_TERMINATE;
     497        int rc;
     498
     499        rc = pfring_read_generic(libtrace, packet, 0);
     500       
     501        if (rc > 0) {
     502                event.size = rc;
     503                event.type = TRACE_EVENT_PACKET;
     504        } else if (rc == 0) {
     505                if (libtrace_halt) {
     506                        event.type = TRACE_EVENT_TERMINATE;
     507                } else {
     508                        event.type = TRACE_EVENT_SLEEP;
     509                        event.seconds = 0.0001;
     510                }
     511        } else {
     512                event.type = TRACE_EVENT_TERMINATE;
     513        }
    490514        return event;
    491515}
Note: See TracChangeset for help on using the changeset viewer.