<div dir="ltr">Thank you. I make a error with "<span style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:14px">tot_len</span>".</div><div class="gmail_extra"><br><div class="gmail_quote">2014-09-16 23:05 GMT+08:00 ankur dwivedi <span dir="ltr"><<a href="mailto:ankurengg2003@gmail.com" target="_blank">ankurengg2003@gmail.com</a>></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"><<a href="mailto:lxlenovostar@gmail.com" target="_blank">lxlenovostar@gmail.com</a>></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 = "192.168.109.176";</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->source = dport;</div><div><span style="white-space:pre-wrap">                        </span>udph->dest = dport;</div><div><span style="white-space:pre-wrap">                        </span>udph->len = htons(udph_len);</div><div><span style="white-space:pre-wrap">                        </span>udph->check = 0;</div><div><span style="white-space:pre-wrap">                        </span>udph->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->check == 0)</div><div><span style="white-space:pre-wrap">                        </span>//<span style="white-space:pre-wrap">        </span>udph->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->version = 4; iph->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->tos = 0;</div><div><span style="white-space:pre-wrap">                        </span>put_unaligned(htons(iph_len), &(send_iph->tot_len));</div><div><span style="white-space:pre-wrap">                        </span>//send_iph->id = htons(atomic_inc_return(&ip_ident));</div><div><span style="white-space:pre-wrap">                        </span>send_iph->id = 0;</div><div><span style="white-space:pre-wrap">                        </span>send_iph->frag_off = 0;</div><div><span style="white-space:pre-wrap">                        </span>send_iph->ttl = 64;</div><div><span style="white-space:pre-wrap">                        </span>send_iph->protocol = IPPROTO_UDP;</div><div><span style="white-space:pre-wrap">                        </span>send_iph->check = 0;</div><div><span style="white-space:pre-wrap">                        </span>put_unaligned(daddr, &(send_iph->saddr));</div><div><span style="white-space:pre-wrap">                        </span>put_unaligned(in_aton(dest_addr), &(send_iph->daddr));</div><div><span style="white-space:pre-wrap">                        </span>send_iph->check = ip_fast_csum((unsigned char *)send_iph, send_iph->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->protocol = eth->h_proto = htons(ETH_P_IP);</div><div><span style="white-space:pre-wrap">                        </span>memcpy(eth->h_source, dev->dev_addr, ETH_ALEN);</div><div><span style="white-space:pre-wrap">                        </span>memcpy(eth->h_dest, "00:0C:29:DC:2D:F5", ETH_ALEN);</div><div><br></div><div><span style="white-space:pre-wrap">                        </span>send_skb->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'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>