summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Burnicki <martin.burnicki@meinberg.de>2021-11-19 09:48:02 +0100
committerMartin Burnicki <martin.burnicki@meinberg.de>2021-11-19 09:48:02 +0100
commit711d9ed080242255118f6d4187d3abb8d49e04a5 (patch)
treee58e1d8737da50d578286410fa910c674f405682
parenta1e5c7a702168a5457728bf7de2a400a0aec1bc7 (diff)
downloadntptest-711d9ed080242255118f6d4187d3abb8d49e04a5.tar.gz
ntptest-711d9ed080242255118f6d4187d3abb8d49e04a5.zip
Use some predefined exit codes
-rwxr-xr-xntptest.c58
1 files changed, 15 insertions, 43 deletions
diff --git a/ntptest.c b/ntptest.c
index 2a18e2f..2425319 100755
--- a/ntptest.c
+++ b/ntptest.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: ntptest.c 1.15 2019/09/04 07:42:17 martin REL_M $
+ * $Id: ntptest.c 1.16 2020/04/01 12:50:08 martin REL_M $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -12,6 +12,8 @@
*
* -----------------------------------------------------------------------
* $Log: ntptest.c $
+ * Revision 1.16 2020/04/01 12:50:08 martin
+ * Use exit codes defined in mbgerror.h.
* Revision 1.15 2019/09/04 07:42:17 martin
* Return specific exit codes in case of error, and
* list the valid exit codes in the usage information.
@@ -94,37 +96,7 @@ static const char program_version[] = "v1.11";
static const char program_copyright[] = "(c) Meinberg 2014-2019";
static const char program_contact[] = "contact: <martin.burnicki@meinberg.de>";
-enum EXIT_CODES
-{
- EXIT_OK, // Success (EXIT_SUCCESS is a predefined symbol)
- EXIT_FAIL_USAGE, // Usage printed, invalid parameter?
- EXIT_FAILED_GENERIC, // General failure, e.g. insufficient memory.
- EXIT_FAIL_DNS, // Host name lookup failed.
- EXIT_FAIL_SOCK_ID, // Failed to open UDP socket.
- EXIT_FAIL_SEND, // Failed to send UDP packet.
- EXIT_FAIL_RECEIVE, // Failed to receive UDP packet.
- EXIT_FAIL_ENCRYPT, // Failed to encrypt a packet.
- EXIT_FAIL_DECRYPT, // Failed to decrypt an encrypted packet.
- EXIT_FAIL_CRYPT_NACK, // Failed because received a crypto NACK.
- N_EXIT_CODES
-};
-
-#define EXIT_CODE_INFO_STRS \
-{ \
- "Success", /* EXIT_OK */ \
- "Usage printed, e.g. invalid parameter.", /* EXIT_FAIL_USAGE */ \
- "General failure, e.g. insufficient memory.", /* EXIT_FAILED_GENERIC */ \
- "Host name lookup failed.", /* EXIT_FAIL_DNS */ \
- "Failed to open UDP socket.", /* EXIT_FAIL_SOCK_ID */ \
- "Failed to send UDP packet.", /* EXIT_FAIL_SEND */ \
- "Failed to receive UDP packet.", /* EXIT_FAIL_RECEIVE */ \
- "Failed to encrypt a packet.", /* EXIT_FAIL_ENCRYPT */ \
- "Failed to decrypt an encrypted packet.", /* EXIT_FAIL_DECRYPT */ \
- "Received a crypto NACK." /* EXIT_FAIL_CRYPT_NACK */ \
-}
-
-
-static int exit_code = EXIT_OK;
+static int exit_code = MBG_NTP_EXIT_SUCCESS;
#if defined( MBG_TGT_WIN32 )
@@ -223,7 +195,7 @@ void do_ntp_queries( void )
mbglog( LOG_ERR, "Failed to open UDP socket in %s: %s", __func__,
mbg_strerror( mbg_get_last_socket_error( NULL ) ) );
- exit( EXIT_FAIL_SOCK_ID );
+ exit( MBG_NTP_EXIT_FAIL_SOCKET );
}
@@ -249,7 +221,7 @@ void do_ntp_queries( void )
if ( auth_code != MBG_NTP_AUTH_OK )
{
- exit_code = EXIT_FAIL_ENCRYPT;
+ exit_code = MBG_NTP_EXIT_FAIL_ENCRYPT;
mbglog( LOG_WARNING, "Failed to encrypt request packet with key %i", md5_key_id );
}
}
@@ -262,7 +234,7 @@ void do_ntp_queries( void )
{
mbglog( LOG_ERR, "Failed to send UDP packet in %s: %s", __func__,
mbg_strerror( mbg_get_last_socket_error( NULL ) ) );
- exit( EXIT_FAIL_SEND );
+ exit( MBG_NTP_EXIT_FAIL_SEND );
}
glb_query_stats.requests++;
@@ -310,7 +282,7 @@ void do_ntp_queries( void )
{
mbglog( LOG_ERR, "Failed to receive from UDP socket: %s",
mbg_strerror( mbg_get_last_socket_error( NULL ) ) );
- exit( EXIT_FAIL_RECEIVE );
+ exit( MBG_NTP_EXIT_FAIL_RECEIVE );
}
// Use the receive time stamp taken earlier.
@@ -321,10 +293,10 @@ void do_ntp_queries( void )
rslt.auth_code = mbg_ntp_auth_decrypt( &key_cache, &resp_info );
if ( rslt.auth_code == MBG_NTP_AUTH_NACK )
- exit_code = EXIT_FAIL_CRYPT_NACK;
+ exit_code = MBG_NTP_EXIT_FAIL_CRYPT_NACK;
else
if ( rslt.auth_code == MBG_NTP_AUTH_FAIL )
- exit_code = EXIT_FAIL_DECRYPT;
+ exit_code = MBG_NTP_EXIT_FAIL_DECRYPT;
#else
rslt.auth_code = MBG_NTP_AUTH_NONE;
#endif
@@ -409,7 +381,7 @@ cont:
static /*HDR*/
void usage( void )
{
- const char *exit_code_str[N_EXIT_CODES] = EXIT_CODE_INFO_STRS;
+ const char *exit_code_str[N_MBG_NTP_EXIT_CODES] = MBG_NTP_EXIT_CODE_STRS;
int i;
printf( "\n" );
@@ -445,7 +417,7 @@ void usage( void )
printf( "Program exit codes:\n" );
- for ( i = 0; i < N_EXIT_CODES; i++ )
+ for ( i = 0; i < N_MBG_EXIT_CODES; i++ )
printf( " %i: %s\n", i, exit_code_str[i] );
printf( "\n" );
@@ -582,7 +554,7 @@ int main( int argc, char *argv[] )
if ( must_print_usage )
{
usage();
- exit( EXIT_FAIL_USAGE );
+ exit( MBG_NTP_EXIT_FAIL_USAGE );
}
@@ -611,7 +583,7 @@ int main( int argc, char *argv[] )
{
int rc = mbg_get_gethostbyname_error( NULL );
mbglog( LOG_ERR, "Unknown host %s: %s", tgt_host, mbg_strerror( rc ) );
- exit( EXIT_FAIL_DNS );
+ exit( MBG_NTP_EXIT_FAIL_DNS );
}
// set up host info for sending
@@ -633,7 +605,7 @@ int main( int argc, char *argv[] )
if ( mbg_rc_is_error( rc ) )
{
- exit_code = EXIT_FAILED_GENERIC;
+ exit_code = MBG_NTP_EXIT_FAIL_GENERIC;
goto out;
}