How to get income sip ip address in an Asterisk application?

Hi All,

My question is, in an Asterisk application, such as app_dial, app_cdr, etc. how can I get the preivous hop ip of a sip call? It is important for bill to know the ip address.

Thanks