I'm not exactly sure about how it can be done in Linphone Android as I've worked on the Linux based Linphone.
But what I know on the basis of Linux based Linphone implementation is that Linphone uses "belle-sip" library to parse the SIP message. As I can see in the belle-sip library code they use "fix_incoming_via()" function in "belle-sip/src/channel.c", this function checks the remote host address & port in VIA header & compares them with the source IP address & source port of the received SIP packet. In case, they don't match the function overwrites & replaces the host, port values in VIA header with the actual remote source IP & remote source port of the received packet.
So, in essence, I think you can use the values present in the SIP Via header (as they're fixed in case of any discripency at the lower level itself).