cnping

Minimal Graphical Ping Tool
git clone https://git.sinitax.com/cnlohr/cnping
Log | Files | Refs | Submodules | README | LICENSE | sfeed.txt

commit 418e61d21394806efb5c419ca6be014cbeed22f1
parent 5c42452616a85c6877f5502a828dc82f61212a80
Author: cnlohr <lohr85@gmail.com>
Date:   Wed, 21 Jun 2017 01:22:31 -0400

tweak a few things to improve readability.

Diffstat:
Mcnping.c | 6+++---
Mos_generic.c | 2+-
Mos_generic.h | 4++--
Mping.c | 30+++++++++++++++---------------
Mping.h | 4++--
Msearchnet.c | 2+-
6 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/cnping.c b/cnping.c @@ -377,12 +377,12 @@ int main( int argc, const char ** argv ) if( argc > 2 ) { - pingperiod = atof( argv[2] ); - printf( "Extra ping period: %f\n", pingperiod ); + pingperiodseconds = atof( argv[2] ); + printf( "Extra ping period: %f\n", pingperiodseconds ); } else { - pingperiod = 0.02; + pingperiodseconds = 0.02; } if( argc > 3 ) diff --git a/os_generic.c b/os_generic.c @@ -1,6 +1,5 @@ #include "os_generic.h" - #ifdef USE_WINDOWS #include <windows.h> @@ -56,6 +55,7 @@ void * OGJoinThread( og_thread_t ot ) { WaitForSingleObject( ot, INFINITE ); CloseHandle( ot ); + return 0; } void OGCancelThread( og_thread_t ot ) diff --git a/os_generic.h b/os_generic.h @@ -1,7 +1,7 @@ #ifndef _OS_GENERIC_H #define _OS_GENERIC_H -#ifdef WIN32 +#if defined( WIN32 ) || defined (WINDOWS) || defined( _WIN32) #define USE_WINDOWS #endif @@ -25,7 +25,7 @@ og_thread_t OGCreateThread( void * (routine)( void * ), void * parameter ); void * OGJoinThread( og_thread_t ot ); void OGCancelThread( og_thread_t ot ); -//Always a recrusive mutex. +//Always a recursive mutex. og_mutex_t OGCreateMutex(); void OGLockMutex( og_mutex_t om ); void OGUnlockMutex( og_mutex_t om ); diff --git a/ping.c b/ping.c @@ -45,10 +45,6 @@ void bzero(void * loc, int len) } #endif -void usleep(int x) { - Sleep(x / 1000); -} - #include <windows.h> #include <stdio.h> #include <winsock2.h> @@ -87,7 +83,7 @@ struct icmphdr { }; #endif -float pingperiod; +float pingperiodseconds; int precise_ping; #define PACKETSIZE 1500 @@ -133,7 +129,7 @@ void listener(void) if ( setsockopt(sd, SOL_IP, IP_TTL, &val, sizeof(val)) != 0) { - ERRM("Erro: could not set TTL option\n"); + ERRM("Error: could not set TTL option\n"); exit( -1 ); } @@ -166,7 +162,9 @@ void listener(void) if ( bytes > 0 ) display(buf + 28, bytes - 28 ); else - perror("recvfrom"); + { + ERRM("Error: recvfrom failed"); + } goto keep_retry_quick; } @@ -219,7 +217,9 @@ void ping(struct sockaddr_in *addr ) pckt.hdr.checksum = checksum(&pckt, sizeof(pckt) - sizeof( pckt.msg ) + rsize ); if ( sendto(sd, (char*)&pckt, sizeof(pckt) - sizeof( pckt.msg ) + rsize , 0, (struct sockaddr*)addr, sizeof(*addr)) <= 0 ) - perror("sendto"); + { + ERRM("Sendto failed."); + } if( precise_ping ) @@ -228,19 +228,19 @@ void ping(struct sockaddr_in *addr ) do { ctime = OGGetAbsoluteTime(); - if( pingperiod >= 1000 ) stime = ctime; - } while( ctime < stime + pingperiod ); - stime += pingperiod; + if( pingperiodseconds >= 1000 ) stime = ctime; + } while( ctime < stime + pingperiodseconds ); + stime += pingperiodseconds; } else { - if( pingperiod > 0 ) + if( pingperiodseconds > 0 ) { - uint32_t dlw = 1000000.0*pingperiod; - usleep( dlw ); + uint32_t dlw = 1000000.0*pingperiodseconds; + OGUSleep( dlw ); } } - } while( pingperiod >= 0 ); + } while( pingperiodseconds >= 0 ); //close( sd ); //Hacky, we don't close here because SD doesn't come from here, rather from ping_setup. We may want to run this multiple times. } diff --git a/ping.h b/ping.h @@ -18,8 +18,8 @@ void listener(void); void ping(struct sockaddr_in *addr ); void do_pinger( const char * strhost ); -//If pingperiod = -1, run ping/do_pinger once and exit. -extern float pingperiod; +//If pingperiodseconds = -1, run ping/do_pinger once and exit. +extern float pingperiodseconds; extern int precise_ping; //if 0, use minimal CPU, but ping send-outs are only approximate, if 1, spinlock until precise time for ping is hit. void ping_setup(); diff --git a/searchnet.c b/searchnet.c @@ -85,7 +85,7 @@ int main( int argc, char ** argv ) send_id[2] = (cur>>8)&0xff; send_id[3] = (cur)&0xff; // printf( "Pinging: %s\n", dispip ); - pingperiod = -1; + pingperiodseconds = -1; do_pinger( dispip ); OGUSleep( (int)(speed * 1000000) );