2000-04-13 09:19:23 +00:00
|
|
|
#include "echoping.h"
|
|
|
|
|
2000-07-23 19:17:37 +00:00
|
|
|
/* $Id$ */
|
2000-04-13 09:19:23 +00:00
|
|
|
|
|
|
|
/* Most of error-handling routines stolen from Stevens' books */
|
|
|
|
|
|
|
|
void
|
|
|
|
my_perror ()
|
|
|
|
{
|
|
|
|
fprintf (stderr, " %s\n", sys_err_str ());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Recoverable error. Print a message, and return to caller.
|
|
|
|
*
|
|
|
|
* err_ret(str, arg1, arg2, ...)
|
|
|
|
*
|
|
|
|
* The string "str" must specify the conversion specification for any args.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* VARARGS1 */
|
|
|
|
void
|
2001-01-28 21:03:05 +00:00
|
|
|
err_ret (char *str, ...)
|
2000-04-13 09:19:23 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
2001-02-20 21:48:39 +00:00
|
|
|
va_start (args, str);
|
2001-01-28 21:03:05 +00:00
|
|
|
vfprintf (stderr, str, args);
|
2000-04-13 09:19:23 +00:00
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
my_perror ();
|
|
|
|
|
|
|
|
fflush (stdout);
|
|
|
|
fflush (stderr);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fatal error. Print a message and terminate. Don't dump core and don't
|
|
|
|
* print the system's errno value.
|
|
|
|
*
|
|
|
|
* err_quit(str, arg1, arg2, ...)
|
|
|
|
*
|
|
|
|
* The string "str" must specify the conversion specification for any args.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* VARARGS1 */
|
|
|
|
void
|
2001-01-28 21:03:05 +00:00
|
|
|
err_quit (char *str, ...)
|
2000-04-13 09:19:23 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
2001-01-28 21:03:05 +00:00
|
|
|
va_start (args, str);
|
|
|
|
vfprintf (stderr, str, args);
|
2000-04-13 09:19:23 +00:00
|
|
|
fputc ('\n', stderr);
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fatal error related to a system call. Print a message and terminate.
|
|
|
|
* Don't dump core, but do print the system's errno value and its associated
|
|
|
|
* message.
|
|
|
|
*
|
|
|
|
* err_sys(str, arg1, arg2, ...)
|
|
|
|
*
|
|
|
|
* The string "str" must specify the conversion specification for any args.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* VARARGS1 */
|
2001-02-20 21:48:39 +00:00
|
|
|
void
|
2001-01-28 21:03:05 +00:00
|
|
|
err_sys (char *str, ...)
|
2000-04-13 09:19:23 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
2001-01-28 21:03:05 +00:00
|
|
|
va_start (args, str);
|
|
|
|
vfprintf (stderr, str, args);
|
2000-04-13 09:19:23 +00:00
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
my_perror ();
|
|
|
|
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
usage ()
|
|
|
|
{
|
2001-01-25 15:35:30 +00:00
|
|
|
fprintf (stderr,
|
2004-04-06 09:49:26 +00:00
|
|
|
"Usage: %s [-4] [-6] [-v] [-r] [-f fill] [-t timeout] [-c] [-d] [-u] [-s size] [-n number] [-w delay] [-h url] [-i url] [-p priority] [-P tos] [-C] [-S] [-m plugin] hostname[:port]\n",
|
2001-01-25 15:35:30 +00:00
|
|
|
progname);
|
2000-04-13 09:19:23 +00:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a string containing some additional operating-system dependent
|
|
|
|
* information. Note that different versions of UNIX assign different
|
|
|
|
* meanings to the same value of "errno" (compare errno's starting with 35
|
|
|
|
* between System V and BSD, for example). This means that if an error
|
|
|
|
* condition is being sent to another UNIX system, we must interpret the
|
|
|
|
* errno value on the system that generated the error, and not just send the
|
|
|
|
* decimal value of errno to the other system.
|
|
|
|
*/
|
|
|
|
|
|
|
|
char *
|
|
|
|
sys_err_str ()
|
|
|
|
{
|
|
|
|
static char msgstr[200];
|
|
|
|
|
|
|
|
if (errno != 0)
|
|
|
|
{
|
2003-11-05 12:29:15 +00:00
|
|
|
sprintf (msgstr, "(%s)", strerror(errno));
|
2000-04-13 09:19:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msgstr[0] = '\0';
|
2003-11-05 12:29:15 +00:00
|
|
|
}
|
2000-04-13 09:19:23 +00:00
|
|
|
return (msgstr);
|
|
|
|
}
|