Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-10-12
7
Medium Priority
?
976 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 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
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.

 
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

Technology Partners: 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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

730 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