I am receiving a successful connection to the server and i am in my callback function:
I am trying to get the name of the host and print that to my console:
if(theType == kCFSocketConnectCallBack){
NSLog(@"Connection is accepted");
CFSocketNativeHandle nativeSocket = CFSocketGetNative(theSocket);
uint8_t name[SOCK_MAXADDRLEN];
socklen_t namelen = sizeof(name);
NSData *peer = nil;
if (getpeername(nativeSocket, (struct sockaddr *)name, &namelen) == 0) {
peer = [NSData dataWithBytes:name length:namelen];
NSString *string = [[NSString alloc] initWithData:peer encoding:NSUTF8StringEncoding];
NSLog(@"IP adress of connected peer: %@", string);
}
When i run the application in the debug mode i can see the IP address value assigned to name , so it's successful in getting the name , each value is uint8_t.. The peer length is showing me 16; My problem converting it to NSData then NSString...
output: 2010-01-31 13:57:58.671 IP adress of connected peer: (null)
My string is being output as NULL,
Any advise is appreciated, thanks....