LCOV - code coverage report
Current view: top level - waltz/aio - fd_aio_pcapng.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 40 0.0 %
Date: 2024-11-13 11:58:15 Functions: 0 5 0.0 %

          Line data    Source code
       1             : #include "fd_aio_pcapng.h"
       2             : #include "../../util/net/fd_pcapng_private.h"
       3             : 
       4             : #include <errno.h>
       5             : 
       6             : /* fd_aio_pcapng_send implements fd_aio_send_t */
       7             : 
       8             : static int
       9             : fd_aio_pcapng_send( void *                    ctx,
      10             :                     fd_aio_pkt_info_t const * batch,
      11             :                     ulong                     batch_cnt,
      12             :                     ulong *                   opt_batch_idx,
      13           0 :                     int                       flush ) {
      14             : 
      15           0 :   long ts = fd_log_wallclock(); /* TODO allow custom clock */
      16             : 
      17           0 :   fd_aio_pcapng_t * mitm = (fd_aio_pcapng_t *)ctx;
      18             : 
      19           0 :   for( ulong i=0; i<batch_cnt; i++ ) {
      20           0 :     if( FD_UNLIKELY( 1UL!=fd_pcapng_fwrite_pkt( ts, batch[ i ].buf, batch[ i ].buf_sz, mitm->pcapng ) ) ) {
      21           0 :       FD_LOG_WARNING(( "fd_pcapng_fwrite_pkt failed (%i-%s)", errno, fd_io_strerror( errno ) ));
      22           0 :       break;
      23           0 :     }
      24           0 :   }
      25             : 
      26             :   /* pcaping doesn't require any additional destination */
      27           0 :   if( mitm->dst ) {
      28           0 :     return fd_aio_send( mitm->dst, batch, batch_cnt, opt_batch_idx, flush );
      29           0 :   }
      30             : 
      31           0 :   return FD_AIO_SUCCESS;
      32           0 : }
      33             : 
      34             : FD_FN_CONST fd_aio_t const *
      35           0 : fd_aio_pcapng_get_aio( fd_aio_pcapng_t const * mitm ) {
      36           0 :   return &mitm->local;
      37           0 : }
      38             : 
      39             : ulong
      40           0 : fd_aio_pcapng_start( void * pcapng ) {
      41           0 :   fd_pcapng_shb_opts_t shb_opts = {0};
      42           0 :   fd_pcapng_shb_defaults( &shb_opts );
      43             : 
      44           0 :   if( FD_UNLIKELY( 1UL!=fd_pcapng_fwrite_shb( &shb_opts, pcapng ) ) )
      45           0 :     return 0UL;
      46             : 
      47           0 :   if( FD_UNLIKELY( 1UL!=fd_pcapng_fwrite_idb(
      48           0 :         FD_PCAPNG_LINKTYPE_ETHERNET, NULL, pcapng ) ) )
      49           0 :     return 0UL;
      50             : 
      51           0 :   return 1UL;
      52           0 : }
      53             : 
      54             : fd_aio_pcapng_t *
      55             : fd_aio_pcapng_join( void *           _mitm,
      56             :                     fd_aio_t const * dst,
      57           0 :                     void *           pcapng ) {
      58             : 
      59           0 :   fd_aio_pcapng_t * mitm = (fd_aio_pcapng_t *)_mitm;
      60           0 :   mitm->dst    = dst;
      61           0 :   mitm->pcapng = pcapng;
      62             : 
      63           0 :   FD_TEST( fd_aio_join( fd_aio_new( &mitm->local, mitm, fd_aio_pcapng_send ) ) );
      64             : 
      65           0 :   return mitm;
      66           0 : }
      67             : 
      68             : void *
      69           0 : fd_aio_pcapng_leave( fd_aio_pcapng_t * mitm ) {
      70           0 :   fd_aio_delete( fd_aio_leave( &mitm->local ) );
      71             : 
      72           0 :   mitm->dst    = NULL;
      73           0 :   mitm->pcapng = NULL; /* FIXME flush? */
      74             : 
      75           0 :   return (void *)mitm;
      76           0 : }

Generated by: LCOV version 1.14