packet capturing tex file
hi every one i have taken a code of packet capturing from net and i am saving that information in a text file
but the problem is that even i have close the file using close() function but it is still created and i think there are not
packets in the network but is is still created i delete it and it is again created. any idea please tell me
here is the part where i have implemented filing. (i have run this code on terminal )
void packetHandler(
{
FILE *f1;
const struct ether_header* ethernetHeader;
const struct ip* ipHeader;
const struct udphdr* udpHeader;
const struct tcphdr*tcpHeader;
char sourceIp[
char destIp[
char * transport_protocol;
char sp[5] ,dp[5];
int sourcePort,
u_char *data;
int dataLength = 0;
char dataStr[100]="";
char filedata[500]="";
ethernetHeader = (struct ether_header*
if (ntohs(
{
ipHeader = (struct ip*)(packet + sizeof(struct ether_header));
inet_
inet_
if (ipHeader->ip_p == IPPROTO_UDP)
{
udpHeader = (struct udphdr*)(packet + sizeof(struct ether_header) + sizeof(struct ip));
sourcePort = ntohs(udpHeader
destPort = ntohs(udpHeader
dataLength = pkthdr->len - (sizeof(struct ether_header) + sizeof(struct ip) + sizeof(struct udphdr));
}
else if (ipHeader->ip_p == IPPROTO_TCP)
{
sourcePort = ntohs(tcpHeader
destPort = ntohs(tcpHeader
data = (u_char*)(packet + sizeof(struct ether_header) + sizeof(struct ip) + sizeof(struct tcphdr));
dataLength = pkthdr->len - (sizeof(struct ether_header) + sizeof(struct ip) + sizeof(struct tcphdr));
}
}
sprintf(
sprintf(
f1=fopen(
fputs(sourceIp,f1);
fputs("\n",f1);
fputs(destIp,f1);
fputs(" ",f1);
fputs(sp,f1);
fputs(" ",f1);
fputs(dp,f1);
fputs(" ",f1);
fputs("\n",f1);
fclose(f1);
} //end function
thanks in adcance
Question information
- Language:
- English Edit question
- Status:
- Answered
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask sajidtariq for more information if necessary.