I want the Tor to just find the address of a hostname (just give me the IP) on a given circuit without be connected to that hostname. I find that the RELAY_CONNECTED cell includes the IP address of the requested hostname, but in this case the exit node is connected to the hostname and after that returns the IP. According to the Tor Protocol Specification, the RELAY_RESOLVE finds the address associated with a hostname but I do not know how to use it in source code and how to find it.
It is not possible to get the IP address of a Tor hidden service.
For a normal Tor circuit, the client knows the IP of the server, but the server does not know the IP of the client.
The idea behind hidden services is that when both a client and a server are Tor-enabled, it's possible to build Tor circuits in both directions and hide both the client and server IP (by using intermediate nodes).
References: a high-level description of the protocol can be found in Tor: Hidden Service Protocol, while a more detailed description can be found in the original design paper Tor: The Second-Generation Onion Router.