Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6174789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:48:38+00:00 2026-05-23T23:48:38+00:00

I am a complete newbie to networking, however I am a c/c++ programmer, and

  • 0

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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:48:39+00:00Added an answer on May 23, 2026 at 11:48 pm

    Your problem is very simple: you are not telling the CFSocket where you want it to send the data.

    You carefully construct an address in addr, but then don’t use it. You either need to call CFSocketSetAddress to set the destination address on the socket (if you want all packets you send to go to the same destination), or pass the address as the 2nd argument to CFSocketSendData.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a complete newbie at Haskell. I'm trying to compile this Haskell file I've
I'm a complete newbie to Django. I've been trying to get it working on
I'm a complete Xcode/Objective-C/Cocoa newbie but I'm learning fast and really starting to enjoy
I'm a complete newbie in OCaml and trying to create a simple console program.
I am a complete newbie in working with a Ruby on Rails (RoR) application.
I'm a complete newbie to Windows and COM programming, trying to use com4j in
I'm a complete newbie to Objective-C/XCode and it's been a bit daunting so far.
I'm a complete newbie to Objective-C, coming from a background of PHP, assorted dialects
I'm really new at network-programming, so I hope this isn't a complete Newbie-question. I
I'm a complete newbie to C# so excuse me if this looks weird. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.