3
votes

I have read loads of Microsoft documentation regarding RPC programming and still do not figure out how do we get from RPC server the IP address of the connecting client.

I am sure there is a simple way to get client IP address from server when connecting, but do not know how to do this :/

Thanks for helping, a simple pointer to a documentation would be great.

2
MSDN states it's possible using RpcBindingServerFromClient() function. See my answer. - Ivan Zhakov

2 Answers

4
votes

No - there is no documented way to accomplish this. Windows RPC by design abstracts the network transport (and associated metadata like network addresses) from it's clients.

If you really need something like this, you could bake it into your interface (e.g. implement a Connect() method where your client provides it's IP address that you could stash in a Context Handle). This assumes of course, that you can trust your clients to provide valid IP addresses...

3
votes

It should be possible using RpcBindingServerFromClient. Quoting documentation for RpcBindingServerFromClient:

To query a client's address, an application starts by calling the RpcBindingServerFromClient function to obtain a partially bound server binding handle. The server binding handle can be used to obtain a string binding by invoking RpcBindingToStringBinding. The server can then call RpcStringBindingParse to extract the client's network address from the string binding.

UPDATE 16/05/2017: There is also undocumented function I_RpcServerInqRemoteConnAddress() that most likely return client IP address. But I didn't try it yet.