File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / trafshow / trafshow.h
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 16:55:18 2012 UTC (12 years, 4 months ago) by misho
Branches: trafshow, MAIN
CVS tags: v5_2_3p0, v5_2_3, HEAD
trafshow

    1: /*
    2:  *	Copyright (c) 1993-2004 Rinet Corp., Novosibirsk, Russia
    3:  *
    4:  * Redistribution and use in source forms, with and without modification,
    5:  * are permitted provided that this entire comment appears intact.
    6:  *
    7:  * THIS SOURCE CODE IS PROVIDED ``AS IS'' WITHOUT ANY WARRANTIES OF ANY KIND.
    8:  */
    9: 
   10: #ifndef	_TRAFSHOW_H_
   11: #define	_TRAFSHOW_H_
   12: 
   13: #include <sys/types.h>
   14: #include <sys/time.h>
   15: #include <netinet/in.h>
   16: #include <pcap.h>
   17: #include <pthread.h>
   18: 
   19: /*
   20:  * The default snapshot length.  This value allows most printers to print
   21:  * useful information while keeping the amount of unwanted data down.
   22:  */
   23: #ifndef INET6
   24: #define	SNAPLEN		68	/* ether + IPv4 + TCP + 14 */
   25: #define	ADDRBITLEN	32	/* in bits */
   26: #else
   27: #define	SNAPLEN		96	/* ether + IPv6 + TCP + 22 */
   28: #define	ADDRBITLEN	128	/* in bits */
   29: #endif
   30: 
   31: #define	REFRESH_TIME	2	/* in seconds */
   32: #define	PURGE_TIME	10	/* must be bigger than REFRESH_TIME */
   33: 
   34: #define	TEMP_DIR	"/tmp"
   35: 
   36: typedef enum { Interfaces, NetStat, FlowDump, HelpPage } ShowMode;
   37: 
   38: #ifndef	TRUE
   39: #define	TRUE	1
   40: #endif
   41: #ifndef	FALSE
   42: #define	FALSE	0
   43: #endif
   44: 
   45: #ifndef	MAX
   46: #define	MAX(a, b)	((b) < (a) ? (a) : (b))
   47: #endif
   48: #ifndef	MIN
   49: #define	MIN(a, b)	((a) < (b) ? (a) : (b))
   50: #endif
   51: #ifndef	ABS
   52: #define	ABS(a)		((a) >= 0  ? (a) : -(a))
   53: #endif
   54: 
   55: #if defined(htons) && defined(_BIG_ENDIAN) && defined(sparc)
   56: #undef	htons
   57: #define	htons(x)	((uint16_t)(x))
   58: #endif
   59: #if defined(ntohs) && defined(_BIG_ENDIAN) && defined(sparc)
   60: #undef	ntohs
   61: #define	ntohs(x)	((uint16_t)(x))
   62: #endif
   63: 
   64: #ifdef	DEBUG
   65: #include <time.h>
   66: #include <stdio.h>
   67: #define	dprintf(x)	\
   68: 	{\
   69: 		char Dbuf[50];\
   70: 		struct timeval Dtv;\
   71: 		gettimeofday(&Dtv, 0);\
   72: 		strftime(Dbuf, sizeof(Dbuf), "%T", localtime(&Dtv.tv_sec));\
   73: 		printf("%s.%03d: ", Dbuf, (int)(Dtv.tv_usec / 1000));\
   74: 		printf x;\
   75: 		printf("\n");\
   76: 	}
   77: #else
   78: #define	dprintf(x)
   79: #endif
   80: 
   81: struct netstat_header;
   82: struct htab;
   83: struct selector;
   84: 
   85: typedef	struct pcap_handler {
   86: 	struct pcap_handler *prev, *next;
   87: 	struct pcap_handler *top, *deep;
   88: 
   89: /* fixed input parameters */
   90: 
   91: 	const char *name;		/* interface name */
   92: 	const char *descr;		/* interface description (or null) */
   93: 	const char *addrstr;		/* interface network address list */
   94: 	pcap_t *pcap;			/* pcap device handler */
   95: 	pcap_addr_t *addr;		/* pcap device addresses */
   96: 
   97: /* aggregation stuff */
   98: 	int masklen;			/* mask length in bits */
   99: 	struct netstat_header *maskhdr;	/* mask address */
  100: 
  101: /* operation parameters */
  102: 
  103: 	/*struct timeval pcap_time;*/	/* last packet capture time */
  104: 
  105: 	pthread_mutex_t *ns_mutex;	/* netstat hash table mutex */
  106: 	struct htab *ns_hash;		/* netstat hash table */
  107: 
  108: 	struct selector *selector;	/* list items selector */
  109: 	int selected;			/* the flag: this item is selected */
  110: 
  111: 	/* total statistics */
  112: 	u_int64_t pkt_cnt;              /* packet counter */
  113: 	u_int64_t pkt_len;              /* length of ip packet */
  114: 	u_int64_t data_len;             /* length of ip data */
  115: 
  116: 	u_int64_t pkt_cnt_rate;         /* rate of packet counter */
  117: 	u_int64_t pkt_len_rate;         /* rate of packet length */
  118: 	u_int64_t data_len_rate;        /* rate of data length */
  119: 
  120: } PCAP_HANDLER;
  121: 
  122: 
  123: /* function prototypes */
  124: struct netstat;
  125: char *pcap_setexpr(PCAP_HANDLER *ph_list, const char *expr);
  126: PCAP_HANDLER *pcap_get_selected(PCAP_HANDLER *ph);
  127: PCAP_HANDLER *pcap_set_selected(PCAP_HANDLER *ph, int idx);
  128: void pcap_save(PCAP_HANDLER *ph, const struct netstat *ns);
  129: void pcap_purge(void *arg); /* PCAP_HANDLER *ph_list */
  130: void pcap_clear(void *arg); /* PCAP_HANDLER *ph_list */
  131: void pcap_show(void *arg); /* PCAP_HANDLER *ph_list */
  132: 
  133: PCAP_HANDLER *pcaph_create(PCAP_HANDLER *top, const struct netstat_header *nh);
  134: void pcaph_close(PCAP_HANDLER *ph);
  135: 
  136: /* global variables */
  137: 
  138: extern char package[];
  139: extern char version[];
  140: extern char target[];
  141: extern char compiled[];
  142: extern const char *progname;
  143: extern const char *hostname;
  144: extern const char *color_conf;
  145: extern char *expression;
  146: extern char *search;
  147: extern int aggregate;
  148: extern int popbackflow;
  149: extern int refresh_time;
  150: extern int purge_time;
  151: extern int promisc;
  152: extern int Oflag;
  153: extern int nflag;
  154: extern ShowMode show_mode;
  155: 
  156: #endif	/* !_TRAFSHOW_H_ */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>