NETWORK ATTACKS FRAMEWORK
1.0.0
A NETwork Attacks framework. Making network attacks impact evaluation easier!
|
#include <stdio.h>
#include <syslog.h>
Go to the source code of this file.
Defines | |
#define | WANT_DEBUGMODE |
#define | DEBUG(l, s, args...) alog(l, s, __FUNCTION__, ## args) |
Functions | |
void | log_init () |
void | log_cleanup () |
const char * | packet_type (unsigned int type) |
void | alog (int type, int errnum, const char *function, const char *format,...) |
void | log_pkt_fields (AODV_msg *msg) |
void | print_rt_table (void *arg) |
void | log_rt_table_init () |
char * | ip_to_str (struct in_addr addr) |
Variables | |
int | debug |
Definition at line 74 of file NA_debug_aodv.h.
#define WANT_DEBUGMODE |
Definition at line 65 of file NA_debug_aodv.h.
void alog | ( | int | type, |
int | errnum, | ||
const char * | function, | ||
const char * | format, | ||
... | |||
) |
Definition at line 160 of file NA_debug_aodv.cc.
{ #ifndef _WIN32 va_list ap; static char buffer[256] = ""; static char log_buf[1024]; char *msg; struct timeval now; struct tm *time; int len = 0; /* NS_PORT: Include IP address in log */ #ifdef NS_PORT if (DEV_NR(NS_DEV_NR).enabled == 1) { len += sprintf(log_buf + len, "%s: ", ip_to_str(DEV_NR(NS_DEV_NR).ipaddr)); } #endif /* NS_PORT */ va_start(ap, format); if (type == LOG_WARNING) msg = &buffer[9]; else msg = buffer; vsprintf(msg, format, ap); va_end(ap); if (!debug && !log_to_file) goto syslog; gettimeofday(&now, NULL); #ifdef NS_PORT time = gmtime(&now.tv_sec); #else time = localtime(&now.tv_sec); #endif /* if (type <= LOG_NOTICE) */ /* len += sprintf(log_buf + len, "%s: ", progname); */ len += sprintf(log_buf + len, "%s %02d:%02d:%02d.%03ld %s: %s",nodeName, time->tm_hour, time->tm_min, time->tm_sec, now.tv_usec / 1000, function, msg); // len += sprintf(log_buf + len, "%s time = %lf - %s %s ",nodeName, simTime(), function, // msg); if (errnum == 0) len += sprintf(log_buf + len, "\n"); else len += sprintf(log_buf + len, ": %s\n", strerror(errnum)); if (len > 1024) { fprintf(stderr, "alog(): buffer to small! len = %d\n", len); goto syslog; } /* OK, we are clear to write the buffer to the aodv log file... */ if (log_to_file) write_to_log_file(log_buf, len); /* If we have the debug option set, also write to stdout */ if (debug) fputs(log_buf, stdout); /* Syslog all messages that are of severity LOG_NOTICE or worse */ syslog: if (type <= LOG_NOTICE) { if (errnum != 0) { errno = errnum; syslog(type, "%s: %s: %m", function, msg); } else syslog(type, "%s: %s", function, msg); } /* Exit on error */ if (type <= LOG_ERR) exit(-1); #endif }
char* ip_to_str | ( | struct in_addr | addr | ) |
Definition at line 634 of file NA_debug_aodv.cc.
{ static char buf[16 * 4]; static int index = 0; char *str; #ifdef NS_PORT #ifndef OMNETPP #undef htonl #endif addr.s_addr = htonl(addr.s_addr); #endif #ifdef OMNETPP IPv4Address add_aux(addr.s_addr.getIPv4()); strcpy(&buf[index],add_aux.str().c_str()); #else strcpy(&buf[index], inet_ntoa(addr)); #endif str = &buf[index]; index += 16; index %= 64; return str; }
void log_cleanup | ( | ) |
Definition at line 113 of file NA_debug_aodv.cc.
{ #ifndef _WIN32 if (log_to_file && log_file_fd) { if (NS_OUTSIDE_CLASS close(log_file_fd) < 0) fprintf(stderr, "Could not close log_file_fd!\n"); } #endif }
void log_init | ( | ) |
Definition at line 64 of file NA_debug_aodv.cc.
{ #ifndef _WIN32 /* NS_PORT: Log filename is prefix + IP address + suffix */ #ifdef NS_PORT char AODV_LOG_PATH[strlen(AODV_LOG_PATH_PREFIX) + strlen(AODV_LOG_PATH_SUFFIX) + 16]; char AODV_RT_LOG_PATH[strlen(AODV_LOG_PATH_PREFIX) + strlen(AODV_RT_LOG_PATH_SUFFIX) + 16]; sprintf(AODV_LOG_PATH, "%s%d%s", AODV_LOG_PATH_PREFIX, node_id, AODV_LOG_PATH_SUFFIX); sprintf(AODV_RT_LOG_PATH, "%s%d%s", AODV_LOG_PATH_PREFIX, node_id, AODV_RT_LOG_PATH_SUFFIX); #endif /* NS_PORT */ if (log_to_file) { if ((log_file_fd = open(AODV_LOG_PATH, O_RDWR | O_CREAT | O_TRUNC, S_IROTH | S_IWUSR | S_IRUSR | S_IRGRP)) < 0) { perror("open log file failed!"); exit(-1); } } if (rt_log_interval) { if ((log_rt_fd = open(AODV_RT_LOG_PATH, O_RDWR | O_CREAT | O_TRUNC, S_IROTH | S_IWUSR | S_IRUSR | S_IRGRP)) < 0) { perror("open rt log file failed!"); exit(-1); } } openlog(progname, 0, LOG_DAEMON); #endif }
void log_pkt_fields | ( | AODV_msg * | msg | ) |
Definition at line 287 of file NA_debug_aodv.cc.
{ RREQ *rreq; RREP *rrep; RERR *rerr; struct in_addr dest, orig; switch (msg->type) { case AODV_RREQ: rreq = (RREQ *) msg; dest.s_addr = rreq->dest_addr; orig.s_addr = rreq->orig_addr; DEBUG(LOG_DEBUG, 0, "rreq->flags:%s rreq->hopcount=%d rreq->rreq_id=%ld", rreq_flags_to_str(rreq), rreq->hcnt, ntohl(rreq->rreq_id)); DEBUG(LOG_DEBUG, 0, "rreq->dest_addr:%s rreq->dest_seqno=%lu", ip_to_str(dest), ntohl(rreq->dest_seqno)); DEBUG(LOG_DEBUG, 0, "rreq->orig_addr:%s rreq->orig_seqno=%ld", ip_to_str(orig), ntohl(rreq->orig_seqno)); break; case AODV_RREP: rrep = (RREP *) msg; dest.s_addr = rrep->dest_addr; orig.s_addr = rrep->orig_addr; DEBUG(LOG_DEBUG, 0, "rrep->flags:%s rrep->hcnt=%d", rrep_flags_to_str(rrep), rrep->hcnt); DEBUG(LOG_DEBUG, 0, "rrep->dest_addr:%s rrep->dest_seqno=%d", ip_to_str(dest), ntohl(rrep->dest_seqno)); DEBUG(LOG_DEBUG, 0, "rrep->orig_addr:%s rrep->lifetime=%d", ip_to_str(orig), ntohl(rrep->lifetime)); break; case AODV_RERR: rerr = (RERR *) msg; DEBUG(LOG_DEBUG, 0, "rerr->dest_count:%d rerr->flags=%s", rerr->dest_count, rerr->n ? "N" : "-"); break; } }
void log_rt_table_init | ( | ) |
Definition at line 107 of file NA_debug_aodv.cc.
{ timer_init(&rt_log_timer, &NS_CLASS print_rt_table, NULL); timer_set_timeout(&rt_log_timer, rt_log_interval); }
const char* packet_type | ( | unsigned int | type | ) |
void print_rt_table | ( | void * | arg | ) |
Definition at line 513 of file NA_debug_aodv.cc.
{ #ifndef _WIN32 char rt_buf[2048], ifname[64], seqno_str[11]; int len = 0; struct timeval now; struct tm *time; if (rt_tbl.num_entries == 0) goto schedule; gettimeofday(&now, NULL); #ifdef NS_PORT time = gmtime(&now.tv_sec); #else time = localtime(&now.tv_sec); #endif len += sprintf(rt_buf, "# Time: %02d:%02d:%02d.%03ld IP: %s seqno: %u entries/active: %u/%u\n", time->tm_hour, time->tm_min, time->tm_sec, now.tv_usec / 1000, devs_ip_to_str(), this_host.seqno, rt_tbl.num_entries, rt_tbl.num_active); len += sprintf(rt_buf + len, "%-15s %-15s %-3s %-3s %-5s %-6s %-5s %-5s %-15s\n", "Destination", "Next hop", "HC", "St.", "Seqno", "Expire", "Flags", "Iface", "Precursors"); write(log_rt_fd, rt_buf, len); len = 0; for (AodvRtTableMap::iterator it = aodvRtTableMap.begin(); it != aodvRtTableMap.end(); it++) { rt_table_t *rt = it->second; if (rt->dest_seqno == 0) sprintf(seqno_str, "-"); else sprintf(seqno_str, "%u", rt->dest_seqno); /* Print routing table entries one by one... */ #ifdef AODV_USE_STL long dif = (1000.0*(SIMTIME_DBL(rt->rt_timer.timeout) - SIMTIME_DBL(simTime()))); if (rt->precursors.empty()) len += sprintf(rt_buf + len, "%-15s %-15s %-3d %-3s %-5s %-6lu %-5s %-5s\n", ip_to_str(rt->dest_addr), ip_to_str(rt->next_hop), rt->hcnt, state_to_str(rt->state), seqno_str, (rt->hcnt == 255) ? 0 : dif, rt_flags_to_str(rt->flags), if_indextoname(rt->ifindex, ifname)); else { len += sprintf(rt_buf + len, "%-15s %-15s %-3d %-3s %-5s %-6lu %-5s %-5s %-15s\n", ip_to_str(rt->dest_addr), ip_to_str(rt->next_hop), rt->hcnt, state_to_str(rt->state), seqno_str, (rt->hcnt == 255) ? 0 : dif, rt_flags_to_str(rt->flags), if_indextoname(rt->ifindex, ifname), ip_to_str(rt->precursors[0].neighbor)); #else if (rt->precursors.empty()) len += sprintf(rt_buf + len, "%-15s %-15s %-3d %-3s %-5s %-6lu %-5s %-5s\n", ip_to_str(rt->dest_addr), ip_to_str(rt->next_hop), rt->hcnt, state_to_str(rt->state), seqno_str, (rt->hcnt == 255) ? 0 : timeval_diff(&rt->rt_timer.timeout, &now), rt_flags_to_str(rt->flags), if_indextoname(rt->ifindex, ifname)); else { len += sprintf(rt_buf + len, "%-15s %-15s %-3d %-3s %-5s %-6lu %-5s %-5s %-15s\n", ip_to_str(rt->dest_addr), ip_to_str(rt->next_hop), rt->hcnt, state_to_str(rt->state), seqno_str, (rt->hcnt == 255) ? 0 : timeval_diff(&rt->rt_timer.timeout, &now), rt_flags_to_str(rt->flags), if_indextoname(rt->ifindex, ifname), ip_to_str(((precursor_t *) rt->precursors[0].neighbor)); #endif /* Print all precursors for the current routing entry */ for (unsigned int i = 1; i< rt->precursors.size(); i++) { precursor_t *pr = &rt->precursors[i]; len += sprintf(rt_buf + len, "%64s %-15s\n", " ",ip_to_str(pr->neighbor)); /* Since the precursor list is grown dynamically * the write buffer should be flushed for every * entry to avoid buffer overflows */ write(log_rt_fd, rt_buf, len); len = 0; } } if (len > 0) { write(log_rt_fd, rt_buf, len); len = 0; } } /* Schedule a new printing of routing table... */ schedule: timer_set_timeout(&rt_log_timer, rt_log_interval); #endif }
int debug |