Hi all,
I have a strange problem. I have written code which, as a stand alone program, uses libnet to construct an ARP request packet. I then send numerous identical packets with
Code:
for( c = 0; c < 5; c++ ) {
libnet_write( libnet_handle );
}
That works great.
My problem is when I take that very same code and add it to a program that sends and then receives ARP packets (specifically, the replies to the requests sent earlier). The very same code, when put into a function that is called repeatedly, causes a segmentation fault the second time it is called. The previous stand-alone program has been put into a function called send_arp():
void send_arp( void ); is the prototype.
The former stand-alone working-fine program, now-a-function-called-send_arp() is called from the new program like this:
Code:
for( x = 0; x < 2; x++ ) {
send_arp();
pcap_dispatch( pkt_descriptor, 0, ( void * )pcap_callback_fct, NULL );
pcap_dispatch( pkt_descriptor, 0, ( void * )pcap_callback_fct, NULL );
}
This will send out an ARP request, which is picked up by pcap_dispatch; a response is sent from the target, which is picked up by the second call to pcap_dispatch. So far so good. The second iteration of the loop, however, causes the program to segfault just before libnet_write( libnet_handle ); in send_arp(). I have traced this with gdb and also by inserting printf-debug-type statements so I know how far the program has gotten.
I'm at a loss why a perfectly working program will not behave when rewritten as a function. Any help--including just brainstorming "who knows, maybe this is it" sorts of ideas--will be greatly appreciated.
TIA!