<div dir="ltr">Thank you. I make a error with &quot;<span style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:14px">tot_len</span>&quot;.</div><div class="gmail_extra"><br><div class="gmail_quote">2014-09-16 23:05 GMT+08:00 ankur dwivedi <span dir="ltr">&lt;<a href="mailto:ankurengg2003@gmail.com" target="_blank">ankurengg2003@gmail.com</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>What is getting shown in tcpdump?<br><br></div>I guess its a checksum problem.<br></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Sun, Sep 7, 2014 at 2:42 PM, lx <span dir="ltr">&lt;<a href="mailto:lxlenovostar@gmail.com" target="_blank">lxlenovostar@gmail.com</a>&gt;</span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">hi all:<div>      I want to send a udp packet in kernel module. the codes is:</div><div>####################################################</div><div><div>                       /*</div><div><span style="white-space:pre-wrap">                        </span>* send UDP packet </div><div><span style="white-space:pre-wrap">                        </span>*/</div><div><span style="white-space:pre-wrap">                        </span>char *dest_addr = &quot;192.168.109.176&quot;;</div><div><span style="white-space:pre-wrap">                        </span>int eth_len, udph_len, iph_len, len;</div><div><span style="white-space:pre-wrap">                        </span>eth_len = sizeof(struct ethhdr);</div><div><span style="white-space:pre-wrap">                        </span>iph_len = sizeof(struct iphdr);</div><div><span style="white-space:pre-wrap">                        </span>udph_len  = sizeof(struct udphdr);</div><div><span style="white-space:pre-wrap">                        </span>len<span style="white-space:pre-wrap">        </span>= eth_len + iph_len + udph_len;</div><div><br></div><div><span style="white-space:pre-wrap">                        </span>struct sk_buff *send_skb = alloc_skb(len, GFP_ATOMIC);</div><div><span style="white-space:pre-wrap">                        </span>if (!send_skb)</div><div><span style="white-space:pre-wrap">                                </span>return NF_DROP;</div><div><br></div><div><span style="white-space:pre-wrap">                        </span>//skb_put(send_skb, len);</div><div><span style="white-space:pre-wrap">                        </span>skb_reserve(send_skb, len);</div><div><span style="white-space:pre-wrap">                        </span> </div><div><span style="white-space:pre-wrap">                        </span>skb_push(send_skb, sizeof(struct udphdr));</div><div><span style="white-space:pre-wrap">                        </span> </div><div><span style="white-space:pre-wrap">                        </span>skb_reset_transport_header(send_skb);</div><div><span style="white-space:pre-wrap">                        </span></div><div><span style="white-space:pre-wrap">                        </span>udph = udp_hdr(send_skb);</div><div><span style="white-space:pre-wrap">                        </span>udph-&gt;source = dport;</div><div><span style="white-space:pre-wrap">                        </span>udph-&gt;dest = dport;</div><div><span style="white-space:pre-wrap">                        </span>udph-&gt;len = htons(udph_len);</div><div><span style="white-space:pre-wrap">                        </span>udph-&gt;check = 0;</div><div><span style="white-space:pre-wrap">                        </span>udph-&gt;check = csum_tcpudp_magic(daddr, in_aton(dest_addr), udph_len, IPPROTO_UDP, csum_partial(udph, udph_len, 0));</div><div><span style="white-space:pre-wrap">                                </span></div><div><span style="white-space:pre-wrap">                        </span>//if (udph-&gt;check == 0)</div><div><span style="white-space:pre-wrap">                        </span>//<span style="white-space:pre-wrap">        </span>udph-&gt;check = CSUM_MANGLED_0;</div><div><br></div><div><span style="white-space:pre-wrap">                        </span>skb_push(send_skb, sizeof(struct iphdr));</div><div><span style="white-space:pre-wrap">                        </span>skb_reset_network_header(send_skb);</div><div><span style="white-space:pre-wrap">                        </span>send_iph = ip_hdr(send_skb);</div><div><br></div><div><span style="white-space:pre-wrap">                        </span>// iph-&gt;version = 4; iph-&gt;ihl = 5; </div><div><span style="white-space:pre-wrap">                        </span>put_unaligned(0x45, (unsigned char *)send_iph);</div><div><span style="white-space:pre-wrap">                        </span>send_iph-&gt;tos      = 0;</div><div><span style="white-space:pre-wrap">                        </span>put_unaligned(htons(iph_len), &amp;(send_iph-&gt;tot_len));</div><div><span style="white-space:pre-wrap">                        </span>//send_iph-&gt;id       = htons(atomic_inc_return(&amp;ip_ident));</div><div><span style="white-space:pre-wrap">                        </span>send_iph-&gt;id       = 0;</div><div><span style="white-space:pre-wrap">                        </span>send_iph-&gt;frag_off = 0;</div><div><span style="white-space:pre-wrap">                        </span>send_iph-&gt;ttl      = 64;</div><div><span style="white-space:pre-wrap">                        </span>send_iph-&gt;protocol = IPPROTO_UDP;</div><div><span style="white-space:pre-wrap">                        </span>send_iph-&gt;check    = 0;</div><div><span style="white-space:pre-wrap">                        </span>put_unaligned(daddr, &amp;(send_iph-&gt;saddr));</div><div><span style="white-space:pre-wrap">                        </span>put_unaligned(in_aton(dest_addr), &amp;(send_iph-&gt;daddr));</div><div><span style="white-space:pre-wrap">                        </span>send_iph-&gt;check    = ip_fast_csum((unsigned char *)send_iph, send_iph-&gt;ihl);</div><div><span style="white-space:pre-wrap">                        </span>  </div><div><span style="white-space:pre-wrap">                        </span>eth = (struct ethhdr *) skb_push(send_skb, ETH_HLEN);</div><div><span style="white-space:pre-wrap">                        </span>skb_reset_mac_header(send_skb);</div><div><span style="white-space:pre-wrap">                        </span>send_skb-&gt;protocol = eth-&gt;h_proto = htons(ETH_P_IP);</div><div><span style="white-space:pre-wrap">                        </span>memcpy(eth-&gt;h_source, dev-&gt;dev_addr, ETH_ALEN);</div><div><span style="white-space:pre-wrap">                        </span>memcpy(eth-&gt;h_dest, &quot;00:0C:29:DC:2D:F5&quot;, ETH_ALEN);</div><div><br></div><div><span style="white-space:pre-wrap">                        </span>send_skb-&gt;dev = dev;</div><div><span style="white-space:pre-wrap">                        </span>dev_queue_xmit(send_skb);</div></div><div>#################################################### </div><div><br></div><div>I think the udp packe is sent,but the wirshark detect this packet is error. </div><div>The Error message is:</div><div>####################################################</div><div><img src="cid:ii_hzs5wca70_1484f6280f1c6631" height="339" width="562"><br>​<br></div><div>####################################################</div><div><br></div><div>Tell me how to debug it? I&#39;m a new one, </div><div>Thank you.</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div>
<br></div></div>_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org" target="_blank">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
<br></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><br>-- <br><br> <br>-- <br>                  <br>ankur dwivedi<br><a href="http://about.me/ankur_dwivedi" target="_blank">http://about.me/ankur_dwivedi</a><br> <br>
</font></span></div>
</blockquote></div><br></div>