We need to populate the SIP Via and Contact headers with the IP
address that the SIP packet will be sent on to a particular
destination.
The standard way to do this in BSD Sockets is with a connected UDP socket. That is:
-
Create your socket.
-
Call connect
with your destination IP address.
-
Call getsockname
to read back the source IP address.
Make sure you monitor these IP addresses for changes otherwise thing’ll fail in various common scenarios like:
To monitor for changes in this specific case, use SCNetworkReachabilityCreateWithAddressPair
.
Also, be aware that connecting a UDP socket means that an ICMP response can be reflected as errors on the socket. I’m not sure where that’s covered in Apple’s documentation; for this sort of thing I usually reach for my trusty copy of UNIX Network Programming.
http://www.unpbook.com
Finally, make sure your BSD Sockets code works in an IPv6-only environment.
MobileTen wrote:
These BSD APIs were neutered years ago by apple for privacy reasons to
avoid using an IP or mac address tracking a user as a replacement to
the once available unique device identifier.
This is only half right. It’s true that recent versions of iOS prevent apps from accessing hardware MAC addresses. However, that change does not apply to local IP addresses.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
These BSD APIs were neutered years ago by apple for privacy reasons to avoid using an IP or mac address tracking a user as a replacement to the once available unique device identifier. You will have to find the IP address by some other means maybe having the server detect the incoming IP address.