cnping

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

commit 0419a4184a8dbf21eb4d7aacd8e234d8769581bf
parent 9ae6ad450a3bd01f5b10238aad39f86642197f5d
Author: cnlohr <lohr85@gmail.com>
Date:   Sat,  9 Apr 2016 18:55:50 -0400

Update cnping - keep the dynamic pingtime feature for use with cnping-mousey

Diffstat:
MMakefile | 6++++--
Mcnping.c | 5++---
Dcnping.exe | 0
Mping.c | 32+++++++++++++++++++++++++-------
Mping.h | 8++++++--
5 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,4 +1,4 @@ -all : cnping searchnet +all : cnping searchnet cnping-mousey CFLAGS:=$(CFLAGS) -g -Os CXXFLAGS:=$(CFLAGS) @@ -9,10 +9,12 @@ MINGW32:=/usr/bin/i686-w64-mingw32- cnping.exe : cnping.c DrawFunctions.c WinDriver.c os_generic.c ping.c $(MINGW32)gcc -g -mwindows -m32 $(CFLAGS) -o $@ $^ -lgdi32 -lws2_32 -s -# Rasterizer.o cnping : cnping.o DrawFunctions.o XDriver.o os_generic.o ping.o gcc $(CFLAGS) -o $@ $^ -lX11 -lm -lpthread -lXinerama -lXext $(LDFLAGS) +cnping-mousey : cnping-mousey.o DrawFunctions.o XDriver.o os_generic.o ping.o + gcc $(CFLAGS) -o $@ $^ -lX11 -lm -lpthread -lXinerama -lXext $(LDFLAGS) + searchnet : os_generic.o ping.o searchnet.o gcc $(CFLAGS) -o $@ $^ -lpthread diff --git a/cnping.c b/cnping.c @@ -23,13 +23,12 @@ unsigned frames = 0; unsigned long iframeno = 0; short screenx, screeny; const char * pinghost; -float pingperiod; float GuiYScaleFactor; uint8_t pattern[8]; -#define PINGCYCLEWIDTH 1024 +#define PINGCYCLEWIDTH 2048 #define TIMEOUT 4 double PingSendTimes[PINGCYCLEWIDTH]; @@ -81,7 +80,7 @@ void * PingListen( void * r ) void * PingSend( void * r ) { - do_pinger( pinghost, pingperiod ); + do_pinger( pinghost ); printf( "Fault on ping.\n" ); exit( -1 ); } diff --git a/cnping.exe b/cnping.exe Binary files differ. diff --git a/ping.c b/ping.c @@ -28,6 +28,7 @@ #include <errno.h> #include <strings.h> #include "ping.h" +#include "os_generic.h" #ifdef WIN32 #include <winsock2.h> #define SOL_IP 0 @@ -66,7 +67,8 @@ struct icmphdr { #endif #include <stdlib.h> - +float pingperiod; +int precise_ping; #define PACKETSIZE 1500 struct packet @@ -143,7 +145,7 @@ void listener(void) /*--------------------------------------------------------------------*/ /*--- ping - Create message and send it. ---*/ /*--------------------------------------------------------------------*/ -void ping(struct sockaddr_in *addr, float pingperiod) +void ping(struct sockaddr_in *addr ) { #ifdef WIN32 @@ -166,6 +168,8 @@ void ping(struct sockaddr_in *addr, float pingperiod) ERRM("Warning: Request nonblocking I/O failed."); #endif + double stime = OGGetAbsoluteTime(); + do { int len=sizeof(r_addr); @@ -183,10 +187,24 @@ void ping(struct sockaddr_in *addr, float pingperiod) if ( sendto(sd, (char*)&pckt, sizeof(pckt) - sizeof( pckt.msg ) + rsize , 0, (struct sockaddr*)addr, sizeof(*addr)) <= 0 ) perror("sendto"); - if( pingperiod > 0 ) + + if( precise_ping ) + { + double ctime; + do + { + ctime = OGGetAbsoluteTime(); + if( pingperiod >= 1000 ) stime = ctime; + } while( ctime < stime + pingperiod ); + stime += pingperiod; + } + else { - uint32_t dlw = 1000000.0*pingperiod; - usleep( dlw ); + if( pingperiod > 0 ) + { + uint32_t dlw = 1000000.0*pingperiod; + usleep( dlw ); + } } } while( pingperiod >= 0 ); close( sd ); @@ -241,7 +259,7 @@ void ping_setup() } -void do_pinger( const char * strhost, float _ping_period ) +void do_pinger( const char * strhost ) { struct hostent *hname; hname = gethostbyname(strhost); @@ -250,7 +268,7 @@ void do_pinger( const char * strhost, float _ping_period ) psaddr.sin_family = hname->h_addrtype; psaddr.sin_port = 0; psaddr.sin_addr.s_addr = *(long*)hname->h_addr; - ping(&psaddr, _ping_period); + ping(&psaddr ); } char errbuffer[1024]; diff --git a/ping.h b/ping.h @@ -15,8 +15,12 @@ void display(uint8_t *buf, int bytes); int load_ping_packet( uint8_t * buffer, int buffersize ); void listener(void); -void ping(struct sockaddr_in *addr , float pingperiod); //If pingperiod = -1, run once and exit. -void do_pinger( const char * strhost, float _ping_period ); //If pingperiod = -1, run once and exit. +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; +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();