2013-03-01 8 views
9

मुझे आईओएस में अपने व्यक्तिगत हॉटस्पॉट के सबनेट मास्क और प्रसारण पते को खोजने का एक तरीका ढूंढना होगा।आईओएस में व्यक्तिगत हॉटस्पॉट के सबनेट मास्क और ब्रॉडकास्ट पते को कैसे प्राप्त करें

यदि डिवाइस वाईफ़ाई से कनेक्ट है तो डिवाइस के आईपी पते को खोजने के लिए मैं निम्न तरीके से उपयोग कर रहा हूं। लेकिन व्यक्तिगत हॉटस्पॉट के लिए नेटवर्क गुण प्राप्त करने के तरीके को समझ नहीं सकते हैं।

+ (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; 
} 

उत्तर

9

जहां पता असाइन किया गया है, बस सम्मिलित करें:

netmask = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_netmask)->sin_addr)]; 
संबंधित मुद्दे