Solved

ICMP query froze when I request it to fast, program with C++ for windows platform under winxp

Posted on 2004-08-30
6
237 Views
Last Modified: 2010-04-01
Hi,

  I made myself some little utility in a object so far it's fine but when I try to ping as for sending 30-40 packets in a row
it's all ok but as of when I try to get those back by quering with recvfrom to rapidly in a tight loop it freeze.
If I put MessageBox in the middle to get to know everytime it loop then it goes through no trouble and
I can see on a list the result. So is there a way on a raw ICMP socket to gather info to see if there is a specific
way to see if there is data in advance or something else so I don't need to put MessageBox or a big delay
in between of every query. It has been weeks and I could not figure it out. Remember that I am using
WinXP and programming in C++ and using raw ICMP socket.


Thank you
0
Comment
Question by:Dogofwars
  • 3
  • 2
6 Comments
 
LVL 22

Expert Comment

by:grg99
ID: 11929803
We'd have to see your code.

Remember that ICMP is an nreliable protocol, so if you send out 40 requests, only 40 - m might get to the destination, only 40 - n might get processed, only 40 - p might get back to you, where 40  >= m >= n >=  p.  So don't be looping for exactly 40 times.

0
 

Author Comment

by:Dogofwars
ID: 11929948
it has a timer of 2 second, pass that it get out of the loop, it freze within the recvfrom procedure and I wanted
to know how someone would do it in a tight loop or explain what to do to avoid it to freze. And as to see my code I would ned to paste three file in there because there are object procedure.  
0
 
LVL 22

Assisted Solution

by:grg99
grg99 earned 150 total points
ID: 11930322
You can do it several ways:

(1)  Set an alarm() which will kick you out of the recvfrom().

(2)  Set the socket to be non-blocking with fcntl().

(3)  Use select() to check for data before doing the recv().

(4)  Use poll() to do likewise, but sideways.

(5)  Use a separate thread to do the recvfrom()'s.


Any of the above should do the trick.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Dogofwars
ID: 11932996
the select() is what I use and it seam not to work unless I did not code it correctly but again, I'll come back at you for this later.
0
 
LVL 2

Accepted Solution

by:
guntherothk earned 350 total points
ID: 11935311
You are probably blocking in recvfrom() waiting for a packet to arrive. select() gives you a signal telling you that a packet has arrived, however, if 10 packets arrive before you get around to looking, you still only get one signal. You need to peek at the socket to see if there is any data waiting. In windows sockets, the function to do this is

    ULONG result;
    if (!ioctlsocket(socket, FIONREAD, &result))
    {// bytes are available, read them. result is the number
    }

In berkeley sockets, it's probably ioctl() or fcntl(). For ICMP or any other datagram protocol, the ioctlsocket() method returns the number of bytes in the first whole datagram on the kernel's input queue, not the total of all the datagrams.

So the outline of your receiving routine looks like; each time I get a signal from select(), while there are bytes on the socket, get and process a packet.
0
 

Author Comment

by:Dogofwars
ID: 11935865
It's true I am blocking it but it seam that select does not do the job correctly because it's watching first to see if there is something or not but when I pass the number of packet I have send it block when the procedure should only occur when there is a packet. It work correctly with non raw socket but with raw socket it seam select does not do any good and just tell there is data anyway, strange but probably saying that because it's some data that is made for
other program and not the ICMP type of data. So if you open a socket that is raw but only report back ICMP and no other data and if other data occur select will return that there is data waiting but not especially what I am looking
for and not what recvfrom is waiting for therefore blocking. A little bit weird and complex but it seam the only logic.
I think I will use another way to get around that, maybe what you are suggesting.

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question