Solved

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

Posted on 2004-10-12
7
922 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 86

Expert Comment

by:jkr
Comment Utility
>>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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now