Resolve IP Address for hostname on the iPhone

simple

March 17, 2010

iOS, UIKit

No Comment

On the Mac you might use NSHost, but as this is missing on the iPhone you are of using CFHost. Or much simpler use some standard C functions and you can easily get an IP Address for a hostname on the iPhone:


        #include
        #include

        // Get host entry info for given host
        struct hostent *remoteHostEnt = gethostbyname(“apple.com”);

        // Get address info from host entry
        struct in_addr *remoteInAddr = (struct in_addr *) remoteHostEnt->h_addr_list[0];

        // Convert numeric addr to ASCII string
        char *sRemoteInAddr = inet_ntoa(*remoteInAddr);

        NSString *s = [[NSString alloc] initWithFormat: @“Remote IP: %s\n”, sRemoteInAddr];

Do not forget that their might be more that one IP assigned to a hostname!

You can also get a nice tutorial at:

http://servin.com/iphone/iPhone-Network-Status.html

Related Posts

iPhone OS: Enterprise Business Tools

If you need to manage iPhones or iPads in a big enterprise business, your should read Apples Support Documents: http://www.apple.com/de/support/iphone/enterprise/ and in any case download the iPhone Configuration Tools for Mac OS X: http://support.apple.com/kb/DL851 and for Windows: http://support.apple.com/kb/DL926 You can then setup configuration profiles, that reflect the setup of your environment: • Passcode-Richtlinien • Funktions-Einschränkungen […]

Read More

iPhone OS: Design a nice InApp Purchase View

To get up a nice InAppPurchase View for Apple’s AppStore, we first need some good looking buttons: http://code.google.com/p/iphonegradientbuttons/ http://undefinedvalue.com/2010/02/27/shiny-iphone-buttons-without-photoshop/ http://iphonedevelopment.blogspot.com/2010/05/improved-gradient-buttons.html http://stackoverflow.com/questions/422066/gradients-on-uiview-and-uilabels-on-iphone/ There are also some tweaks for the UITableView you might consider using: http://stackoverflow.com/questions/400965/how-to-customize-the-background-border-colors-of-a-grouped-table-view/ http://stackoverflow.com/questions/986392/programmatically-force-a-uiscrollview-to-stop-scrolling-for-sharing-a-table-view/ more information upcoming…

Read More

Leave a Reply