Solved

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

Posted on 2004-08-30
6
238 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

734 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