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

  • SEARCH
  • Home
  • 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 8866367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:46:02+00:00 2026-06-14T16:46:02+00:00

im stuck with sending a raw ethernet frame. [edit] I found some errors. 1.

  • 0

im stuck with sending a raw ethernet frame.

[edit]
I found some errors.
1. It has to be AF_PACKET in the socket call.
2. AF_PACKET doesnt have an option SOCK_PACKET, but SOCK_DGRAM and SOCK_RAW

With SOCK_DGRAM wireshark captures a malformed LLC packet.
But with SOCK_RAW no error message and no captured packet.

i dont find whats really going wrong.
[/edit]

the code:

if ((ethernet_socket = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) == -1)
    cout << "Ethernet Socket: "<< strerror(errno) << endl;

struct sockaddr_ll socket_address;
socket_address.sll_family   = PF_PACKET;
socket_address.sll_protocol = htons(ETH_P_IP);
socket_address.sll_ifindex=if_nametoindex("eth0");
socket_address.sll_hatype   = 1; // ARPHRD_ETHER
socket_address.sll_pkttype  = PACKET_OTHERHOST;
socket_address.sll_halen    = ETH_ALEN;
memcpy(socket_address.sll_addr,dest_mac_addr,ETH_ALEN);

int send_result = 0;

char *opt=(char*)malloc(4*sizeof(char));
strcpy(opt,"eth0");

if(setsockopt(ethernet_socket, SOL_SOCKET, SO_BINDTODEVICE, opt, 4)==-1)
    cout << "Could not bind socket to device: " << strerror(errno) << endl;

if ((send_result  
= sendto(ethernet_socket, &buffer, sizeof(buffer), 0,  
    (struct sockaddr*)&socket_address, sizeof(socket_address)))==-1){
        cout << "sendto error: "<< strerror(errno) << endl;
        return send_result;
}

regards
Ck

  • 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-06-14T16:46:03+00:00Added an answer on June 14, 2026 at 4:46 pm

    I found the solution how this works.
    i took a look at the source code of the Linux program PackEth.

    the following code works for me.

    if ((ethernet_socket = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) == -1)
        cout << "Ethernet Socket: "<< strerror(errno) << endl;  //errorhandling
    
    memset(&ifr, 0, sizeof(ifr));
    strncpy (ifr.ifr_name, "eth0", sizeof(ifr.ifr_name) - 1);
    ifr.ifr_name[sizeof(ifr.ifr_name)-1] = '\0';
    
    
    if (ioctl(ethernet_socket, SIOCGIFINDEX, &ifr) == -1) {
        cout << "No such interface:"<< strerror(errno) << endl;
        close(ethernet_socket);
    }
    
    ioctl(ethernet_socket, SIOCGIFFLAGS, &ifr);
    if ( (ifr.ifr_flags & 0x1) == 0) {
        cout << "Interface is down: "<< strerror(errno) << endl;
        close(ethernet_socket);
    }
    
    ioctl(ethernet_socket, SIOCGIFINDEX, &ifr);
    
    
    memset(&socket_address, 0, sizeof (socket_address));
    socket_address.sll_family    = AF_PACKET;
    socket_address.sll_ifindex   = ifr.ifr_ifindex;
    socket_address.sll_protocol  = htons(ETH_P_ALL);
    
    if ((raw_send = sendto(ethernet_socket, buffer, size_payload+14,0,(struct     sockaddr*)     
                               &socket_address, sizeof(socket_address)))==-1){
        cout << "sendto error: "<< strerror(errno) << endl;
        return raw_send;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm quite stuck with a problem sending mail from a PHP script. Some data:
I am new to android programming and have found myself stuck I have been
I'm creating a used cars website (written in PHP), and I'm stuck on sending
Been stuck on this for ages. Currently learning Django and done some bits on
Kinda stuck here... I have an application with lets say 5000 rows of data
i managed to send multiple emails ( check here ).i am stuck with sending
while being stuck in some c**p SM code I ended up wondering is there
Im stuck with a ajax function im creating. Here is the deal, I have
I just got stuck. I have 2 view controllers one is WatchListViewController and 2nd
I have been stuck with this prolem for the past 5 hours or so..

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.