diff options
author | Martin Burnicki <martin.burnicki@meinberg.de> | 2015-06-26 12:00:00 +0200 |
---|---|---|
committer | Martin Burnicki <martin.burnicki@meinberg.de> | 2015-06-26 12:00:00 +0200 |
commit | b4987393ee0d42a1266b8f574f41a7230fc4aa87 (patch) | |
tree | 72e3f527e0580504fb0998ac6d3d7c1ce4cdf736 | |
parent | 410110dc4388f33ecb4d9e30f2627df00e5ba7d5 (diff) | |
download | ntptest-b4987393ee0d42a1266b8f574f41a7230fc4aa87.tar.gz ntptest-b4987393ee0d42a1266b8f574f41a7230fc4aa87.zip |
Don't exit on initial timeout in continuous mode1.2
-rwxr-xr-x | ntptest.c | 85 |
1 files changed, 42 insertions, 43 deletions
@@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: ntptest.c 1.4 2015/05/11 11:12:51 martin REL_M $ + * $Id: ntptest.c 1.5 2015/06/26 14:11:56 martin REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -12,6 +12,8 @@ * * ----------------------------------------------------------------------- * $Log: ntptest.c $ + * Revision 1.5 2015/06/26 14:11:56 martin + * Don't exit on initial timeout in continuous mode. * Revision 1.4 2015/05/11 11:12:51 martin * Support continuous monitoring (-Z), e.g. for leap second tests. * Revision 1.3 2015/02/27 13:10:31 martin @@ -37,7 +39,7 @@ static const char program_name[] = "ntptest"; -static const char program_version[] = "v1.1"; +static const char program_version[] = "v1.2"; static const char program_copyright[] = "(c) Meinberg 2014-2015"; static const char program_contact[] = "contact: <martin.burnicki@meinberg.de>"; @@ -152,58 +154,55 @@ void do_ntp_queries( void ) break; } - if ( rc == 0 ) // select() timed out + if ( rc > 0 ) // no timeout { - mbglog( LOG_ERR, "Timeout waiting for reply packet, exiting." ); - exit( 1 ); - } + // read response packet + slen_src = sizeof( si_src ) ; + reply_info.len = recvfrom( sockfd, &reply_info.packet, sizeof( reply_info.packet ), 0, + (struct sockaddr *) &si_src, &slen_src ); - // read response packet - slen_src = sizeof( si_src ) ; - reply_info.len = recvfrom( sockfd, &reply_info.packet, sizeof( reply_info.packet ), 0, - (struct sockaddr *) &si_src, &slen_src ); - - if ( reply_info.len < 0 ) - { - mbglog( LOG_ERR, "Failed to receive from UDP socket in %s: %s", __func__, strerror( errno ) ); - continue; - } + if ( reply_info.len < 0 ) + { + mbglog( LOG_ERR, "Failed to receive from UDP socket in %s: %s", __func__, strerror( errno ) ); + continue; + } - // get time stamp when response was received - clock_gettime( CLOCK_REALTIME, &reply_info.tsr ); + // get time stamp when response was received + clock_gettime( CLOCK_REALTIME, &reply_info.tsr ); - eval_ntp_packet( &rslt, &reply_info, &glb_query_stats ); - ntoh_ntp_packet( &req_info ); + eval_ntp_packet( &rslt, &reply_info, &glb_query_stats ); + ntoh_ntp_packet( &req_info ); - if ( verbose ) - print_ntp_results( &rslt, &req_info, &reply_info, &glb_query_stats, 1, 1 ); - else - { - static double initial_delta_t; - static int has_been_called; + if ( verbose ) + print_ntp_results( &rslt, &req_info, &reply_info, &glb_query_stats, 1, 1 ); + else + { + static double initial_delta_t; + static int has_been_called; - NTP_PACKET *p = &reply_info.packet; + NTP_PACKET *p = &reply_info.packet; - print_ntp_time( "", &p->base.transmit_time, NULL, 1 ); + print_ntp_time( "", &p->base.transmit_time, NULL, 1 ); - if ( !has_been_called ) - { - // Compute and save the initial delta t. - // The system time when the packet has been received is - // available in tv_rcv and t_rcv. + if ( !has_been_called ) + { + // Compute and save the initial delta t. + // The system time when the packet has been received is + // available in tv_rcv and t_rcv. - initial_delta_t = delta_tstamps( &p->base.transmit_time, &rslt.t_rcv ); - has_been_called = 1; - } + initial_delta_t = delta_tstamps( &p->base.transmit_time, &rslt.t_rcv ); + has_been_called = 1; + } - if ( compensate_initial_offset ) - rslt.ntp_offs -= initial_delta_t; + if ( compensate_initial_offset ) + rslt.ntp_offs -= initial_delta_t; - printf( ", st %u, leap %u, offs[ms]: %+.3f\n", - p->base.flags.stratum, - p->base.flags.leap_ind, - rslt.ntp_offs * 1000 ); - fflush( NULL ); + printf( ", st %u, leap %u, offs[ms]: %+.3f\n", + p->base.flags.stratum, + p->base.flags.leap_ind, + rslt.ntp_offs * 1000 ); + fflush( NULL ); + } } if ( !run_continuously ) |