// Initialize log void log_init(STRING* _logFile) { txtLog = txt_create(LOG_LINES,999); txtLog.font = fontLog; txtLog.size_x = screen_size.x; txtLog.size_y = 100; set(txtLog, SHOW | OUTLINE); int i; for(i=0; i<txtLog.strings; i++) { (txtLog.pstring)[i] = str_create("#256"); } // Color for log text vec_set(cLogColor, vector(255,255,255)); // Log to file, too? if (_logFile != NULL) { nLogToFile = 1; str_cpy(strLogFile, _logFile); } // If logging to file, initialize file IO if (nLogToFile == 1) { log_write_header(); } }
// Toggle logging to file void log_toggle_file_log() { if (txtLog == NULL) return; nLogToFile = 1 - nLogToFile; if (nLogToFile == 1) { if (nLogHeaderWritten == 0) { log_write_header(); } } }
int set_loglevel(int level, char *filename) { char eci[strlen(filename)+5]; char ecp[strlen(filename)+5]; /* close any previously opened file */ log_stop(); /* if we want to stop logging, return here */ if (level == LOG_STOP) { DEBUG_MSG("set_loglevel: stopping the log process"); return E_SUCCESS; } DEBUG_MSG("set_loglevel(%d, %s)", level, filename); /* all the host type will be unknown, warn the user */ if (EC_GBL_OPTIONS->read) { USER_MSG("*********************************************************\n"); USER_MSG("WARNING: while reading form file we cannot determine \n"); USER_MSG("if an host is local or not because the ip address of \n"); USER_MSG("the NIC may have been changed from the time of the dump. \n"); USER_MSG("*********************************************************\n\n"); } snprintf(eci, strlen(filename)+5, "%s.eci", filename); snprintf(ecp, strlen(filename)+5, "%s.ecp", filename); memset(&fdp, 0, sizeof(struct log_fd)); memset(&fdi, 0, sizeof(struct log_fd)); /* open the file(s) */ switch(level) { case LOG_PACKET: if (EC_GBL_OPTIONS->compress) { fdp.type = LOG_COMPRESSED; } else { fdp.type = LOG_UNCOMPRESSED; } /* create the file */ if (log_open(&fdp, ecp) != E_SUCCESS) return -E_FATAL; /* initialize the log file */ log_write_header(&fdp, LOG_PACKET); /* add the hook point to DISPATCHER */ hook_add(HOOK_DISPATCHER, &log_packet); /* no break here, loglevel is incremental */ /* fall through */ case LOG_INFO: if (EC_GBL_OPTIONS->compress) { fdi.type = LOG_COMPRESSED; } else { fdi.type = LOG_UNCOMPRESSED; } /* create the file */ if (log_open(&fdi, eci) != E_SUCCESS) return -E_FATAL; /* initialize the log file */ log_write_header(&fdi, LOG_INFO); /* add the hook point to DISPATCHER */ hook_add(HOOK_DISPATCHER, &log_info); /* add the hook for the ARP packets */ hook_add(HOOK_PACKET_ARP, &log_info); /* add the hook for ICMP packets */ hook_add(HOOK_PACKET_ICMP, &log_info); /* add the hook for DHCP packets */ /* (fake icmp packets from DHCP discovered GW and DNS) */ hook_add(HOOK_PROTO_DHCP_PROFILE, &log_info); break; } atexit(log_stop); return E_SUCCESS; }