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