how to send a ping packet
i have made a module which aims to send the ping packet using ioctl command from user space(application). however i am not sure whether its sending a ping packet or not because when i try to recieve a packet thru hook function there is no reply to it. i am sending the ping packet to router(192.168.1.1).following is my code its compiling and running w/o errors:
int device_ioctl(struct net_device *dev,struct ifreq *ifr, int cmd) { int len; //printk("%s , %d",__func__,__LINE__); switch(cmd) { case SIOCDEVPRIVATE: printk("here it is : %s: %d\n",__func__,__LINE__); break; case WLAN_TRANSMIT : icmp.type = ICMP_ECHO; icmp.code = 0; icmp.un.echo.sequence = i++; icmp.un.echo.id = current->pid & 0xFFFF; printk(KERN_ALERT"ID::%X\n",icmp.un.echo.id); ip4.protocol = 0x01; //for icmp protocol ip4.tos = 0x00; ip4.frag_off = 0; ip4.daddr = in_aton(procfs_buffer); ip4.saddr = in_aton(ifr->ifr_addr.sa_data); len = sizeof(data); skb = dev_alloc_skb(1500); skb->dev = __dev_get_by_name(&init_net,"wlan0"); skb_reserve(skb,NET_IP_ALIGN); //header of 2 bytes; increments tail and data pointer skb->data = skb_put(skb,sizeof(len)); // increments all pointer or adds data memcpy(data,skb->data,len); wdev = skb->dev; skb->transport_header =skb_push(skb,sizeof(icmp)); memset(skb->transport_header,0,sizeof(struct icmphdr)); memcpy(skb->transport_header,&icmp,sizeof(struct icmphdr)); skb->network_header=skb_push(skb,sizeof(ip4)); memset(skb->network_header,0,sizeof(struct iphdr)); memcpy(skb->network_header,&ip4,sizeof(struct iphdr)); // printk("i::%d\n",i); // skb->mac_header = skb_push(skb,6*sizeof(0xFF)); // memset(skb->mac_header,0xFF,6*sizeof(0xFF)); dev_queue_xmit(skb); // kfree(skb); } return 0; } unsigned int hook_func(unsigned int hooknum, struct sk_buff *skb1, const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff *)) { struct sk_buff *sock_buff; struct iphdr *ip1; struct icmphdr *icmp1; sock_buff = skb1; //printk("ihere we are::%s,%d\n",__func__,__LINE__); ip1 = (struct iphdr *)skb_network_header(sock_buff); //printk(KERN_ALERT"proto:%d,addr:%X::%X\n",ip1->protocol,ip1->saddr,ip1->daddr); if(ip1->protocol==1) { printk(KERN_ALERT"proto:%d,addr:%X::%X\n",ip1->protocol,ip1->saddr,ip1->daddr); icmp1 = (struct icmphdr *)skb_transport_header(sock_buff); printk(KERN_ALERT"reply type: %c,,seq : %04X\n",icmp1->type,icmp1->un.echo.id); } // kfree(sock_buff); return NF_ACCEPT; } hook function is working fine but not sure how to send a ping packet(in doubt because not getting a reply packet). regards karan |
You can use tcpdump to see if the packet is being sent.
|
All times are GMT -5. The time now is 05:02 PM. |