I’m new to iOS/MacOS programming and have not found any examples I understand. I imagine it is only a few lines of code to do this, so sorry if this is covered already but for the life of me I cannot find it.
I’m using CFStreamCreatePairWithSocketToHost to create in/out streams. I just want to get the local endpoint info (specifically the IP address, don’t care about port really). I already obtain the public IP info from my server, but for security/logging reasons I need the local address as well.
This is on iOS, not MacOS, if it matters.
The following code demonstrates how to get the local socket address. It works with IPv4 and IPv6 addresses. (It is more than a few lines, perhaps somebody knows a shorter solution.)