1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
/*
Nast common include file
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* include */
#include <libnet.h>
#include </usr/include/pcap.h>
#include <pthread.h>
#include "../config.h"
#ifdef HAVE_LIBNCURSES
#include <ncurses.h>
#endif
#include "ARPhdr.h"
/* colors */
#define BOLD "\033[1m"
#define UNDER "\033[3m"
#define NORMAL "\033[0m"
#define CYAN "\033[1;36m"
#define TCP_HDR_LEN hdr.len - LIBNET_IPV4_H - LIBNET_TCP_H + offset
#define UDP_HDR_LEN hdr.len - LIBNET_IPV4_H - LIBNET_TCP_H + offset
#define ICMP_HDR_LEN hdr.len - LIBNET_IPV4_H - LIBNET_TCP_H + offset
#define IGMP_HDR_LEN hdr.len - LIBNET_IPV4_H - LIBNET_TCP_H + offset
#define PROMISC 1
#define NOT_PROMISC 0
/* sniffing functions */
int run_sniffer (u_short promisc, u_short data, u_short hex, u_short f, u_short l, u_short tcpdlog, u_short tcpdread, char *filter, char *dev, char ldname[50]);
/* ASCII DATA,HEX DATA,LOGFILE/STDOUT,LOG DATA FILE */
void handle_TCP (u_short d, u_short x, FILE *output, FILE *ldd);
void handle_UDP (u_short d, u_short x, FILE *output, FILE *ldd);
void handle_ICMP(u_short d, u_short x, FILE *output, FILE *ldd);
void handle_IGMP(FILE *output);
void handle_ARP (FILE *output);
u_int16_t handle_ethernet (u_char *packet);
int device (char *dev, pcap_t* descr);
void data_sniffo (char *data, u_int l, FILE *log);
void print_ascii_hex (char *data_info, u_int len, FILE *log);
/* network analyzer functions */
struct host * map_lan (char *dev, u_short mode, u_short *n);
int psearch (char *dev, u_long ip_dst, u_short lg);
int fgw (u_char *dev);
int rst (char *dev, u_long src, u_long dst, u_short sport, u_short dport);
int flink (u_char *dev);
int port(char *dev, u_long dst_ip, libnet_plist_t *plist_p, int lg);
int mport (u_char *dev, u_short ports[], int lg);
int mhport (u_char *dev, libnet_plist_t *plist_p, int lg);
int stream (char *dev, u_long ip_src, u_long ip_dst, u_short sport, u_short dport, int lg);
int car (char *dev, int lg);
int run_bc (char *dev, char *filter);
/* other functions*/
void sigexit(int);
void openfile(void);
void bkg(void);
/* ncurses menu */
#ifdef HAVE_LIBNCURSES
int main_graph(void);
#endif
/* common functions */
char * dn (char * s);
int runcplx (char what, char *dev, int l);
char * nast_hex_ntoa (u_char *s);
char * nast_atoda (u_char *s);
int w_error(int fatal, char *err, ...);
int n_error(char *err, int fatal);
void n_print(char *wins, int y, int x, int lg, char *string, ...);
int ng_print(char *wins, int y, int x, char *string);
int check_pthread(void);
void init_scr(void);
/* variable */
extern FILE *logd;
extern short offset;
extern int npkt;
extern u_char *packet;
extern u_char *buf;
extern struct pcap_pkthdr hdr;
extern pcap_t* descr;
extern pcap_dumper_t *dumper;
extern struct pcap_stat statistic;
extern bpf_u_int32 maskp; /* subnet mask */
extern bpf_u_int32 netp; /* ip */
extern int datalink;
extern struct bpf_program fp; /* hold compiled program */
extern char *logname;
extern char *tcpdl;
extern u_short tr,tl;
extern u_short graph; /* global var for ncurses mode */
extern u_short cont;
/* golbal var*/
extern int stream_glob;
extern int bc_glob;
extern int sniff_glob;
extern int rst_glob;
extern int arp_glob;
extern pthread_t pt[2];
extern int lg;
struct host
{
unsigned char mac[ETHER_ADDR_LEN];
unsigned char ip[4];
};
/* time variable */
extern time_t tm;
extern char timed[60];
/* for demonize nast */
extern u_short demonize;
extern int line_s;
extern int row_s;
|