⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nprobe.i

📁 该软件根据网络数据生成NetFlow记录。NetFlow可用于网络规划、负载均衡、安全监控等
💻 I
📖 第 1 页 / 共 5 页
字号:
/*  -*- Mode: C;  -*- *//*******************************************************************************                                                                             **   Copyright 2005 University of Cambridge Computer Laboratory.               **                                                                             **   This file is part of Nprobe.                                              **                                                                             **   Nprobe 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.                                       **                                                                             **   Nprobe 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 Nprobe; if not, write to the Free Software                     **   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA **                                                                             *******************************************************************************/%module nprobe%{#include <stdio.h>#include <linux/limits.h>#include <sys/time.h>#include <sys/resource.h>#include <assert.h>#include <netinet/in.h>#include <arpa/inet.h>#include "http_errdefs.h"#include "basic_defs.h"#include "list.h"#include "counters.h"#include "np_file.h"#include "flows.h"#include "http.h"#include "tcp.h"#include "udp.h"#include "udp_ns.h"#include "icmp.h"#include "except.h"#include "sundry_records.h"#include "if_stats.h"#include "procstat.h"#include "wread_util.h"#include "print_util.h"#include "flow_util.h"#include "report.h"#include "http_util.h"#include "content_t.h"#include "writer.h"//#include "malloc_trace.h"#include "malloc_rec.h"#include "service.h"%}%include "http_errdefs.h"%include "basic_defs.h"%include "counters.h"%include "np_file.h"%include "fingerprint.h"%include "flows.h"%include "tcp.h"%include "http.h"%include "parse_object.h"%include "udp.h"%include "sundry_records.h"%include "procstat.h"%include "udp_ns.h"%include "icmp.h"%include "http_util.h"%include "content_t.h"%include "writer.h"%include "service.h"/*****************************************************************************//* * Some non-method functions  */char *host_string(unsigned int addr);char *intoa_string(unsigned int addr);int _inet_aton(char *dotaddr);void print_hostname(unsigned int addr);void set_print_full_hostname(int flag);char *port_string(unsigned short port, int proto);char *rectype_str(int type);char *atmdata_string(unsigned int atmdata);unsigned char parse_type(char *arg);char *http_server_returncode_string(unsigned short code);/* char *http_server_objtype_string(unsigned short objtype); */char *http_server_objtype_string(int objtype);char *http_client_method_string(unsigned char method);//char *linkrec_type_string(int type);char *http_errstring(int err);unsigned int n2hl(unsigned int addr);int accept_conn(struct flow_inner *conn, int fspec);void filter_help(void);void _free(long addr);void malloc_report(void);%{char *host_string(unsigned int addr){  unsigned int a = addr;  return get_hname((char *)&a);}char *intoa_string(unsigned int addr){  //return inet_ntoa((struct in_addr)addr);  return intoa(addr);}int _inet_aton(char *dotaddr){  struct in_addr a;  if (inet_aton(dotaddr, &a) == 0)    //fprintf(stderr, "addr %s\n", dotaddr);    //printf("addr %s\n", dotaddr);    //wr_error("_inet_aton");    a.s_addr = 0U;  return (int)a.s_addr;}void print_hostname(unsigned int addr){  unsigned int a = addr;  printf("%s", get_hname((char *)&a));}void set_print_full_hostname(int flag){  print_hostnames = flag;}char *port_string(unsigned short port, int prot){  return tcpudp_port_string(port, (unsigned char)prot);}char *atmdata_string(unsigned int atmdata){  return get_atmaddr(atmdata);}unsigned char parse_type(char *arg){  return _parse_type(arg);}char *http_server_returncode_string(unsigned short code){  return status_string(code);}/* char *http_server_objtype_string(unsigned short objtype)*/char *http_server_objtype_string(int objtype){  return content_type_string(objtype);}char *http_client_method_string(unsigned char method){  return method_string(method);}/*  char *linkrec_type_string(int type) *//*  { *//*    return link_rec_type_string((unsigned char) type); *//*  } */unsigned int n2hl(unsigned int addr){  return ntohl(addr);}char *http_errstring(int err){  return http_err_string(err);}int accept_conn(struct flow_inner *conn, int fspec){  return _pass(conn, fspec);}void filter_help(void){  _filter_help();}char *rectype_str(int type){  return np_rectype_str((unsigned char)type);}/* Free some allocated chunk of memory */void _free(long addr){  free((void *)addr);}void malloc_report(void){  report_rec_malloc_full();}%};/* * Want methods that return python objects to do so without further wrapping *  */%typemap(python, out) PyObject *{  $target=(PyObject *)_result;}/*****************************************************************************//*%except(python) {  char *err;  clear_except();  $tell_all  if ((err = check_except()))  fprintf(stderr, "%s\n"; err);  }*//*%except(python);*//*****************************************************************************//* * Class  ulong_int - generated from basic-defs.h  * - used to convert unsigned ints to Python longs */%addmethods ulong_int {/* Constructor */ulong_int(int ul){  struct ulong_int *up;  if ((up = (struct ulong_int *)malloc(sizeof(struct ulong_int))) == NULL)    wr_error("ulong_int: malloc");  up->half = ((unsigned int)ul)/2;  up->odd = ((unsigned int)ul) & 0x1;  return up;}/*Destructor */~ulong_int(){  free(self);}}; /* End addmethods ulong_int *//*****************************************************************************//*  * Class counters - generated from counters.h * Represents global run-time counters. */%addmethods counters {/* Constructor */counters(){  struct counters *cp;  tmval tv = {0UL, 0UL};	  if ((cp = (struct counters *)malloc(sizeof(struct counters))) == NULL)    wr_error("counters: malloc");  counters_init(cp, &tv, 0);    return cp;}/*Destructor */~counters(){  free(self);}/* Add in another counter */void addin(counters_t *addnd){  add_ctrs(self, addnd);  return;}void printself(char *leader){  report_counters(self, stdout, leader);}void printself_tofile(char *path, char *leader){  FILE *file;  if ((file = fopen(path, "w")) == NULL)    wr_error("counters_printself_tofile(): open");  report_counters(self, file, leader);  if (fclose(file) != 0)    wr_error("counters_printself_tofile(): close");}void printself_tofile_with_preamble(char *path, char *leader, char *preamble){  FILE *file;  if ((file = fopen(path, "w")) == NULL)    wr_error("counters_printself_tofile(): open");  fprintf(file, "%s", preamble);  report_counters(self, file, leader);  if (fclose(file) != 0)    wr_error("counters_printself_tofile(): close");}/* Return run start time */struct tval *run_start(){  return (struct tval *)&self->start;}/* Return run end time */struct tval *run_end(){  return (struct tval *)&self->stop;}}; /* End addmethods counters *//*****************************************************************************//*  * Class np_file - generated from np_file.h * Represents an Nprobe dump file and state for reading it together with  *  header info and associated counters. * Contains class fhdr_t */%addmethods np_file { /* Constructor */np_file(char *file, int build_indx){  struct np_file *npf;	  if ((npf = (struct np_file *)malloc(sizeof(struct np_file))) == NULL)    wr_error("Np_file: malloc");    strcpy(npf->fnm, file);  _file_open(npf);    if (build_indx)    _indx(npf);  else    npf->offsets = NULL;		    return npf;}/*Destructor */~np_file() {  if (fclose(self->file) != 0)    wr_error("np_file_delete: fclose error");  if (self->offsets)    free(self->offsets);  free(self);}/* Reset file */void reset(){  _file_reset(self);}/* Print file global counters */void printcounters(char *leader){  report_counters(&self->counters, stdout, leader);}/* Print file global counters */void printcounters_tofile(FILE *file, char *leader){  report_counters(&self->counters, file, leader);}/* Print file name */void printname(){  printf("%s\n", self->fnm);}/* Print file header */void printhdr(){  printf("File %s (%s)\n", self->fnm, 	 self->counters.fh.compressed != NOT_COMPRESSED ? "compressed"	 : "not compressed");  if (self->counters.fh.how_collected == TCPDUMP_COLL)    printf("\tResults from dump file %s:\n", self->counters.fh.data);  else    printf("\tResults from online run:\n");  printf("\t%lu records\n", 	 self->counters.nrecords);}/* Get file open time */struct tval *open(){  return (struct tval *)&self->counters.start;}/* Get file close time */struct tval *close(){  return (struct tval *)&self->counters.stop;}/* Print entire contents - optionally of type X*/int printfile(int type, int keytype, char *keystr, int quietflag){  unsigned int key;  struct in_addr addr;  if(keytype == KEY_CONN_ID || keytype == KEY_REC)    {      key = strtoul(keystr, NULL, 0);    }  else if (keytype == KEY_SERV_ADDR || keytype == KEY_CLI_ADDR)    {       if ((key = inet_aton(keystr, &addr)) == 0)	{	  fprintf(stderr, "Cannot translate address %s\n", keystr);	  exit(1);	}      key = addr.s_addr;    }  else if (keytype)    {      wr_error("printfile: keytype error");    }  return _printfile(self, 1, (unsigned char)type, keytype, key, quietflag);}/* Filter for desired record type */int filter(int type, char *ofile){  return _filter_file(self, type, ofile);}/* Get # cpus of collecting machine */int get_ncpus(){  return self->counters.fh.ncpus;}/* Get tick rate */int get_hz(){  return self->counters.fh.hz;}/* Get page size */int get_pgsz(){  return self->counters.fh.pgsz;}void seekrec(unsigned int rec){  _seek_rec(self, rec);}/* Position to read next record - return record type */int next_rec(){  return _next_rec(self, REC_ALL);}/* Position to read next record of specified type - return record type */int next_type_rec(int type){  return _next_rec(self, (unsigned char)type);}/* Advance over record to preeamble of next */void advance(){  _advance(self);}/* Return index of current record */unsigned int curr_indx(){  return self->indx -1;}/* Return 1 if record is of specified type */int is_rectype(int type, int wanted){  return _is_rectype(type, wanted);}/* Return current file offset */long int offset(){  return _offset(self);}/* Return file offset of current record (after rec header) */long int curr_offset(){  return self->curr_offset;}/* Seek to given offset */int seek(long offset){  return _seek(self, offset);}/*  * Position to read next record of type TCP/HTTP or UDP/NS  * - return record type or -1 if EOF  */int find_next_http_or_ns_record(){  int type;  while (1)    {      type = _next_rec(self, REC_IP);      if (type == REC_TCP_HTTP || type == REC_UDP_DNS || type == -1)	return type;      else 	_advance(self);    }}/*  * Position to read next record of type TCP, TCP_OPEN or TCP_HDRS * - return record type or -1 if EOF  */int find_next_tcp_and_hdrs(){  int type;#if 0  while (1)    {      type = _next_rec(self, REC_IP);      if ((type > REC_TCP_MIN 	  && type < REC_TCP_MAX)	  || type == -1)	return type;      else 	_advance(self);    }#endif  return _next_rec(self, REC_TCP_ALL);}/*  * Position to read next record of type TCP/HTTP, TCP_OPEN, TCP_HDRS or UDP/NS  * - return record type or -1 if EOF  */int find_next_http_and_hdrs_or_ns_record(){  int type;  while (1)    {      type = _next_rec(self, REC_IP);      if (type == REC_TCP_HTTP 	  || type == REC_TCP_HTTP_OPEN 	  || type == REC_TCP_HTTP_HDRS 	  || type == REC_UDP_DNS 	  || type == -1)	return type;      else 	_advance(self);    }}/*  * Position to read next record of type period report  * - return record type or -1 if EOF  */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -