Flowgrind
Advanced TCP traffic generator
fg_error.c File Reference

Error-reporting routines used by Flowgrind. More...

#include "config.h"
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "fg_progname.h"
#include "fg_error.h"

Go to the source code of this file.

Functions

void error (enum error_levels level, int errnum, const char *fmt,...)
 

Detailed Description

Error-reporting routines used by Flowgrind.

Definition in file fg_error.c.

Function Documentation

◆ error()

void error ( enum error_levels  level,
int  errnum,
const char *  fmt,
  ... 
)

Definition at line 38 of file fg_error.c.

39 {
40 
41  const char *err_prefix = NULL;
42  switch (level) {
43  case ERR_WARNING:
44  err_prefix = "warning";
45  break;
46  case ERR_ERROR:
47  case ERR_CRIT:
48  err_prefix = "error";
49  break;
50  default:
51  err_prefix = "unknown error";
52  }
53 
54  fprintf(stderr, "%s: %s: ", progname, err_prefix);
55 
56  va_list ap;
57  va_start(ap, fmt);
58  vfprintf(stderr, fmt, ap);
59  va_end(ap);
60 
61  const char *err_errnum = NULL;
62  if (errnum) {
63  err_errnum = strerror(errnum);
64  if (!err_errnum)
65  err_errnum = "unknown system error";
66  fprintf (stderr, ": %s", err_errnum);
67  }
68 
69  fprintf(stderr, "\n");
70  fflush (stderr);
71 
72  if (level > ERR_ERROR)
73  exit(EXIT_FAILURE);
74 }
ERR_CRIT
@ ERR_CRIT
Critical conditions.
Definition: fg_error.h:63
ERR_WARNING
@ ERR_WARNING
Warning conditions.
Definition: fg_error.h:59
ERR_ERROR
@ ERR_ERROR
Error conditions.
Definition: fg_error.h:61
progname
const char * progname
String containing name the program is called with.
Definition: fg_progname.c:35