Skip to content

Instantly share code, notes, and snippets.

@phucnm
Created March 4, 2016 04:05
Show Gist options
  • Save phucnm/712faf4584c5baa9a84f to your computer and use it in GitHub Desktop.
Save phucnm/712faf4584c5baa9a84f to your computer and use it in GitHub Desktop.
Get IP NSString from address data in iOS
#include <arpa/inet.h>
- (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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment