This question was already asked here: http://stackoverflow.com/questions/1720316/nsnetservice-ip-address
and here: http://stackoverflow.com/questions/938521/iphone-bonjour-nsnetservice-ip-address-and-port
I've used both of those to get where I'm at now. My problem is the following method I have doesn't quite work:
- (NSString *)getStringFromAddressData:(NSData *)dataIn {
struct sockaddr_in *socketAddress = nil;
NSString *ipString = nil;
socketAddress = (struct sockaddr_in *)[dataIn bytes];
ipString = [NSString stringWithFormat: @"%s",
inet_ntoa(socketAddress->sin_addr)]; ///problem here
return ipString;
}
This gives a build error saying both "Dereferencing pointer to incomplete type" and "Implicit declaration of function 'inet_ntoa'" on the same line.
I've checked and I don't think I'm missing some type of framework to get inet_ntoa
to work. Any idea what I'm doing wrong? thanks.