greetings
Im using cheap thread in my project and i cant quite make as desired.
problem description:
one of my modules is a transparent bridge system. (a PC with 2 NICs)
basically, this system just throws all packets sniffed from NIC A to
NIC B and also the other way around.
so in my program i've created 2 threads and called the ct_sched()
The 1st thread sniffs packets from NIC A then throws it to NIC B for
retransmission.
The 2nd thread does the same thing but the other way around NIC B to
NIC A.
All went fine until I tested it and what happended is that when a
packet is received from NIC A thread 1 callback function is executed
but thread 2 is also executed which should not happen since no
packet is detected on NICB. i think it got something to do with the
shared memory space (void * pdata) but i dont know how to use it.
WELL I HOPE SOMEONE COULD HELP ME THNX
source code:
int thread_NIC1( void * pData )
{
//pcap_next_ex() will only return if a packet
//is detected on a NIC
//thread 2 has a callback function called thread_NIC2()and
//identical to thread_NIC1() the only difference
//is if((res = pcap_next_ex(g_opennic2handle, &header, &pkt_data))
//>= 0)
if((res = pcap_next_ex(g_opennic1handle, &header, &pkt_data)) >= 0)
{
if(res == 0)
return CT_OKAY;
for(i=0;i<12;i++)
{
if(pkt_data[i]!=5)
return CT_OKAY;
}
//if(getpacket)
//{
/* convert the timestamp to readable format*/
ltime=localtime(&header->ts.tv_sec);
strftime( timestr, sizeof timestr, "%H:M:%",
ltime);
printf("\nWinPcap pkt_header content: \n");
printf("\n%s,%.6d len:%d\n", timestr, header-
>ts.tv_usec, header->len);
printf("\npkt_data content: \n");
for(i=0;i<((int)(header->caplen+1));i++)
{
printf("%x",pkt_data[i]);
if(((i+1)%LINE_LEN)==0)
printf("\n");
}
printf("\n\n");
printf("\nForwarding packet to NIC2
interface\n");
pcap_sendpacket(g_opennic2handle,pkt_data,
(int)header->caplen);
//}
//getpacket = TRUE;
return CT_OKAY;
}
else if(res == -1)
{
printf("Error reading the packets: %s\n", pcap_geterr
(g_opennic1handle));
return ct_exit();
}
else
return CT_OKAY;
}