Regarding network interface name with dual SIM iPhone

I investigated what network interface names are assigned to carrier networks on a dual SIM iPhone by examining the output of getifaddrs(). (An part of the program used for this is provided below.)

//////////////
struct ifaddrs *interfaces = NULL;
struct ifaddrs *an_interface = NULL;

if (0 == getifaddrs(&interfaces)) {
    an_interface = interfaces;
    while (an_interface != NULL) {
        if( an_interface->ifa_addr->sa_family == AF_INET) {
            NSString* name = [NSString stringWithUTF8String:an_interface->ifa_name];
            NSLog(@"Interface name is: %@", name);
        }
        an_interface = an_interface->ifa_next;
    }
}
freeifaddrs(interfaces);

In this investigation, it appeared that the interface name for the sXGP SIM selected under "iPhone > Settings > Cellular > Cellular Data" was always "pdp_ip0". (A screenshot of "Cellular Data" is provided below. this is sample of sXGP selected )"

[QUESTION]

Is the SIM selected in Settings of iPhone always assigned to "pdp_ip0"?

[BACKGROUND]

I am developing a VoIP application and opening sockets by specifying IP addresses for communication.

On a dual SIM iPhone, multiple networks (IP addresses) are visible. Therefore, I need to determine which network to use. My question is whether I can reliably make this decision based on the network interface name.

If the SIM selected in Settings is always assigned to "pdp_ip0", I intend to open the socket using the IP address of "pdp_ip0".

Alternatively, should I use a different method to select the appropriate network interface?

Answered by DTS Engineer in 855813022
Is the SIM selected in Settings of iPhone always assigned to "pdp_ip0"?

BSD interface names are not considered API on Apple platforms. You should not make assumption like en0 is the built-in Wi-Fi, or pdp_ip0 is the primary WWAN interface. Doing that will likely work in most cases and then your program will fail in hard-to-reproduce edge cases.

I have a lot of information about dealing with multiple interfaces in the various posts referenced by Extra-ordinary Networking. I recommend that you read those first, and then come back here with your follow-up questions.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Is the SIM selected in Settings of iPhone always assigned to "pdp_ip0"?

BSD interface names are not considered API on Apple platforms. You should not make assumption like en0 is the built-in Wi-Fi, or pdp_ip0 is the primary WWAN interface. Doing that will likely work in most cases and then your program will fail in hard-to-reproduce edge cases.

I have a lot of information about dealing with multiple interfaces in the various posts referenced by Extra-ordinary Networking. I recommend that you read those first, and then come back here with your follow-up questions.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Regarding network interface name with dual SIM iPhone
 
 
Q