Help creating CFSocket
Help creating CFSocket
- Subject: Help creating CFSocket
- From: Rick Mann <email@hidden>
- Date: Tue, 26 Oct 2010 02:17:53 -0700
Hi. I'm trying to create a CFSocket, but I'm getting back NULL. errno is 49, which I take to be EADDRNOTAVAIL. The address I'm getting back is valid.
Any ideas? TIA!
- (bool)
computeOffsetWithAddress: (NSData*) inAddrData
{
struct sockaddr_storage addr = { 0 };
struct sockaddr_in* addr4 = (struct sockaddr_in*) &addr;
//struct sockaddr_in6* addr6 = (struct sockaddr_in6*) &addr;
NSAssert(inAddrData.length <= sizeof(addr), @"Address supplied larger than sockaddr");
[inAddrData getBytes: &addr length: inAddrData.length];
uint8_t* addrBytes = (uint8_t*) &addr4->sin_addr.s_addr;
NSLog(@"Got addr: %u.%u.%u.%u", addrBytes[0], addrBytes[1], addrBytes[2], addrBytes[3]);
// Create a CFSocket and connect it to the supplied IP…
CFSocketSignature sig = { 0 };
sig.protocolFamily = PF_INET;
sig.socketType = SOCK_DGRAM;
sig.protocol = IPPROTO_UDP;
NSData* addrData = [NSData dataWithBytes: addr4 length: addr4->sin_len];
addr4->sin_port = 123;
sig.address = (CFDataRef) addrData;
CFSocketContext ctx = { 0 };
ctx.info = self;
mSocket = CFSocketCreateConnectedToSocketSignature(kCFAllocatorDefault,
&sig,
kCFSocketDataCallBack,
socketCallback,
&ctx,
30.0);
mNumOffsets = 0;
[self getOffset];
return false;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden