LCOV - code coverage report
Current view: top level - waltz/aio - fd_aio_pcapng.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 50 0.0 %
Date: 2025-03-20 12:08:36 Functions: 0 6 0.0 %

          Line data    Source code
       1             : #include "fd_aio_pcapng.h"
       2             : #include "../../util/net/fd_pcapng.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             : ulong
      55           0 : fd_aio_pcapng_start_l3( void * pcapng ) {
      56           0 :   fd_pcapng_shb_opts_t shb_opts = {0};
      57           0 :   fd_pcapng_shb_defaults( &shb_opts );
      58             : 
      59           0 :   if( FD_UNLIKELY( 1UL!=fd_pcapng_fwrite_shb( &shb_opts, pcapng ) ) )
      60           0 :     return 0UL;
      61             : 
      62           0 :   if( FD_UNLIKELY( 1UL!=fd_pcapng_fwrite_idb(
      63           0 :         FD_PCAPNG_LINKTYPE_RAW, NULL, pcapng ) ) )
      64           0 :     return 0UL;
      65             : 
      66           0 :   return 1UL;
      67           0 : }
      68             : 
      69             : fd_aio_pcapng_t *
      70             : fd_aio_pcapng_join( void *           _mitm,
      71             :                     fd_aio_t const * dst,
      72           0 :                     void *           pcapng ) {
      73             : 
      74           0 :   fd_aio_pcapng_t * mitm = (fd_aio_pcapng_t *)_mitm;
      75           0 :   mitm->dst    = dst;
      76           0 :   mitm->pcapng = pcapng;
      77             : 
      78           0 :   FD_TEST( fd_aio_join( fd_aio_new( &mitm->local, mitm, fd_aio_pcapng_send ) ) );
      79             : 
      80           0 :   return mitm;
      81           0 : }
      82             : 
      83             : void *
      84           0 : fd_aio_pcapng_leave( fd_aio_pcapng_t * mitm ) {
      85           0 :   fd_aio_delete( fd_aio_leave( &mitm->local ) );
      86             : 
      87           0 :   mitm->dst    = NULL;
      88           0 :   mitm->pcapng = NULL; /* FIXME flush? */
      89             : 
      90           0 :   return (void *)mitm;
      91           0 : }

Generated by: LCOV version 1.14