00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <include.h>
00029 #include <src/crt_io.h>
00030 #include <src/interface.h>
00031 #include <src/errmsg.h>
00032 #ifdef WITH_SYSLOG
00033 #include <syslog.h>
00034 #endif
00035
00036 extern UINT8 CursesIsInUse;
00037 extern ConfigStruct config;
00038
00039 #ifdef HAVE_LIBNCURSES
00040 extern WINDOW *RealTime_WND;
00041 #endif
00042 #ifdef WITH_THREAD
00043 extern pthread_mutex_t screen_mutex;
00044 #endif
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 void fatal(int error_code, char *fmt, ...)
00058 {
00059 va_list ap;
00060
00061 #ifdef HAVE_LIBNCURSES
00062 if (CursesIsInUse == TRUE)
00063 RefreshAllWND();
00064 if (config.DebugLevel >= 1)
00065 sleep(3);
00066 #else
00067 fflush(stdout);
00068 #endif
00069 va_start(ap, fmt);
00070 #ifdef HAVE_LIBNCURSES
00071 if (CursesIsInUse == TRUE)
00072 EndCurses();
00073 #endif
00074 vfprintf(stderr, fmt, ap);
00075 vfprintf(stderr, ">> %s\n", ErrorsMsg[error_code]);
00076 va_end(ap);
00077 exit(error_code);
00078 }
00079
00080
00081
00082
00083
00084
00085 void debug(UINT8 DL, char *fmt, ...)
00086 {
00087 va_list ap;
00088
00089 if (config.DebugLevel < DL)
00090 return;
00091 if (CursesIsInUse == FALSE)
00092 fflush(stdout);
00093 va_start(ap, fmt);
00094 #ifdef HAVE_LIBNCURSES
00095 if (CursesIsInUse == TRUE) {
00096 #ifdef WITH_THREAD
00097 pthread_mutex_lock(&screen_mutex);
00098 #endif
00099 vwprintw(RealTime_WND, fmt, ap);
00100 if (config.DebugLevel > 0)
00101 wrefresh(RealTime_WND);
00102 #ifdef WITH_THREAD
00103 pthread_mutex_unlock(&screen_mutex);
00104 #endif
00105 } else {
00106 #endif
00107 vfprintf(stderr, fmt, ap);
00108 fflush(stderr);
00109 #ifdef HAVE_LIBNCURSES
00110 }
00111 #endif
00112 va_end(ap);
00113 }
00114
00115
00116
00117
00118
00119
00120 void debugTS(UINT8 DL, char *fmt, ...)
00121 {
00122 va_list ap;
00123 struct timeb binary_now;
00124
00125
00126
00127 ftime(&binary_now);
00128
00129
00130 if (config.DebugLevel < DL)
00131 return;
00132 if (CursesIsInUse == FALSE)
00133 fflush(stdout);
00134 va_start(ap, fmt);
00135 #ifdef HAVE_LIBNCURSES
00136 if (CursesIsInUse == TRUE) {
00137 #ifdef WITH_THREAD
00138 pthread_mutex_lock(&screen_mutex);
00139 #endif
00140 wprintw(RealTime_WND, "%d.%03d:", (int) binary_now.time,
00141 binary_now.millitm);
00142 vwprintw(RealTime_WND, fmt, ap);
00143 if (config.DebugLevel > 0)
00144 wrefresh(RealTime_WND);
00145 #ifdef WITH_THREAD
00146 pthread_mutex_unlock(&screen_mutex);
00147 #endif
00148 } else {
00149 #endif
00150 vfprintf(stderr, fmt, ap);
00151 fflush(stderr);
00152 #ifdef HAVE_LIBNCURSES
00153 }
00154 #endif
00155 va_end(ap);
00156 }
00157
00158
00159
00160
00161
00162 void warning(char *fmt, ...)
00163 {
00164 va_list ap;
00165
00166 if (CursesIsInUse == FALSE)
00167 fflush(stdout);
00168 va_start(ap, fmt);
00169 #ifdef HAVE_LIBNCURSES
00170 if (CursesIsInUse == TRUE) {
00171 #ifdef WITH_THREAD
00172 pthread_mutex_lock(&screen_mutex);
00173 #endif
00174 vwprintw(RealTime_WND, fmt, ap);
00175 if (config.DebugLevel > 0)
00176 wrefresh(RealTime_WND);
00177 #ifdef WITH_THREAD
00178 pthread_mutex_unlock(&screen_mutex);
00179 #endif
00180 } else {
00181 #endif
00182 vfprintf(stderr, fmt, ap);
00183 fflush(stderr);
00184 #ifdef HAVE_LIBNCURSES
00185 }
00186 #endif
00187 va_end(ap);
00188 }
00189
00190
00191
00192
00193
00194
00195 void warning_if_error(int errorcode)
00196 {
00197 if (errorcode != NO_ERROR) {
00198 if (CursesIsInUse == FALSE)
00199 fflush(stdout);
00200 #ifdef HAVE_LIBNCURSES
00201 if (CursesIsInUse == TRUE) {
00202 #ifdef WITH_THREAD
00203 pthread_mutex_lock(&screen_mutex);
00204 #endif
00205 wprintw(RealTime_WND, "Warning : %s\n", ErrorsMsg[errorcode]);
00206 if (config.DebugLevel > 0)
00207 wrefresh(RealTime_WND);
00208 #ifdef WITH_THREAD
00209 pthread_mutex_unlock(&screen_mutex);
00210 #endif
00211 } else {
00212 #endif
00213 fprintf(stderr, "Warning : %s\n", ErrorsMsg[errorcode]);
00214 fflush(stderr);
00215 #ifdef HAVE_LIBNCURSES
00216 }
00217 #endif
00218 }
00219 }
00220
00221
00222 void DumpHexPaquets(WINDOW * RealTime_WND, UINT8 msgbuf[], int recvlen)
00223 {
00224 unsigned int n, i, end;
00225
00226 #ifdef WITH_THREAD
00227 pthread_mutex_lock(&screen_mutex);
00228 #endif
00229 wprintw(RealTime_WND, "MSG=\n");
00230
00231 for (n = 0; n < recvlen; n += 16) {
00232 if (n > MAX_BUFFER_SIZE)
00233 break;
00234 end = MIN_OF((recvlen - n), 16);
00235 wprintw(RealTime_WND, "0x%04X - ", n);
00236
00237
00238 for (i = 0; i < 16; i++) {
00239
00240 if (i < end)
00241 wprintw(RealTime_WND, "%02X", (UINT8) msgbuf[n + i]);
00242 else
00243 wprintw(RealTime_WND, " ");
00244
00245 if (!((i + 1) % 2))
00246 wprintw(RealTime_WND, " ");
00247 }
00248
00249
00250 for (i = 0; i < end; i++) {
00251
00252 if (msgbuf[n + i] >= 0x20 && msgbuf[n + i] <= 0x7E)
00253 wprintw(RealTime_WND, "%c", (char) msgbuf[n + i]);
00254 else
00255 wprintw(RealTime_WND, ".");
00256 }
00257
00258 wprintw(RealTime_WND, "\n");
00259 }
00260 wrefresh(RealTime_WND);
00261 #ifdef WITH_THREAD
00262 pthread_mutex_unlock(&screen_mutex);
00263 #endif
00264 }
00265
00266
00267
00268
00269
00270 void Send_IDS_Warning(char *message)
00271 {
00272 warning("%s", message);
00273 #ifdef WITH_SYSLOG
00274 if (config.SendAlert2Syslog == TRUE)
00275 syslog(LOG_USER || LOG_WARNING, "%s", message);
00276 #endif
00277 }