I am a complete newbie to networking, however I am a c/c++ programmer, and am working in objective-c (This is for OSX/iPhone).
I am trying to learn how to send a magic packet with a UDP socket using cfsocket. I've seen there are libraries such as AsyncUDPSocket library, however I do not want to use these.
I attempted to look at apples UDPecho file but, as a beginner it did confuse me. I've googled around ALOT, and I have put together the code below, I have a packet sniffer running and it doesn't register anything being sent. I understand my code is missing alot of error catching, however I am just trying to get the basics in first.
Is this code right? (apologies if this seams ambiguous) What I mean is am I missing certain stages of the code such as: CFSocketSetAddress?
If anyone knows any really good tutorials it would help.
Any help is greatly appreciated, as I am a complete beginner at this.
Thanks
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
CFSocketRef WOLsocket;
WOLsocket = CFSocketCreate(kCFAllocatorDefault, PF_INET, SOCK_DGRAM, IPPROTO_UDP, 0, NULL, NULL);
if ( socket == NULL) {
NSLog(@"CfSocketCreate Failed");
}else{
if( socket ) {
NSLog(@"Socket created :)");
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_len = sizeof(addr);
addr.sin_family = AF_INET;
addr.sin_port = htons(9); //port
inet_aton("255.255.255.255", &addr.sin_addr); //ip adress
char ethadd []= "helloworld";
CFDataRef Data = CFDataCreate(NULL, (const UInt8*)ethadd, sizeof(ethadd));
CFSocketSendData(socket,NULL, Data, 0);}
}
[pool drain];
return 0;
}