struct db_tns_accept//0x02
{
u_short ns_vr;
u_short ser_opt;
// u_char ser_opt2;//no need
u_short SDU_size;
u_short TDU_size;
u_short hardware;
u_short data_length;
u_short offset;
u_char flag0;
u_char flag1;
};
struct db_tns_reject//0x04
{
u_char usr_refuse_reason;
u_char sys_refuse_reason;
u_char data_length;
};
struct db_tns_redirect//0x05
{
u_short data_length;
u_char data;//
};
struct db_tns_marker//0x0c
{
//u_char data_length[3];
u_char type;
u_char data_byte0;
u_char data_byte1;
};
struct db_tns_data
{
u_short data_flag;//Data Flag
};
/*sqlserver header-tds protocol*/
/*DB2 header-db2 protocol*/
/*sybase header-npgsql protocol*/
/*Postgresql header-tds protocol*/
/*protocol define end*/
/*function define start*/
void
got_ethernet_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet);
void
got_ip_package(u_char *args,const struct pcap_pkthdr *header,const u_char *packet);
void
got_tcp_package(u_char *args,const struct pcap_pkthdr *header,const u_char *packet,int size_ip);
void
got_udp_package(u_char *args,const struct pcap_pkthdr *header,const u_char *packet,int size_ip);
void
got_mysql_package(u_char *args,const struct pcap_pkthdr *header,const u_char *packet,int size_tcp);
void
got_tns_package(u_char *args,const struct pcap_pkthdr *header,const u_char *packet,int size_tcp);
void
got_data_package(u_char *args,const struct pcap_pkthdr *header,const u_char *packet,int size_header);
void
print_payload(const u_char *payload, int len);
void
print_hex_ascii_line(const u_char *payload, int len, int offset);
void
print_app_banner(void);
void
print_app_usage(void);
void
put_in_file(const u_char *buff,int len);
/*function define end*/
/*function implement start*/
/*
* app name/banner
*/
void
print_app_banner(void)
{
printf("%s - %s\n", APP_NAME, APP_DESC);
printf("%s\n", APP_COPYRIGHT);
printf("%s\n", APP_DISCLAIMER);
printf("\n");
return;
}
/*
* print help text
*/
void
print_app_usage(void)
{
printf("Usage: %s [interface]\n", APP_NAME);
printf("\n");
printf("Options:\n");
printf(" interface Listen on <interface> for packets.\n");
printf("\n");
return;
}
/*
* print data in rows of 16 bytes: offset hex ascii
*
* 00000 47 45 54 20 2f 20 48 54 54 50 2f 31 2e 31 0d 0a GET / HTTP/1.1..
*/
void
print_hex_ascii_line(const u_char *payload, int len, int offset)
{
int i;
int gap;
const u_char *ch;
/* offset */
printf("%05d ", offset);
/* hex */
ch = payload;
for(i = 0; i < len; i++) {
printf("%02x ", *ch);
ch++;
/* print extra space after 8th byte for visual aid */
if (i == 7)
printf(" ");
}
/* print space to handle line less than 8 bytes */
if (len < 8)
printf(" ");
/* fill hex gap with spaces if not full line */
if (len < 16) {
gap = 16 - len;
for (i = 0; i < gap; i++) {
printf(" ");
}
}
printf(" ");
/* ascii (if printable) */
ch = payload;
for(i = 0; i < len; i++) {
if (isprint(*ch))
printf("%c", *ch);
else
printf(".");
ch++;
}
printf("\n");
return;
}
/*
* print packet payload data (avoid printing binary data)
*/
void
print_payload(const u_char *payload, int len)
{
int len_rem = len;
int line_width = 16; /* number of bytes per line */
int line_len;
int offset = 0; /* zero-based offset counter */
const u_char *ch = payload;
if (len <= 0)
return;
/* data fits on one line */
if (len <= line_width) {
print_hex_ascii_line(ch, len, offset);
return;
}