src/p_net_ifc_lnx.c
static void
p_net_ifs_getStats( lua_State *L, struct ifaddrs *ifa )
{
	struct rtnl_link_stats *stats;
	struct sockaddr_ll     *ll_addr;
	// TODO: This can hold a MAC Address but not a FireWire address -> needs
	// hardware to do more dev work.  Consider using sockaddr_ll->sll_halen
	// properly.
	char                    hw_buffer[ 19 ]; // 18+1 for NUL termination

	if (ifa->ifa_addr && ifa->ifa_data && AF_PACKET == ifa->ifa_addr->sa_family)
	{
		stats    = ifa->ifa_data;
#define IF_STAT( FLD )                     \
   lua_pushinteger( L, stats->FLD );       \
   lua_setfield( L, -2, #FLD "" );

		lua_createtable( L, 21, 0 );

		IF_STAT( rx_packets );             // total packets received
		IF_STAT( tx_packets );             // total packets transmitted
		IF_STAT( rx_bytes );               // total bytes received
		IF_STAT( tx_bytes );               // total bytes transmitted
		IF_STAT( rx_errors );              // bad packets received
		IF_STAT( tx_errors );              // packet transmit problems
		IF_STAT( rx_dropped );             // no space in linux buffers
		IF_STAT( tx_dropped );             // no space available in linux
		IF_STAT( multicast );              // multicast packets received
		IF_STAT( collisions );
		// detailed rx_errors:
		IF_STAT( rx_length_errors );
		IF_STAT( rx_over_errors );         // receiver ring buff overflow
		IF_STAT( rx_crc_errors );          // recved pkt with crc error
		IF_STAT( rx_frame_errors );        // recv'd frame alignment error
		IF_STAT( rx_fifo_errors );         // recv'r fifo overrun
		IF_STAT( rx_missed_errors );       // receiver missed packet
		// detailed tx_errors
		IF_STAT( tx_aborted_errors );
		IF_STAT( tx_carrier_errors );
		IF_STAT( tx_fifo_errors );
		IF_STAT( tx_heartbeat_errors );
		IF_STAT( tx_window_errors );
		lua_setfield( L, -2, "stats" );
#undef IF_STAT
		ll_addr = (struct sockaddr_ll*) ifa->ifa_addr;
		sprintf( hw_buffer, " %02x:%02x:%02x:%02x:%02x:%02x",
		    ll_addr->sll_addr[0],
		    ll_addr->sll_addr[1],
		    ll_addr->sll_addr[2],
		    ll_addr->sll_addr[3],
		    ll_addr->sll_addr[4],
		    ll_addr->sll_addr[5] );
		lua_pushlstring( L, hw_buffer, 18 );
		lua_setfield( L, -2, "hw_address" );
		lua_pushinteger( L, ll_addr->sll_ifindex);
		lua_setfield( L, -2, "index" );
	}
}
/**--------------------------------------------------------------------------
 * Extract statistic data from interface if available
 * \param   L        Lua state.
 * \param   ifa      struct ifaddrs instance.
 * \lreturn table    aggregated statistic data.
 * \return  int/bool 1 if succesful, else 0.
 * --------------------------------------------------------------------------*/
Extract statistic data from interface if available
\param   L        Lua state.
\param   ifa      struct ifaddrs instance.
\lreturn table    aggregated statistic data.
\return  int/bool 1 if succesful, else 0.
Extract statistic data from interface if available \ param L Lua state . \ param ifa struct ifaddrs instance . \ lreturn table aggregated statistic data . \ return int / bool 1 if succesful else 0 .
static void
p_net_ifs_getStats( lua_State *L, struct ifaddrs *ifa )
{
	struct rtnl_link_stats *stats;
	struct sockaddr_ll     *ll_addr;
	char                    hw_buffer[ 19 ]; 
	if (ifa->ifa_addr && ifa->ifa_data && AF_PACKET == ifa->ifa_addr->sa_family)
	{
		stats    = ifa->ifa_data;
#define IF_STAT( FLD )                     \
   lua_pushinteger( L, stats->FLD );       \
   lua_setfield( L, -2, #FLD "" );
		lua_createtable( L, 21, 0 );
		IF_STAT( rx_packets );             
		IF_STAT( tx_packets );             
		IF_STAT( rx_bytes );               
		IF_STAT( tx_bytes );               
		IF_STAT( rx_errors );              
		IF_STAT( tx_errors );              
		IF_STAT( rx_dropped );             
		IF_STAT( tx_dropped );             
		IF_STAT( multicast );              
		IF_STAT( collisions );
		IF_STAT( rx_length_errors );
		IF_STAT( rx_over_errors );         
		IF_STAT( rx_crc_errors );          
		IF_STAT( rx_frame_errors );        
		IF_STAT( rx_fifo_errors );         
		IF_STAT( rx_missed_errors );       
		IF_STAT( tx_aborted_errors );
		IF_STAT( tx_carrier_errors );
		IF_STAT( tx_fifo_errors );
		IF_STAT( tx_heartbeat_errors );
		IF_STAT( tx_window_errors );
		lua_setfield( L, -2, "stats" );
#undef IF_STAT
		ll_addr = (struct sockaddr_ll*) ifa->ifa_addr;
		sprintf( hw_buffer, " %02x:%02x:%02x:%02x:%02x:%02x",
		    ll_addr->sll_addr[0],
		    ll_addr->sll_addr[1],
		    ll_addr->sll_addr[2],
		    ll_addr->sll_addr[3],
		    ll_addr->sll_addr[4],
		    ll_addr->sll_addr[5] );
		lua_pushlstring( L, hw_buffer, 18 );
		lua_setfield( L, -2, "hw_address" );
		lua_pushinteger( L, ll_addr->sll_ifindex);
		lua_setfield( L, -2, "index" );
	}
}
static void p_net_ifs_getStats ( lua_State * L , struct ifaddrs * ifa ) { struct rtnl_link_stats * stats ; struct sockaddr_ll * ll_addr ; char hw_buffer [ 19 ] ; if ( ifa -> ifa_addr && ifa -> ifa_data && AF_PACKET == ifa -> ifa_addr -> sa_family ) { stats = ifa -> ifa_data ; #define IF_STAT ( FLD )                      \
   lua_pushinteger( L, stats->FLD );       \
   lua_setfield( L, -2, #FLD "" ); lua_createtable ( L , 21 , 0 ) ; IF_STAT ( rx_packets ) ; IF_STAT ( tx_packets ) ; IF_STAT ( rx_bytes ) ; IF_STAT ( tx_bytes ) ; IF_STAT ( rx_errors ) ; IF_STAT ( tx_errors ) ; IF_STAT ( rx_dropped ) ; IF_STAT ( tx_dropped ) ; IF_STAT ( multicast ) ; IF_STAT ( collisions ) ; IF_STAT ( rx_length_errors ) ; IF_STAT ( rx_over_errors ) ; IF_STAT ( rx_crc_errors ) ; IF_STAT ( rx_frame_errors ) ; IF_STAT ( rx_fifo_errors ) ; IF_STAT ( rx_missed_errors ) ; IF_STAT ( tx_aborted_errors ) ; IF_STAT ( tx_carrier_errors ) ; IF_STAT ( tx_fifo_errors ) ; IF_STAT ( tx_heartbeat_errors ) ; IF_STAT ( tx_window_errors ) ; lua_setfield ( L , -2 , " " ) ; #undef  IF_STAT ll_addr = ( struct sockaddr_ll * ) ifa -> ifa_addr ; sprintf ( hw_buffer , " " , ll_addr -> sll_addr [ 0 ] , ll_addr -> sll_addr [ 1 ] , ll_addr -> sll_addr [ 2 ] , ll_addr -> sll_addr [ 3 ] , ll_addr -> sll_addr [ 4 ] , ll_addr -> sll_addr [ 5 ] ) ; lua_pushlstring ( L , hw_buffer , 18 ) ; lua_setfield ( L , -2 , " " ) ; lua_pushinteger ( L , ll_addr -> sll_ifindex ) ; lua_setfield ( L , -2 , " " ) ; } }
Extract statistic data from interface if available
 \param   L        Lua state.
Extract statistic data from interface if available \ param L Lua state .
// TODO: This can hold a MAC Address but not a FireWire address -> needs // hardware to do more dev work.  Consider using sockaddr_ll->sll_halen // properly. // 18+1 for NUL termination // total packets received // total packets transmitted // total bytes received // total bytes transmitted // bad packets received // packet transmit problems // no space in linux buffers // no space available in linux // multicast packets received // detailed rx_errors: // receiver ring buff overflow // recved pkt with crc error // recv'd frame alignment error // recv'r fifo overrun // receiver missed packet // detailed tx_errors