Solved

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

Posted on 2004-10-12
7
945 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 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 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.

809 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