//------------------------------------------------------------------- // watchnic.cpp // // This program continuously reads and displays the contents of // the '/proc/nicports' pseudo-file, in order to give its users // a dynamic view of the volatile RealTek 8139 register-values. // The program expects our 'nicports.c' module to be installed. // // programmer: ALLAN CRUSE // written on: 04 MAY 2005 //------------------------------------------------------------------- #include // for printf(), perror() #include // for open() #include // for exit() #include // for read() #include // for signal() int done = 0; void upon_signal( int signum ) { done = 1; } int main( int argc, char **argv ) { // open the pseudo-file for reading int fd = open( "/proc/nicports", O_RDONLY ); if ( fd < 0 ) { perror( "/proc/nicports" ); exit(1); } // install our signal-handler signal( SIGINT, upon_signal ); // initialize the display screen printf( "\e[H\e[J" ); // clear the screen printf( "\e[?25l\e[?1c "); // cursor invisible printf( "\e[%d;%dH", 7, 14 ); // cursor placement printf( "RealTek 8139 Network Interface Controller registers" ); // continuously read and display the RealTek register-values while ( !done ) { unsigned int data[ 64 ] = {0}; int nbytes = read( fd, data, sizeof( data ) ); if ( nbytes < 0 ) { perror( "read" ); exit(1); } printf( "\e[%d;%dH", 8, 1 ); for (int i = 0; i < 64; i++) { if ( ( i % 8 ) == 0 ) printf( "\n %02X: ", i*4 ); printf( "%08X ", data[ i ] ); } fflush( stdout ); } // restore cursor's visibility near the bottom of the screen printf( "\e[%d;%dH", 22, 1 ); // cursor position printf( "\e[?25h\e[?0c" ); // cursor visibile printf( "\n" ); // output new-line }