#ifndef TRAFFIC_H #define TRAFFIC_H 1 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define BUF_SIZE 128 /* Buffor size */ #define host_len sizeof(struct host) /* For shortage */ #define MAX_COL 17 /* Max number of columns to display */ #define cmp(A, B) ( !bcmp((A), (B), strlen((A))) ) /* Columns */ #define COL_IP 1 #define COL_DATA 2 #define COL_DATA_MAX 3 #define COL_DATA_AVG 4 #define COL_DATA_TOT 5 #define COL_PKT 6 #define COL_PKT_MAX 7 #define COL_PKT_AVG 8 #define COL_PKT_TOT 9 #define COL_MAC 10 #define COL_HOSTNAME 11 #define COL_TCP 12 #define COL_UDP 13 #define COL_ICMP 14 #define COL_TCP_TOT 15 #define COL_UDP_TOT 16 #define COL_ICMP_TOT 17 /* Displaying modes */ #define MODE_STAT 0 #define MODE_HELP 1 typedef struct ether_header eth_hdr; /* Ethernet header */ typedef struct ip ip_hdr; /* IP header */ /* Structure which describe host */ struct host { struct in_addr ip; /* IP Address */ char hostname[32]; /* Hostname */ char mac[18]; /* MAC Address */ u_long in; /* Received bytes in last second */ u_long out; /* Sent byte in last second */ u_long tcp_in; /* TCP bytes received in last second */ u_long tcp_out; /* TCP bytes sent in last second */ u_long udp_in; /* UDP bytes received in last second */ u_long udp_out; /* UDP bytes sent in last second */ u_long icmp_in; /* ICMP bytes received in last second */ u_long icmp_out; /* ICMP bytes sent in last second */ u_long pkt_in; /* Current packets in */ u_long pkt_out; /* Current packets out */ u_long last_in; /* Last received bytes in last time */ u_long last_out; /* Last sent byte in last time */ u_long last_tcp_in; /* Last TCP bytes received in last time */ u_long last_tcp_out; /* Last TCP bytes sent in last time */ u_long last_udp_in; /* Last UDP bytes received in last time */ u_long last_udp_out; /* Last UDP bytes sent in last time */ u_long last_icmp_in; /* Last ICMP bytes received in last time */ u_long last_icmp_out; /* Last ICMP bytes sent in last time */ u_long last_pkt_in; /* Current packets in */ u_long last_pkt_out; /* Current packets out */ u_int64_t tot_in; /* Total bytes in */ u_int64_t tot_out; /* Total bytes out */ u_long tot_tcp_in; /* Total TCP bytes received */ u_long tot_tcp_out; /* Total TCP bytes sent */ u_long tot_udp_in; /* Total UDP bytes received */ u_long tot_udp_out; /* Total UDP bytes sent */ u_long tot_icmp_in; /* Total ICMP bytes received */ u_long tot_icmp_out; /* Total ICMP bytes sent */ u_int64_t tot_pkt_in; /* Total packets in */ u_int64_t tot_pkt_out; /* Total packets out */ u_long max_in; /* Max bytes in */ u_long max_out; /* Max bytes out */ u_long max_pkt_in; /* Max packets in */ u_long max_pkt_out; /* Max packets out */ }; /* Structure which describe exluded host or network */ struct ehost { struct in_addr ip; /* IP Address */ u_char netmask; /* Netmask */ }; /* Options */ struct options { char *dev; /* Device */ char *logfile; /* Log file */ u_int delay; /* Refresh timeout */ u_long times; /* Number of functions calls to estimate elapsed time */ u_char page; /* Current page to display */ short columns[MAX_COL]; /* Diaplaying columns array */ short mode; /* Displaying mode */ short sort; /* Sort column */ u_char rsort; /* Reverse sorting */ float unit; /* Transfer unit */ char unit_name[5]; /* Unit name */ float unit_t; /* Total transfer unit */ char unit_t_name[5]; /* Total unit name */ u_short total; /* Total disabled */ char *exfile; /* Exclude file */ char daemon; /* Daemon mode disabled by default */ char *config; /* Config file */ int discovery; /* Discover hosts */ int private; /* Only IP private classes */ int timeout; /* Exit after timeout */ int revdns; /* Resolve revdns */ }; /* Callback function to pcap_loop() */ void got_packet(u_char *args, const struct pcap_pkthdr * header, const u_char * packet); /* Function which display statistics */ void show_stats(int sig); /* Draw statistics on screen */ void display(); /* Write summarize to file */ void log_file(); /* Routines */ void invalid_class(); float get_unit(char *s); void usage(); void daemonize(); int addhost(struct in_addr h); int addehost(char *h); int addxhost(char *h); char *mac2str(u_char * mac); int inclass(struct in_addr host, struct ehost net); /* Add, Del column */ void add_column(short col); void del_column(short col); /* Printing function */ int print_col(u_char col, u_char pos); /* Sorting */ int cmp_ip(const void *s1, const void *s2); int cmp_data_cur(const void *s1, const void *s2); int cmp_data_tot(const void *s1, const void *s2); int cmp_data_max(const void *s1, const void *s2); int cmp_pkt_cur(const void *s1, const void *s2); int cmp_pkt_tot(const void *s1, const void *s2); int cmp_pkt_max(const void *s1, const void *s2); int cmp_mac(const void *s1, const void *s2); int cmp_hostname(const void *s1, const void *s2); int cmp_tcp(const void *s1, const void *s2); int cmp_udp(const void *s1, const void *s2); int cmp_icmp(const void *s1, const void *s2); int cmp_tcp_tot(const void *s1, const void *s2); int cmp_udp_tot(const void *s1, const void *s2); int cmp_icmp_tot(const void *s1, const void *s2); #endif /* Global variables */ extern struct host *hosts; /* Hosts array */ extern struct host total; /* Summarize */ extern u_int h_num; /* Number of watched hosts */ extern struct options opt; /* Options */ extern char logfile[]; /* Log filename */ extern WINDOW *win; /* Pointer to ncurses window */ extern struct ehost *ehosts; /* Excluded hosts array */ extern struct ehost *xhosts; /* Excluded hosts traffic array */ extern int eh_num; /* Number of excluded hosts */ extern int xh_num; /* Number of excluded hosts traffic */ /* Mutexes */ extern short m_packet; /* Get packet function mutex */ extern short m_display; /* Display function mutex */ extern short m_file; /* File logging function mutex */