Solved

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

Posted on 2004-08-30
6
231 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Dogofwars
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

771 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

14 Experts available now in Live!

Get 1:1 Help Now