Prereqs:
- Have a 3G iPhone for 12-18 months
- Pay AT&T more than $100 per month
Next, I went to the apple store and bought my phone for a net price of ~$30!!!!!
- $299 for 3GS/32GB
- $~30 fees
+$300 cash
---------------
=$~30
I am software engineer with thirteen years of experience building shrink wrap software for businesses. I'll do my best to share my experiences with you in the hopes that they may benefit your lives and careers as Software Engineers or other technocrati.
iterates over the IPs of the phone using getifaddrs(&addrs). if getWiFiIPAddress finds "en0" in the list interface addresses (ifaddrs) it will return the ethernet adapter zero (en0) IP address as a NSSring*. If no address is found the function will return NULL.
//------- includes
#include <ifaddrs.h>
#include <arpa/inet.h >#include <sys/types.h >#include <sys/socket.h >#include <net/if.h >#include <net/if_dl.h >#include <arpa/inet.h >#include <ifaddrs.h >
#if ! defined(IFT_ETHER)
#define IFT_ETHER 0x6/* Ethernet CSMACD */
#endif
//------- Implementation
- (NSString*)getWiFiIPAddress
{
BOOL success;
struct ifaddrs * addrs;
const struct ifaddrs * cursor;
success = getifaddrs(&addrs) == 0;
if (success) {
cursor = addrs;
while (cursor != NULL) {
if (cursor->ifa_addr->sa_family == AF_INET && (cursor->ifa_flags & IFF_LOOPBACK) == 0) // this second test keeps from picking up the loopback address
{
NSString *name = [NSString stringWithUTF8String:cursor->ifa_name];
if ([name isEqualToString:@"en0"]) { // found the WiFi adapter
return [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)cursor->ifa_addr)->sin_addr)];
}
}
cursor = cursor->ifa_next;
}
freeifaddrs(addrs);
}
return NULL;
}
PS: I need a better blog, that support snippets - comments?