Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pcap_mysql/mysql_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ int check_table_sendInfoTable(MYSQL* mysql,char* name)
{
char buf[256]={0};
char qbuf[256]={0};
snprintf(buf,sizeof(buf),"%s (id int(11) AUTO_INCREMENT primary key,srcip VARCHAR(20),desip VARCHAR(20),srcport int(5),desport int(5),sendtime VARCHAR(20),packetlength int(5));",TABLE_NAME_SEND);
snprintf(buf,sizeof(buf),"%s (id int(11) AUTO_INCREMENT primary key,srcip VARCHAR(20),desip VARCHAR(20),srcport int(10),desport int(10),sendtime VARCHAR(20),packetlength int(10));",TABLE_NAME_SEND);
strcpy(qbuf,"CREATE TABLE ");
strcat(qbuf,buf);
//#ifdef DEBUG
Expand Down Expand Up @@ -175,7 +175,7 @@ int check_table_receiveInfoTable(MYSQL* mysql,char* name)
{
char buf[256]={0};
char qbuf[256]={0};
snprintf(buf,sizeof(buf),"%s (id int(11) AUTO_INCREMENT primary key,srcip VARCHAR(20),desip VARCHAR(20),srcport int(5),desport int(5),arrivetime VARCHAR(20),packetlength int(5));",TABLE_NAME_RECEIVE);
snprintf(buf,sizeof(buf),"%s (id int(11) AUTO_INCREMENT primary key,srcip VARCHAR(20),desip VARCHAR(20),srcport int(10),desport int(10),arrivetime VARCHAR(20),packetlength int(10));",TABLE_NAME_RECEIVE);
strcpy(qbuf,"CREATE TABLE ");
strcat(qbuf,buf);
//#ifdef DEBUG
Expand Down Expand Up @@ -213,7 +213,7 @@ int check_table_memMonitorInfoTable(MYSQL* mysql,char* name)
{
char buf[256]={0};
char qbuf[256]={0};
snprintf(buf,sizeof(buf),"%s (id int(11) AUTO_INCREMENT primary key,pid int(10),cr3 VARCHAR(20),procname VARCHAR(20),time int(11),page int(10),access int(5),gfn VARCHAR(20),gfn_offset VARCHAR(20),gla VARCHAR(20),vcpuid VARCHAR(20));",TABLE_NAME_MEM_MONITOR);
snprintf(buf,sizeof(buf),"%s (id int(11) AUTO_INCREMENT primary key,pid int(10),cr3 VARCHAR(20),procname VARCHAR(20),time int(11),page int(10),access int(10),gfn VARCHAR(20),gfn_offset VARCHAR(20),gla VARCHAR(20),vcpuid VARCHAR(20));",TABLE_NAME_MEM_MONITOR);
strcpy(qbuf,"CREATE TABLE ");
strcat(qbuf,buf);
//#ifdef DEBUG
Expand Down Expand Up @@ -269,7 +269,7 @@ static size_t strcat2(char **dst_out, ...)
int insert_sendInfoTable(MYSQL* mysql,char* srcip,char* desip,int srcport,int desport,char* sendtime,int packetlength){
int res = 0;
size_t len;
sprintf(sql_str_," values('%s','%s',%d,%d,'%s',%d)",
sprintf(sql_str_," values('%s','%s',%hu,%hu,'%s',%d)",
srcip,desip,srcport,desport,sendtime,packetlength);
len = strcat2(&sql,ins_send,sql_str_,NULL);
// fwrite(sql,len,1,stdout);
Expand All @@ -284,7 +284,7 @@ int insert_sendInfoTable(MYSQL* mysql,char* srcip,char* desip,int srcport,int de
int insert_receiveInfoTable(MYSQL* mysql,char* srcip,char* desip,int srcport,int desport,char* arrivetime,int packetlength){
int res = 0;
size_t len;
sprintf(sql_str_," values('%s','%s',%d,%d,'%s',%d)",
sprintf(sql_str_," values('%s','%s',%hu,%hu,'%s',%d)",
srcip,desip,srcport,desport,arrivetime,packetlength);
len = strcat2(&sql,ins_receive,sql_str_,NULL);
// fwrite(sql,len,1,stdout);
Expand Down
45 changes: 22 additions & 23 deletions pcap_mysql/pcap_mysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,41 +103,41 @@ struct sniff_tcp {
*/

//pcap
char* filter_exp; /* The filter expression */
char* filter_exp; /* The filter expression */
struct bpf_program fp; /* The compiled filter expression */
bpf_u_int32 mask; /* The netmask of our sniffing device */
bpf_u_int32 net; /* The IP of our sniffing device */
char* dev;
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t* handle = NULL;
char* dev;
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t* handle = NULL;

//package
const struct sniff_ethernet* ethernet; /* The ethernet header */
const struct sniff_ip* ip; /* The IP header */
const struct sniff_tcp* tcp; /* The TCP header */
u_int size_ip;
u_int size_tcp;
const struct sniff_ethernet* ethernet; /* The ethernet header */
const struct sniff_ip* ip; /* The IP header */
const struct sniff_tcp* tcp; /* The TCP header */
u_int size_ip;
u_int size_tcp;

#ifdef PKG_LOG
//logfile
FILE* pkglog = NULL;
FILE* pkglog = NULL;
#endif

//mysql
int err;
MYSQL mysql;
int err;
MYSQL mysql;

//default little endian
int little_endian = 1;
int little_endian = 1;

//packet handler
const struct in_addr* src_addr;
const struct in_addr* dst_addr;
char src_port[2] = {0x00,0x00};
char dst_port[2] = {0x00,0x00};
char* p;
char time_print[13];

const struct in_addr* src_addr;
const struct in_addr* dst_addr;
char src_port[2] = {0x00,0x00};
char dst_port[2] = {0x00,0x00};
char* p;
char time_print[13];
double temp;

void recycle_all(){
printf("recycling resources...\n");
Expand Down Expand Up @@ -226,9 +226,8 @@ void got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *pa
* This piece of code is prone to bug.
* We use this to simplify our data.
*/
sprintf(time_print,"%ld",(header->ts.tv_sec-1457000000));
sprintf(time_print+6,".");
sprintf(time_print+7,"%ld",(header->ts.tv_usec));
temp = (header->ts.tv_usec)*0.000001+(header->ts.tv_sec-1457000000);
sprintf(time_print,"%6.6f",temp);

insert_sendInfoTable(&mysql,
print_src_addr,
Expand Down