CFSocketNativeHandle native;
CFDataRef nativeProp = CFReadStreamCopyProperty(readStream, kCFStreamPropertySocketNativeHandle);
if(nativeProp == NULL)
{
NSLog(@"error");
}
CFDataGetBytes(nativeProp, CFRangeMake(0, CFDataGetLength(nativeProp)), (UInt8 *)&native);
CFRelease(nativeProp);
CFSocketRef distantSocket = CFSocketCreateWithNative(kCFAllocatorDefault, native, 0, NULL, NULL);
CFDataRef distaddr = CFSocketCopyPeerAddress(distantSocket);
struct sockaddr *pSockAddr = (struct sockaddr *) CFDataGetBytePtr(distaddr);
struct sockaddr_in *pSockAddrV4 = (struct sockaddr_in *) pSockAddr;
struct sockaddr_in6 *pSockAddrV6 = (struct sockaddr_in6 *)pSockAddr;
const void *pAddr = (pSockAddr->sa_family == AF_INET) ? (void *)(&(pSockAddrV4->sin_addr)) :(void *)(&(pSockAddrV6->sin6_addr));
char addrBuf[ MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN) ];
const char *pStr = inet_ntop (pSockAddr->sa_family, pAddr, addrBuf, sizeof(addrBuf));
This code compiles fine, but crashes on the CFDataGetBytes call and I get the error message "Variable is not a CFData at this time" for variable nativeProp.
In the code, distantHost is an NSString containing either a FQDN, an IPv4 or IPv6 (for exemple: "www.google.com"). Further in the code, I am able to read from the readStream, so I don't think the readStream is the problem. Am I wrong? I am completely clueless!
Thanks a Lot,