<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 class="" style="white-space:pre">                        </span>* send UDP packet </div><div><span class="" style="white-space:pre">                        </span>*/</div><div><span class="" style="white-space:pre">                        </span>char *dest_addr = &quot;192.168.109.176&quot;;</div><div><span class="" style="white-space:pre">                        </span>int eth_len, udph_len, iph_len, len;</div><div><span class="" style="white-space:pre">                        </span>eth_len = sizeof(struct ethhdr);</div><div><span class="" style="white-space:pre">                        </span>iph_len = sizeof(struct iphdr);</div><div><span class="" style="white-space:pre">                        </span>udph_len  = sizeof(struct udphdr);</div><div><span class="" style="white-space:pre">                        </span>len<span class="" style="white-space:pre">        </span>= eth_len + iph_len + udph_len;</div><div><br></div><div><span class="" style="white-space:pre">                        </span>struct sk_buff *send_skb = alloc_skb(len, GFP_ATOMIC);</div><div><span class="" style="white-space:pre">                        </span>if (!send_skb)</div><div><span class="" style="white-space:pre">                                </span>return NF_DROP;</div><div><br></div><div><span class="" style="white-space:pre">                        </span>//skb_put(send_skb, len);</div><div><span class="" style="white-space:pre">                        </span>skb_reserve(send_skb, len);</div><div><span class="" style="white-space:pre">                        </span> </div><div><span class="" style="white-space:pre">                        </span>skb_push(send_skb, sizeof(struct udphdr));</div><div><span class="" style="white-space:pre">                        </span> </div><div><span class="" style="white-space:pre">                        </span>skb_reset_transport_header(send_skb);</div><div><span class="" style="white-space:pre">                        </span></div><div><span class="" style="white-space:pre">                        </span>udph = udp_hdr(send_skb);</div><div><span class="" style="white-space:pre">                        </span>udph-&gt;source = dport;</div><div><span class="" style="white-space:pre">                        </span>udph-&gt;dest = dport;</div><div><span class="" style="white-space:pre">                        </span>udph-&gt;len = htons(udph_len);</div><div><span class="" style="white-space:pre">                        </span>udph-&gt;check = 0;</div><div><span class="" style="white-space:pre">                        </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 class="" style="white-space:pre">                                </span></div><div><span class="" style="white-space:pre">                        </span>//if (udph-&gt;check == 0)</div><div><span class="" style="white-space:pre">                        </span>//<span class="" style="white-space:pre">        </span>udph-&gt;check = CSUM_MANGLED_0;</div><div><br></div><div><span class="" style="white-space:pre">                        </span>skb_push(send_skb, sizeof(struct iphdr));</div><div><span class="" style="white-space:pre">                        </span>skb_reset_network_header(send_skb);</div><div><span class="" style="white-space:pre">                        </span>send_iph = ip_hdr(send_skb);</div><div><br></div><div><span class="" style="white-space:pre">                        </span>// iph-&gt;version = 4; iph-&gt;ihl = 5; </div><div><span class="" style="white-space:pre">                        </span>put_unaligned(0x45, (unsigned char *)send_iph);</div><div><span class="" style="white-space:pre">                        </span>send_iph-&gt;tos      = 0;</div><div><span class="" style="white-space:pre">                        </span>put_unaligned(htons(iph_len), &amp;(send_iph-&gt;tot_len));</div><div><span class="" style="white-space:pre">                        </span>//send_iph-&gt;id       = htons(atomic_inc_return(&amp;ip_ident));</div><div><span class="" style="white-space:pre">                        </span>send_iph-&gt;id       = 0;</div><div><span class="" style="white-space:pre">                        </span>send_iph-&gt;frag_off = 0;</div><div><span class="" style="white-space:pre">                        </span>send_iph-&gt;ttl      = 64;</div><div><span class="" style="white-space:pre">                        </span>send_iph-&gt;protocol = IPPROTO_UDP;</div><div><span class="" style="white-space:pre">                        </span>send_iph-&gt;check    = 0;</div><div><span class="" style="white-space:pre">                        </span>put_unaligned(daddr, &amp;(send_iph-&gt;saddr));</div><div><span class="" style="white-space:pre">                        </span>put_unaligned(in_aton(dest_addr), &amp;(send_iph-&gt;daddr));</div><div><span class="" style="white-space:pre">                        </span>send_iph-&gt;check    = ip_fast_csum((unsigned char *)send_iph, send_iph-&gt;ihl);</div><div><span class="" style="white-space:pre">                        </span>  </div><div><span class="" style="white-space:pre">                        </span>eth = (struct ethhdr *) skb_push(send_skb, ETH_HLEN);</div><div><span class="" style="white-space:pre">                        </span>skb_reset_mac_header(send_skb);</div><div><span class="" style="white-space:pre">                        </span>send_skb-&gt;protocol = eth-&gt;h_proto = htons(ETH_P_IP);</div><div><span class="" style="white-space:pre">                        </span>memcpy(eth-&gt;h_source, dev-&gt;dev_addr, ETH_ALEN);</div><div><span class="" style="white-space:pre">                        </span>memcpy(eth-&gt;h_dest, &quot;00:0C:29:DC:2D:F5&quot;, ETH_ALEN);</div><div><br></div><div><span class="" style="white-space:pre">                        </span>send_skb-&gt;dev = dev;</div><div><span class="" style="white-space:pre">                        </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" width="562" height="339"><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>