Note that there are some explanatory texts on larger screens.

plurals
  1. PORAW Socket - Ethertype and receive's algorithm - C
    primarykey
    data
    text
    <p>I'm working with raw socket in C language. I need to send and to receive a raw ethernet packet. The packet should start with an IEEE 802.3 header:</p> <p><em>MAC DST [0-5] - MAC SRC [6-11] - ETH TYPE[12-13]</em></p> <p>Catching the packets with wireshark I see the following structure:</p> <p><em>MAC DST [0-5] - MAC SRC [6-11] - LENGTH[12-13] - TRAILER[14-58]-....</em></p> <p>This is my code:</p> <pre><code>... sraw = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_802_3)); ... retVal = setsockopt(sraw, SOL_SOCKET, SO_BINDTODEVICE, (void *)&amp;ifr, sizeof(ifr)); ... val = 3; retVal = setsockopt(sraw, SOL_SOCKET, SO_PRIORITY, &amp;val, sizeof (val)); ... memcpy(ptr_eth_header-&gt;DstMac, dst_mac, 6); memcpy(ptr_eth_header-&gt;SrcMac, src_mac, 6); ptr_eth_header-&gt;Type = htons(ETH_P_802_3); memcpy(buffer + ETHHDR_SIZE, data, 60); ... sockaddr.sll_family = htons(PF_PACKET); sockaddr.sll_protocol = htons(ETH_P_802_3); sockaddr.sll_ifindex = ifr.ifr_ifru.ifru_ivalue; sockaddr.sll_halen = 6; memcpy(&amp;(sockaddr.sll_addr), dst_mac, 6); ... bytes = sendto(sraw, buffer, sizeof(buffer), 0, (struct sockaddr *) &amp;(sockaddr), sizeof (struct sockaddr_ll)); </code></pre> <p>Is it just a wireshark's "problem"? Any ideas?</p> <p>My second problem is about the receipt of the raw messages. The process is stuck on the recvfrom.</p> <p>This is my code:</p> <pre><code>sraw = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_802_3)); ... retVal = setsockopt(sraw, SOL_SOCKET, SO_BINDTODEVICE, (void *)&amp;ifr, sizeof(ifr)); ... val = 3; retVal = setsockopt(sraw, SOL_SOCKET, SO_PRIORITY, &amp;val, sizeof (val)); ... val = CLIENT_PACKET_SIZE; retVal = setsockopt(sraw, SOL_SOCKET, SO_RCVBUF, &amp;val, sizeof (val)); sockaddr.sll_family = htons(PF_PACKET); sockaddr.sll_ifindex = ifr.ifr_ifindex; sockaddr.sll_protocol = htons(ETH_P_802_3); buffer = malloc(CLIENT_PACKET_SIZE * sizeof(char)); while (count &lt; PACKET_COUNT) { bytes = recvfrom(sraw, buffer, CLIENT_PACKET_SIZE, 0, (struct sockaddr *)&amp;sockaddr, (socklen_t*)sizeof(sockaddr)); ... } </code></pre> <p>Could you help me?</p> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload