File: ec_error.c

package info (click to toggle)
ettercap 1:0.8.2-10
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 5,468 kB
  • ctags: 6,333
  • sloc: ansic: 47,337; yacc: 310; lex: 204; makefile: 121; xml: 31; sh: 24
file content (133 lines) | stat: -rw-r--r-- 3,192 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
    ettercap -- error handling module

    Copyright (C) ALoR & NaGA

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

*/

#include <ec.h>
#include <ec_ui.h>

#include <stdarg.h>
#include <errno.h>
#define ERROR_MSG_LEN 200

void fatal_error_msg(char *message, ...);

/*******************************************/

/*
 * raise an error
 */
void error_msg(char *file, const char *function, int line, char *message, ...)
{
   va_list ap;
   char errmsg[ERROR_MSG_LEN + 1];    /* should be enough */
   int err_code;

#ifdef OS_WINDOWS
   err_code = GetLastError();  /* Most likely not a libc error */
   if (err_code == 0)
      err_code = errno;
#else
   err_code = errno;
#endif
   

   va_start(ap, message);
   vsnprintf(errmsg, ERROR_MSG_LEN, message, ap);
   va_end(ap);

   DEBUG_MSG("ERROR : %d, %s\n[%s:%s:%d] %s \n",  err_code, strerror(err_code),
                   file, function, line, errmsg );
   
   /* close the interface and display the error */
   ui_cleanup();
  
   fprintf(stderr, "ERROR : %d, %s\n[%s:%s:%d]\n\n %s \n\n",  err_code, strerror(err_code),
                   file, function, line, errmsg );

   clean_exit(-err_code);
}

/*
 * print a warning message (no exit)
 */
void warn_msg(char *file, const char *function, int line, char *message, ...)
{

   va_list ap;
   char warnmsg[ERROR_MSG_LEN + 1];


   va_start(ap, message);
   vsnprintf(warnmsg, ERROR_MSG_LEN, message, ap);
   va_end(ap);

   DEBUG_MSG("WARNING: [%s:%s:%d] %s \n", file, function, line, warnmsg);

   fprintf(stdout, "WARNING: [%s:%s:%d]\n\n %s \n\n", file, function, line, warnmsg);

}

/*
 * raise a fatal error
 */
void fatal_error(char *message, ...)
{
   va_list ap;
   char errmsg[ERROR_MSG_LEN + 1];    /* should be enough */

   va_start(ap, message);
   vsnprintf(errmsg, ERROR_MSG_LEN, message, ap);
   va_end(ap);

   /* if debug was initialized... */
#ifdef DEBUG
   if (debug_file != NULL)
      DEBUG_MSG("FATAL: %s", errmsg);
#endif

   /* invoke the ui method */
   ui_fatal_error(errmsg);

   /* the ui should exits, but to be sure... */
   clean_exit(-1);
}

/*
 * used in sanity check
 * it represent a BUG in the software
 */

void bug(char *file, const char *function, int line, char *message)
{
   DEBUG_MSG("BUG : [%s:%s:%d] %s \n", file, function, line, message );
   
   /* close the interface and display the error */
   ui_cleanup();
  
   fprintf(stderr, "\n\nBUG at [%s:%s:%d]\n\n %s \n\n", file, function, line, message );

   clean_exit(-666);
}


/* EOF */

// vim:ts=3:expandtab