i am not sure if i get the first point of your question. It feels like a "i want to manipulate sip packets directly". If so, then an sip-proxy like kamailio or opensips i more what you want.
For the second part with the remote-ip take a look at the "info" app and the xml-cdrs for debugging and research for the correct Channel-Variables. Also http://wiki.freeswitch.org/wiki/Channel_Variables is a good point to read.