Summary
Retrieving the local IP address on client-side from within an interceptor
Obtinaing the local IP address fomr a CORBA request
Environment
Orbix 6.3
All Supported Operating Systems
Question/Problem Description
How to retrieve the local IP address on client side within an interceptor?
Clarifying Information
Orbix provides the following methods to access the local and remote address:
local_address_literal() returns the local address, in string format, of the GIOP connection over which a request was received.
remote_address_literal() returns the remote address, in string format, of the GIOP connection over which a request was received.
Both of the above APIs are server side only, so using these from a client side (withing send_request) is not expected to work.
Resolution
Accessing the local address on the client-side, e.g. in an interceptor can be achieved by using the following code:
CORBA::Object_var obj = orb->resolve_initial_references("IT_IPTransport");
if (CORBA::is_nil(obj))
{
self_addr = (const char*) 0;
return;
}
IT_ATLI2_IP::IPTransport_ptr ip_transport = IT_ATLI2_IP::IPTransport::_narrow(obj);
if (CORBA::is_nil(ip_transport))
{
self_addr = (const char*) 0;
return;
}
CORBA::String_var hostname = ip_transport->local_node_name();
IT_ATLI2_IP::IPAddressSeq_var ip_addresses =
ip_transport->name_to_addresses(
hostname,
0,
IT_ATLI2_IP::PROTOCOL_TCP,
IT_UtcT::never()
);
IT_ATLI2_IP::IPAddress_var ip_address = ip_addresses[0];
self_addr = ip_address->node_literal();
#KnowledgeDocs
#Orbix6
#Orbix