crt_io.c File Reference

#include <include.h>
#include <src/crt_io.h>
#include <src/interface.h>
#include <src/errmsg.h>
#include <syslog.h>

Include dependency graph for crt_io.c:

Go to the source code of this file.

Functions

void fatal (int error_code, char *fmt,...)
void debug (UINT8 DL, char *fmt,...)
void debugTS (UINT8 DL, char *fmt,...)
void warning (char *fmt,...)
void warning_if_error (int errorcode)
void DumpHexPaquets (WINDOW *RealTime_WND, UINT8 msgbuf[], int recvlen)
void Send_IDS_Warning (char *message)

Variables

UINT8 CursesIsInUse
ConfigStruct config
WINDOW * RealTime_WND
pthread_mutex_t screen_mutex
 MUTEX for lock screen, so only one func write to it at the same time.


Function Documentation

void fatal ( int  error_code,
char *  fmt,
  ... 
)

Definition at line 57 of file crt_io.c.

References CursesIsInUse, ConfigStruct::DebugLevel, EndCurses(), ErrorsMsg, RefreshAllWND(), and TRUE.

Referenced by closePacket(), getPacket(), main(), openCard(), openCardWLAN(), openPacket(), openPacketCISCO(), selectChannel(), selectChannelWLAN(), and shutCard().

00058 {
00059   va_list ap;
00060 
00061 #ifdef HAVE_LIBNCURSES
00062   if (CursesIsInUse == TRUE)
00063     RefreshAllWND();            // Refresh All Windows
00064   if (config.DebugLevel >= 1)
00065     sleep(3);                   // Sleep for 3 seconds
00066 #else
00067   fflush(stdout);               // Refresh stdout buffer
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 }

void debug ( UINT8  DL,
char *  fmt,
  ... 
)

Definition at line 85 of file crt_io.c.

References CursesIsInUse, ConfigStruct::DebugLevel, FALSE, RealTime_WND, screen_mutex, and TRUE.

00086 {
00087   va_list ap;
00088 
00089   if (config.DebugLevel < DL)
00090     return;                     // Return if debug level is not enougth
00091   if (CursesIsInUse == FALSE)
00092     fflush(stdout);             // Refresh stdout buffer
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 }

void debugTS ( UINT8  DL,
char *  fmt,
  ... 
)

Definition at line 120 of file crt_io.c.

References CursesIsInUse, ConfigStruct::DebugLevel, FALSE, RealTime_WND, screen_mutex, and TRUE.

00121 {
00122   va_list ap;
00123   struct timeb binary_now;
00124 
00125   //struct tm *ascii_now = NULL;
00126 
00127   ftime(&binary_now);
00128   //ascii_now = localtime (&binary_now.time);
00129 
00130   if (config.DebugLevel < DL)
00131     return;                     // Return if debug level is not enougth
00132   if (CursesIsInUse == FALSE)
00133     fflush(stdout);             // Refresh stdout buffer
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 }

void warning ( char *  fmt,
  ... 
)

Definition at line 162 of file crt_io.c.

References CursesIsInUse, ConfigStruct::DebugLevel, FALSE, RealTime_WND, screen_mutex, and TRUE.

Referenced by AnalyseTAG221(), ChangeChannel_th(), DestroyVAP_MADWIFI_NG(), do_ioctl(), extract_radiotap_field(), FillRadioData(), findAvailableIF(), getPacketPCAP(), IwconfigClearSSID(), IwconfigSetChannel(), IwconfigSetMode(), LogDetectedClient(), main(), NextChannel(), openCardCISCO(), openCardMADWIFI_NG(), openCardWLAN(), openPacketHOSTAP(), parse_keystring(), processPacket(), ProcessTagBits(), selectChannel(), Send_IDS_Warning(), sendDeauth(), shutCardCISCO(), and stop_signal().

00163 {
00164   va_list ap;
00165 
00166   if (CursesIsInUse == FALSE)
00167     fflush(stdout);             // Refresh stdout buffer
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 }

void warning_if_error ( int  errorcode  ) 

Definition at line 195 of file crt_io.c.

References CursesIsInUse, ConfigStruct::DebugLevel, ErrorsMsg, FALSE, NO_ERROR, RealTime_WND, screen_mutex, and TRUE.

Referenced by openCardATHEROS(), openCardCISCO(), openCardHERMES(), openCardHOSTAP(), openCardIPW(), openCardPRISM54g(), shutCardATHEROS(), shutCardCISCO(), shutCardHERMES(), shutCardHOSTAP(), shutCardIPW(), and shutCardPRISM54g().

00196 {
00197   if (errorcode != NO_ERROR) {
00198     if (CursesIsInUse == FALSE)
00199       fflush(stdout);           // Refresh stdout buffer
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 }

void DumpHexPaquets ( WINDOW *  RealTime_WND,
UINT8  msgbuf[],
int  recvlen 
)

Definition at line 222 of file crt_io.c.

References MAX_BUFFER_SIZE, MIN_OF, and screen_mutex.

Referenced by analyseBeacon(), FillRadioData(), getPacketIPW(), getPacketPCAP(), and main().

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;                    // Please ... No core dump :-)
00234     end = MIN_OF((recvlen - n), 16);
00235     wprintw(RealTime_WND, "0x%04X - ", n);
00236 
00237     // Print Hex part
00238     for (i = 0; i < 16; i++) {
00239       /* Write only packet, not garbage ;-) */
00240       if (i < end)
00241         wprintw(RealTime_WND, "%02X", (UINT8) msgbuf[n + i]);
00242       else
00243         wprintw(RealTime_WND, "  ");
00244       /* Separator every 2 bytes */
00245       if (!((i + 1) % 2))
00246         wprintw(RealTime_WND, " ");
00247     }
00248 
00249     // Print ASCI part
00250     for (i = 0; i < end; i++) {
00251       // Print caractere if it's printable
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     /* End of line each 16 bytes */
00258     wprintw(RealTime_WND, "\n");
00259   }
00260   wrefresh(RealTime_WND);
00261 #ifdef WITH_THREAD
00262   pthread_mutex_unlock(&screen_mutex);
00263 #endif
00264 }

void Send_IDS_Warning ( char *  message  ) 

Definition at line 270 of file crt_io.c.

References ConfigStruct::SendAlert2Syslog, TRUE, and warning().

Referenced by IDS_BcnInt(), IDS_TimeStamp(), and IDS_Var_SeqNum().

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 }


Variable Documentation

Definition at line 63 of file scanner.c.

Referenced by debug(), debugTS(), EndCurses(), fatal(), main(), warning(), and warning_if_error().

Definition at line 58 of file scanner.c.

WINDOW* RealTime_WND

Definition at line 61 of file scanner.c.

pthread_mutex_t screen_mutex

MUTEX for lock screen, so only one func write to it at the same time.

Definition at line 67 of file scanner.c.


Generated on Fri Jul 25 17:10:50 2008 for WifiScanner by  doxygen 1.5.5