📄 netflow2mysql.h
字号:
/* * Copyright (C) 2003-2004 WIDE Project. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the project nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */#include <sys/types.h>#include <sys/socket.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <netinet/in.h>#include <net/if.h>#include <sys/ioctl.h>#include <arpa/inet.h>#include <getopt.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <mysql.h>#include "NetFlow_v9.h"#include "NetFlow_v5.h"int debug = 0;int store_exporter_address = 0;unsigned long packet_sampling_rate = 1;unsigned long long packet_count = 0;struct hash8 { struct hash8 *next[256]; } template_lookup;struct template_base{ struct template *template; unsigned char is_ipv6;};struct template { struct template *next; char is_scope_field; struct NetFlow_Version_9_FlowSet_Record record;};struct sql_gadget{ MYSQL *handler; char record_buffer[19][16]; char ipv4_bind_map[65536]; char ipv6_bind_map[65536];} *sql;#define SQL_INSERT_HEADER \"INSERT INTO header (\version,\system_uptime,\unix_seconds,\package_sequence,\source_id\) \VALUES\ (\%hu,\%lu,\%lu,\%lu,\%lu)"#define SQL_INSERT_HEADER_WITH_EXPORTER_ADDRESS \"INSERT INTO header (\version,\system_uptime,\unix_seconds,\package_sequence,\source_id,\exporter_address\) \VALUES\ (\%hu,\%lu,\%lu,\%lu,\%lu,\%lu)"#define SQL_INSERT_IPV4_RECORD \"INSERT INTO record (\hid,\ip_protocol_version,\last_switched,\first_switched,\bytes,\pkts,\input_snmp,\output_snmp,\ipv4_src_addr,\ipv4_dst_addr,\prot,\src_tos,\l4_src_port,\l4_dst_port,\ipv4_next_hop,\dst_as,\src_as,\dst_mask,\src_mask,\tcp_flags\) \VALUES\ (\%llu,\%hhu,\%lu,\%lu,\%lu,\%lu,\%hu,\%hu,\%lu,\%lu,\%hhu,\%hhu,\%hu,\%hu,\%lu,\%hu,\%hu,\%hhu,\%hhu,\%hhu )"#define SQL_INSERT_IPV6_RECORD \"INSERT INTO record (\hid,\ip_protocol_version,\last_switched,\first_switched,\bytes,\pkts,\input_snmp,\output_snmp,\ipv6_src_addr,\ipv6_dst_addr,\prot,\src_tos,\l4_src_port,\l4_dst_port,\ipv6_next_hop,\dst_as,\src_as,\dst_mask,\src_mask,\tcp_flags\) \VALUES\ (\%llu,\%hhu,\%lu,\%lu,\%lu,\%lu,\%hu,\%hu,\\"%s\",\\"%s\",\%hhu,\%hhu,\%hu,\%hu,\\"%s\",\%hu,\%hu,\%hhu,\%hhu,\%hhu )"#define ARGUMENTS "\Usage:\n\$ ./NetFlow2MySQL -i <listen interface> -p <listen port>\n\ [--receive-buffer-size <receive buffer size of UDP socket>]\n\ [--mysql-host <mysql host name>]\n\ [--mysql-user <mysql-user>]\n\ [--mysql-password <mysql password>]\n\ [--mysql-database <mysql database>]\n\ [--mysql-port <mysql port>]\n\ [--store-exporter-address]\n\ [-d]\n\ [--packet-sampling-rate <sampling rate>]\n\$ ./NetFlow2MySQL -v\n\See\n\http://cluster19.aist-nara.ac.jp/public/NetFlow2MySQL/NetFlow2MySQL.html\n\for details.\n"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -