Solved

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

Posted on 2004-10-12
7
962 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
[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
7 Comments
 
LVL 12

Accepted Solution

by:
OnegaZhang earned 500 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
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!

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how not to pass environment to child process by using ShellExecute or ShellExecuteEx 16 195
Add values of each row in an array 3 81
Safe conversion? 4 87
learn programming 8 95
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…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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.

751 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