Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How can I perform a RPC ping programatically with C++

Posted on 2004-10-12
7
Medium Priority
?
981 Views
Last Modified: 2012-05-05
I am writing a program that connects to a series of hosts to make a change to registries on Win32 platforms. I am using the RegConnectRegistry() Win32 API to connect to these remote hosts over RPC. The problem is, when a host is not available, it takes 30 seconds or longer for the API to timeout. Therefore, I would like to perform an RPC ping on each host before making the call to RegConnectRegistry(). Does anyone know which method/function I can use to do this? I have search google, experts exchange, and MSDN - no luck.

Thanks!

John
0
Comment
Question by:JohnBolton
  • 3
  • 2
7 Comments
 
LVL 12

Accepted Solution

by:
OnegaZhang earned 1500 total points
ID: 12295744
Some ping related posts
http://www.codeguru.com/Cpp/I-N/network/

You can consider put those lengthy operation into work thread.
You can use asynchronous socket try to connect port 135 before RegConnectRegistry()

Welcome to www.fruitfruit.com 
0
 
LVL 86

Expert Comment

by:jkr
ID: 12298577
RPC itself does not implement a 'ping' - however, you could use an ICMP ping:

// Declare and initialize variables
char *SendData = "Data Buffer";
LPVOID ReplyBuffer;
      
ReplyBuffer = (VOID*) malloc(sizeof(ICMP_ECHO_REPLY) + sizeof(SendData));
if ((dwRetVal = IcmpSendEcho(hIcmpFile,
  inet_addr("123.456.789.0"),
  SendData, sizeof(SendData),
  NULL, ReplyBuffer,
  sizeof(ReplyBuffer) + sizeof(ICMP_ECHO_REPLY),
  1000)) != 0) {
  printf("\tReceived %ld messages.\n", dwRetVal);
  printf("\tMessage: %s\n", ReplyBuffer);
}
else {
  printf("\tCall to IcmpSendEcho() failed.\n");
  printf("\tError: %ld\n", GetLastError());
}

see e.g. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/icmpsendecho.asp ("IcmpSendEcho")
0
 

Author Comment

by:JohnBolton
ID: 12299155
Thanks for the feedback on the IcmpEchoPing. There is a utility from Microsoft called RPCPing.exe so I am sure there is a way to "ping" an RPC server. Another problem I run into is that the Remote Registry Service is off on some of these workstations. So even if the IcmpEchoPing returns true, I am still unable to connect with RegConnectRegistry() and am forced to wait 30 seconds.

The environment I have to consider could have over 10,000 workstations, so I need something that is fairly quick.

John
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

Expert Comment

by:jkr
ID: 12300313
>>There is a utility from Microsoft called RPCPing.exe so I am sure there is a way to "ping" an RPC server

No. That tool serves a different purpose:

http://support.microsoft.com/default.aspx?scid=kb;en-us;167260

"The RPC Ping Utility can be used to confirm the RPC connectivity between the computer running Microsoft Exchange Server and any of the supported Microsoft Exchange Client workstations on the network. This utility can be used to check if the Microsoft Exchange Server services are responding to RPC requests from the client workstations via the network. "

IOW: It connects to a RPC server. That will not work for you, since *your* RPC server connect uses that lengthy timeout. Having done quite a bit RPC coding, I can assure you that there is no 'generic ping'  in that area.
0
 

Author Comment

by:JohnBolton
ID: 12303111
Yes, I have read that page and understand what you are saying. Please don't misunderstand me, I am sure you are very competent.

However, when I did testing with the RPCPing utility, I pinged hosts that do not have Exchange Server running. RPC seems to the be the underlying protocol for the remote registry service. So, for example, if a workstation has the XP firewall turned on, or remote registry service is turned off, RPCPing will return a failure. If everything is as it should be, RPCPing returns success. This is why I am bent on figuring out which API's Microsoft used in RPCPing.

What do you think? :)
0
 

Author Comment

by:JohnBolton
ID: 12364106
OnegaZhang: if you can provide me with an example, I'll award the points to you. Your solution to try an asynchronous socket on the NBT ports seems like my best bet.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.
Suggested Courses

916 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