2013-03-01 8 views
9

Devo trovare un modo per scoprire la subnet mask e l'indirizzo broadcast del mio hotspot personale in iOS.Come ottenere la subnet mask e l'indirizzo broadcast dell'hotspot personale in iOS

Sto utilizzando il seguente modo per trovare l'indirizzo IP del dispositivo se è connesso al WiFi. Ma non riesco a capire il modo di ottenere proprietà di rete per Hotspot personale.

+ (NSString *) localIPAddress 
{ 
    NSString *address = @"error"; 
    struct ifaddrs *interfaces = NULL; 
    struct ifaddrs *temp_addr = NULL; 
    int success = 0; 

    // retrieve the current interfaces - returns 0 on success 
    success = getifaddrs(&interfaces); 

    if (success == 0) 
    { 
     temp_addr = interfaces; 

     while(temp_addr != NULL) 
     { 
      // check if interface is en0 which is the wifi connection on the iPhone 
      if(temp_addr->ifa_addr->sa_family == AF_INET) 
      { 
       if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) 
       { 
        address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)]; 
       } 
      } 

      temp_addr = temp_addr->ifa_next; 
     } 
    } 

    freeifaddrs(interfaces); 

    return address; 
} 

risposta

9

in cui viene assegnato l'indirizzo, basta inserire:

netmask = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_netmask)->sin_addr)]; 
Problemi correlati