commit 10406c772b324383b144777e8ad896b5adc430ba
parent a4eb9f4867220682afff839c366ee171ef1ab8fb
Author: cnlohr <lohr85@gmail.com>
Date: Thu, 13 Jul 2017 01:45:31 -0400
Fix major issue with automatic timing assumption. Also, make friendlier note when pings fail to send.
Diffstat:
5 files changed, 22 insertions(+), 20 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,6 +1,6 @@
all : cnping searchnet cnping-mousey
-CFLAGS:=$(CFLAGS) -g -Os -I/opt/X11/include
+CFLAGS:=$(CFLAGS) -g -Os -I/opt/X11/include -Wall
CXXFLAGS:=$(CFLAGS)
LDFLAGS:=-g -L/opt/X11/lib/
diff --git a/cnping.c b/cnping.c
@@ -67,6 +67,11 @@ int load_ping_packet( uint8_t * buffer, int bufflen )
memcpy( buffer+4, pattern, 8 );
+ if( ping_failed_to_send )
+ {
+ PingSendTimes[(current_cycle+PINGCYCLEWIDTH-1)&(PINGCYCLEWIDTH-1)] = 0; //Unset ping send.
+ }
+
PingSendTimes[current_cycle&(PINGCYCLEWIDTH-1)] = OGGetAbsoluteTime();
PingRecvTimes[current_cycle&(PINGCYCLEWIDTH-1)] = 0;
@@ -162,7 +167,7 @@ void DrawFrame( void )
CNFGColor( 0xff );
dt = now - st;
dt *= 1000;
- totalcountloss++;
+ if( i != 0 ) totalcountloss++;
}
else // no ping sent for this point in time (after startup)
{
@@ -225,7 +230,7 @@ void DrawFrame( void )
"Max : %5.2f ms\n"
"Avg : %5.2f ms\n"
"Std : %5.2f ms\n"
- "Loss: %5.1f %%\n", last, mintime, maxtime, avg, stddev, loss );
+ "Loss: %5.1f %%\n\n%s", last, mintime, maxtime, avg, stddev, loss, (ping_failed_to_send?"Could not send ping.\nIs target reachable?\nDo you have sock_raw to privileges?":"") );
CNFGColor( 0x00 );
for( x = -1; x < 2; x++ ) for( y = -1; y < 2; y++ )
@@ -312,14 +317,11 @@ INT_PTR CALLBACK TextEntry( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
int main( int argc, const char ** argv )
{
char title[1024];
- int i, x, y, r;
+ int i;
double ThisTime;
double LastFPSTime = OGGetAbsoluteTime();
double LastFrameTime = OGGetAbsoluteTime();
double SecToWait;
- int linesegs = 0;
-// struct in_addr dst;
- struct addrinfo *result;
#ifdef WIN32
ShowWindow (GetConsoleWindow(), SW_HIDE);
@@ -336,7 +338,7 @@ int main( int argc, const char ** argv )
#ifdef WIN32
if( argc < 2 )
{
- int ret = DialogBox(0, "IPDialog", 0, TextEntry );
+ DialogBox(0, "IPDialog", 0, TextEntry );
argc = glargc;
argv = glargv;
}
@@ -357,7 +359,7 @@ int main( int argc, const char ** argv )
return -1;
}
- float pingperiod = (argc > 2)?atof( argv[2] ):0.02;
+ pingperiodseconds = (argc > 2)?atof( argv[2] ):0.02;
ExtraPingSize = (argc > 3)?atoi( argv[3] ):0;
if( argc > 4 )
@@ -378,11 +380,7 @@ int main( int argc, const char ** argv )
while(1)
{
- int i, pos;
- float f;
iframeno++;
- RDPoint pto[3];
-
CNFGHandleInput();
CNFGClearFrame();
@@ -398,7 +396,6 @@ int main( int argc, const char ** argv )
if( ThisTime > LastFPSTime + 1 )
{
frames = 0;
- linesegs = 0;
LastFPSTime+=1;
}
diff --git a/cnping.exe b/cnping.exe
Binary files differ.
diff --git a/ping.c b/ping.c
@@ -72,6 +72,7 @@ struct packet
int sd;
int pid=-1;
+int ping_failed_to_send;
struct sockaddr_in psaddr;
uint16_t checksum( const unsigned char * start, uint16_t len )
@@ -110,7 +111,6 @@ void listener()
#endif
for (;;)
{
- int i;
socklen_t addrlenval=sizeof(addr);
int bytes;
@@ -167,7 +167,6 @@ void ping(struct sockaddr_in *addr )
struct packet pckt;
do
{
- int len = sizeof(r_addr);
int rsize = load_ping_packet( pckt.msg, sizeof( pckt.msg ) );
memset( &pckt.hdr, 0, sizeof( pckt.hdr ) ); //This needs to be here, but I don't know why, since I think the struct is fully populated.
@@ -177,9 +176,15 @@ void ping(struct sockaddr_in *addr )
pckt.hdr.un.echo.sequence = cnt++;
pckt.hdr.checksum = checksum((const unsigned char *)&pckt, sizeof( pckt.hdr ) + rsize );
- if( sendto(sd, (char*)&pckt, sizeof( pckt.hdr ) + rsize , 0, (struct sockaddr*)addr, sizeof(*addr)) <= 0 )
+ int sr = sendto(sd, (char*)&pckt, sizeof( pckt.hdr ) + rsize , 0, (struct sockaddr*)addr, sizeof(*addr));
+
+ if( sr <= 0 )
+ {
+ ping_failed_to_send = 1;
+ }
+ else
{
- ERRM("Fail on sendto.");
+ ping_failed_to_send = 0;
}
if( precise_ping )
@@ -235,7 +240,7 @@ void ping_setup()
if ( setsockopt(sd, SOL_IP, IP_TTL, &val, sizeof(val)) != 0)
{
- ERRM("Error: Failed to set TTL option\n");
+ ERRM("Error: Failed to set TTL option. Are you root? Or can do sock_raw sockets?\n");
exit( -1 );
}
diff --git a/ping.h b/ping.h
@@ -21,7 +21,7 @@ void do_pinger( const char * strhost );
//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.
-
+extern int ping_failed_to_send;
void ping_setup();
#ifdef WIN32