I have written a c program which captures the packets from Ethernet in promiscuous mode and writes them into a .csv file.
It is as follows:
But I want my csv file as follows:
How can I do it? Code for writing to the csv file is :
int main()
{
/* declarations*/
logfile=fopen(filename,"w+");
/*related stuffs*/
}
void print_udp_packet(unsigned char *Buffer , int Size)
{
/*ip header length related codes*/
char str[] = "UDP";
fprintf(logfile , "Type:%s,SA:%d,DA:%d,UDP Length:%d,UDP Checksum:%d\n"
,str,ntohs(udph->source),ntohs(udph->dest),ntohs(udph->len),ntohs(udph->check));
}
I have used \n
and ,
for next row and column but I am not able to do as the above output?
[after editing as mentioned in the answer]
Unless I am missing something, simply adjust your fprintf statement to not include the column names. Then an initial logging line to generate the table headers.