Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-08-30
6
Medium Priority
?
243 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 450 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 1050 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

650 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