Search the web
Sign In
New User? Sign Up
cheapthreads · cheap_threads
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want to share photos of your group with the world? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
HELP HELP HELP   Message List  
Reply | Forward Message #3 of 89 |
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;
}







Mon Jul 14, 2003 12:31 pm

blaze01211983
Offline Offline
Send Email Send Email

Forward
Message #3 of 89 |
Expand Messages Author Sort by Date

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...
xcelcior
blaze01211983
Offline Send Email
Jul 14, 2003
12:31 pm

Comments below... ... I'm not sure what you're complaining of. You say that thread 2 runs. It's supposed to. That's what the scheduler does for you -- it...
Scott McKellar
jm407a
Offline Send Email
Jul 15, 2003
2:27 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help