title: gethostbyname( ) failed in iOS6
body: <p>I use gethostbyname() to get the device IP. In iOS5, it works well. But in iOS6, the host value returned by gethostbyname() is NULL. Below is my code to get the current local IP of the device.</p>
  
  <pre><code>// retun the host name
  - (NSString *)hostname
  {
      char baseHostName[256];
      int success = gethostname(baseHostName, 255);
      if (success != 0) return nil;
      baseHostName[255] = '\0';
  
  #if !TARGET_IPHONE_SIMULATOR
      return [NSString stringWithFormat:@"%s.local", baseHostName];
  #else
      return [NSString stringWithFormat:@"%s", baseHostName];
  #endif
  }
  
  // return IP Address
  - (NSString *)localIPAddress
  {
      struct hostent *host = gethostbyname([[self hostname] UTF8String]);
      if (!host) {
          herror("resolv");
          return nil;
      }
      struct in_addr **list = (struct in_addr **)host-&gt;h_addr_list;
      return [NSString stringWithCString:inet_ntoa(*list[0]) encoding:NSUTF8StringEncoding];
  }
  </code></pre>
  
  <p>Notice that, simulator works for both iOS5 and iOS6. Only iOS6 device failed.
  What's the difference for the gethostbyname()?
  Or do you have any other solution to get local ip in iOS6?</p>