Storing in HEX format.

2005-06-08 Thread preeth k
Hello,
  I am writing a program for packet sniffing in Linux platform using C 
language. I am using MYSQL as my database for storing packet information like 
IP, port, packet payload, etc. I have created a table using the following query:

create table idsmatch(sip text,sport integer,dip text,dport integer,payload 
longtext);

And, i have written a query for insertion to the table like this:

sprintf(query,"INSERT INTO 
idsmatch(sip,sport,dip,dport,payload)VALUES('%s',%d,'%s',%d,'%s')",
inet_ntoa(ip->saddr),dbsport,inet_ntoa(ip->daddr),dbdport,temp);

I am able to store all values properly except 'temp'.
'temp' is a char array which holds the packet payload. What I want is to store 
the value of 'temp' in 'HEX' format in the table 'idsmatch'. Please tell me 
what is to be done for that.
Thanks in advance.
Preeth.




MySQL Insert error..

2005-04-18 Thread preeth k
Hello,
I am doing programming in C and uses MySQL database. I have got a problem with 
inserting "values stored in variables" to the database. When compiling the code 
that I have written the following error message shows up:

connect2.c: In function `main':
connect2.c:19: invalid operands to binary +

The code that I have written is given below. Please give a solution.
Thanks in advance,
Preeth.

#include
#include
#include
#include

int main(int argc, char *argv[])
{
MYSQL my_connection;
int res;
char srcip[13]="172.16.4.200";
char destip[13]="172.16.4.220";
int srcport=20;
int destport=30;
mysql_init(&my_connection);
if(mysql_real_connect(&my_connection,"LocalHost","root","master","project",0,NULL,0))
{
printf("Connection Success\n");
/***Insert 
Query***/
res=mysql_query(&my_connection,"INSERT INTO 
ids(sip,sport,dip,dport)VALUES('"+srcip+"',"+srcport+",'"+destip+"',"+destport+")");
if (!res)
{
printf("Inserted %lu rows\n",(unsigned 
long)mysql_affected_rows(&my_connection));
}
else
{
fprintf(stderr,"Insert error %d: 
%s\n",mysql_errno(&my_connection),mysql_error(&my_connection));
}
mysql_close(&my_connection);
}
else
{
fprintf(stderr,"Connection Failed\n");
if (mysql_errno(&my_connection))
{ fprintf(stderr,"Connection error %d: 
%s\n",mysql_errno(&my_connection),mysql_error(&my_connection));
}
}
return EXIT_SUCCESS;
}

/***/


'File' data type in MySQL??

2005-04-05 Thread preeth k
Hello,
   I am doing packet capturing and I want to store the packet headers and 
payload in a MySQL database. I have decided the datatypes for all the fields 
except for the packet "payload". I want to know if I can store the  payload 
particulars in a file and then point that file to the table field. Does MySQL 
support these types of operations? Please suggest a method.
Thanks in advance.
Preeth.