I am trying to construct HTTP content from packet sniffing using C. Right now, I am able to save all of the packets in a file but I want to get rid of the headers in the first packet. The headers are also being saved because they are a part of the TCP payload. The actual body after the header starts after a double "CR, LF" or "\r\n\r\n"
in the HTTP response.
How do I detect "\r\n"
so that I can save only the part of the buffer that follows it? The buffer is u_char type. I can't figure out the command. I looked on Google and other places, but I mostly find C# commands - nothing in C.
i am using this function
void strtofcntnt(const u_char * Biffer, int size)
{
unsigned short iphdrlen;
struct iphdr *iph = (struct iphdr *)(Buffer + sizeof(struct ethhdr));
iphdrlen = iph->ihl*4;
struct tcphdr *tcph = (struct tcphdr*)(Buffer + iphdrlen + sizeof(struct ethhdr))
;
char data[] = *(Buffer);
char rdata[] = strstr(data, "\r\n\r\n");
unsigned int i;
for (i=0;i<=sizeof(data);i++)
{
fprintf(logfile,"%c",(unsigned int)data[i]);
}}
but it gives error in the chara data[] and char rdata[] lines during compiling. error says invalid initializer.