Solved

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

Posted on 2004-08-30
6
233 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Header of docx file 17 97
How to print into std::string like sprintf using C++11? 12 48
Error C2678: binary '!=': no operator found... 4 41
c++, dynamic object by json 1 22
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

912 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now