Код:
#include <stdio.h>
#include <iostream>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <iomanip>
#include <mysql.h>
using namespace std;
MYSQL mysql;
MYSQL_RES *res;
MYSQL_ROW row;
//vars
int fd[2];
int ret;
int i;
void exiterr(int exitcode)
{
fprintf(stderr, "%s\n", mysql_error(&mysql));
exit(exitcode);
}
main(){
uint i = 0;
if (!(mysql_real_connect(&mysql,"127.0.0.1","root","111111","traf",3306, NULL,0)))
exiterr(1);
FILE *file;
char src[16];
char dst[16];
char pack[16];
char bytes[16];
char sport[16];
char dport[16];
char proto[16];
char iface[16];
file = popen ("rsh 127.0.0.1 sh ip acco", "r");
if (file!=NULL){
while (!feof(file)){
if (fscanf(file, "%s", src))
if (fscanf(file, "%s", dst))
if (fscanf(file, "%s", pack))
if (fscanf(file, "%s", bytes))
if (fscanf(file, "%s", sport))
if (fscanf(file, "%s", dport))
if (fscanf(file, "%s", proto))
if (fscanf(file, "%s", iface))
if ( (src[0] == 'A') ){
break;
}
if ( (sizeof(src) > 0) && (src[0] != 'S') ){
if (mysql_query(&mysql,"INSERT INTO stattemp VALUES ('','','sport','dport','bytes',INET_ATON('src'),INET_ATON('dst'))"))
exiterr(3);
}
}
}
pclose (file);
mysql_close(&mysql);
system("rsh 127.0.0.1 clear ip acco");
}
Сам код рабочий, проблема в том что в поля таблицы заносятся не значение переменных sport, dport,bytes..... а просто текст sport, dport,bytes...
то-есть получается вот так:
src_port | dst_port | all_bytes |
----------|-----------|------------|
sport dport bytes
sport dport bytes
sport dport bytes
sport dport bytes
sport dport bytes
как сделать что-бы заносились значения переменных, а не этот текст?