Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A couple of things to get your packets on the wire/air.</p> <ul> <li>The proper .sll_protocol for the arp reply is ETH_P_ARP, from <code>&lt;linux/if_ether.h&gt;</code></li> <li><p>There was an error in endianness when setting ah->arp_op. It is a network byteorder field of 2 octets, so use htons().</p></li> <li><p>In general, the code is a little confused about network and host byteorder. It currently sends out the reply very mangled, but it is unclear to me whether that is the malicious intent of the code, or an accident. In the case that you want to send real, correct IP addresses, use htonl and htons, when building the reply.</p></li> </ul> <p>To fix endianness:</p> <ul> <li>Properly include <code>&lt;arpa/inet.h&gt;</code></li> <li>Use htons(), htonl() ntohs() and ntohl(), always. Their implementation makes it a NOP, if its not needed on your platform.</li> <li>When setting up data to be sent out from host, always process it with hton*()</li> <li>When interpreting data from the network, always ntoh*() it before comparing with local variables.</li> </ul> <p>In summary, the changes I did were 1) .sll_protocol = htons(ETH_P_ARP). (when sending data) 2) ah->arp_op = htons(ARPOP_REPLY) (in the reply arp) 3) Removed the nonsensical ntohs() on ah->arp_hd and ah->arp_pr. You dont want to convert data to host byteorder when populating the send buffer (unless you really really actually do) 4) Added ntohs() conversions and proper defines in some of the comparisons 5) some other small fixes 6) disabled the bit doing system("sudo...")!</p> <p>Full code at <a href="http://pastebin.com/9Udd0uH7" rel="nofollow">pastebin</a>. Here is a diff:</p> <pre><code>thuovila@glx:~/src/so/arp$ diff arp2.c arp_orig.c 13d12 &lt; #include &lt;arpa/inet.h&gt; 20c19 &lt; #define DEVICE "eth1" --- &gt; #define DEVICE "eth0" 25c24 &lt; int s = -1; /*Socketdescriptor*/ --- &gt; int s = 0; /*Socketdescriptor*/ 92c91 &lt; socket_address.sll_protocol = htons(ETH_P_ARP); --- &gt; socket_address.sll_protocol = htons(ETH_P_IP); 95c94 &lt; socket_address.sll_pkttype = 0; //PACKET_OTHERHOST; --- &gt; socket_address.sll_pkttype = PACKET_OTHERHOST; 112c111 &lt; if(ntohs(eh-&gt;h_proto) == ETH_P_ARP) --- &gt; if(htons(eh-&gt;h_proto) == 0x806) 119c118 &lt; if(ntohs(ah-&gt;arp_op) != ARPOP_REQUEST) --- &gt; if(htons(ah-&gt;arp_op) != 0x0001) 139d137 &lt; #if 0 145d142 &lt; #endif 182c179 &lt; eh-&gt;h_proto = htons(ETH_P_ARP); --- &gt; eh-&gt;h_proto = ETH_ARP; 200,201c197,198 &lt; //ah-&gt;arp_hd = ntohs(ah-&gt;arp_hd); &lt; //ah-&gt;arp_pr = ntohs(ah-&gt;arp_pr); --- &gt; ah-&gt;arp_hd = ntohs(ah-&gt;arp_hd); &gt; ah-&gt;arp_pr = ntohs(ah-&gt;arp_pr); 203c200 &lt; ah-&gt;arp_op = htons(ARPOP_REPLY); --- &gt; ah-&gt;arp_op = 0x0002; </code></pre> <p><strong>EDIT</strong> Some wireshark advice. Capture <em>ether proto 0x0806</em> (or <em>arp</em> for short). Use the pseudo device that captures any packets. Your packets should become visible.</p> <p>On linux, if you want to stop the network stack from interfering, use: echo "8" > /proc/sys/net/ipv4/conf/all/arp_ignore</p> <p><strong>EDIT #2</strong> I am not completely sure about the ETH_P_ARP. It might have been a snap judgement on my part. Using ETH_P_IP is correct in the ARP header field, but Im not sure which one to use for the packet socket sll_protocol. Also notice that <code>socket_address.sll_pkttype = PACKET_OTHERHOST;</code>has no effect when sending (see man 7 packet). Also the mandatory SO observation, that you should always use <strong>at least</strong> -Wall (when using gcc or clang) as a compilation flag. </p> <p><strong>EDIT #3</strong> I changed the program a little more. and updated the answer and diff accordingly. Surprisingly it does indeed seem, that .sll_protocol needs to be ETH_P_ARP. My copy of the <em>man 7 packet</em> doesnt even say it is used for anything, but the packet doesnt go out on the wire as ARP without it.</p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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