Line data Source code
1 : /* Include fd_neigh4_map prototypes */ 2 : #include "fd_neigh4_map.h" 3 : 4 : /* Generate fd_neigh4_map definitions */ 5 : #include "fd_neigh4_map_defines.h" 6 : #define MAP_IMPL_STYLE 2 7 : #include "../../util/tmpl/fd_map_slot_para.c" 8 : 9 : #if FD_HAS_HOSTED 10 : 11 : #include <errno.h> 12 : #include <stdio.h> 13 : #include "../../util/net/fd_ip4.h" 14 : #include "../../util/net/fd_eth.h" 15 : 16 : int 17 : fd_neigh4_hmap_fprintf( fd_neigh4_hmap_t const * map, 18 0 : void * file_ ) { 19 0 : FILE * file = file_; 20 : 21 0 : ulong ele_max = fd_neigh4_hmap_ele_max( map ); 22 0 : fd_neigh4_entry_t const * ele = fd_neigh4_hmap_shele_const( map ); 23 : 24 0 : for( ulong j=0UL; j<ele_max; j++ ) { 25 : /* Peek key (atomic due to fd_neigh4_entry_t alignment) */ 26 0 : uint ip4_addr = ele[j].ip4_addr; 27 : 28 : /* Speculative read */ 29 0 : fd_neigh4_hmap_query_t query[1]; 30 0 : if( fd_neigh4_hmap_query_try( map, &ip4_addr, NULL, query, 0 )!=FD_MAP_SUCCESS ) { 31 0 : continue; 32 0 : } 33 : 34 0 : fd_neigh4_entry_t e[1]; memcpy( e, fd_neigh4_hmap_query_ele( query ), sizeof(fd_neigh4_entry_t) ); 35 : 36 : /* Check if read was overrun */ 37 0 : if( FD_UNLIKELY( fd_neigh4_hmap_query_test( query )!=FD_MAP_SUCCESS ) ) { 38 0 : continue; 39 0 : } 40 : 41 0 : if( e->ip4_addr ) { 42 0 : int print_res = fprintf( file, FD_IP4_ADDR_FMT " " FD_ETH_MAC_FMT "\n", 43 0 : FD_IP4_ADDR_FMT_ARGS( e->ip4_addr ), FD_ETH_MAC_FMT_ARGS( e->mac_addr ) ); 44 0 : if( FD_UNLIKELY( print_res<0 ) ) return errno; 45 0 : } 46 0 : } 47 : 48 0 : return 0; 49 0 : } 50 : 51 : #endif /* FD_HAS_HOSTED */