LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 02-17-2012, 01:49 PM   #1
karan2386
Member
 
Registered: Jan 2012
Posts: 34

Rep: Reputation: Disabled
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
 
Old 02-18-2012, 03:36 AM   #2
eeekster
Member
 
Registered: Sep 2011
Posts: 163

Rep: Reputation: Disabled
You can use tcpdump to see if the packet is being sent.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ping - Packet FIltered pembo13 Linux - Networking 3 06-25-2010 11:24 AM
madwifi ping packet loss preacher.ca Linux - Wireless Networking 3 02-03-2006 01:21 PM
ping packet loss 100% kpachopoulos Linux - Networking 1 04-14-2005 05:29 PM
Duplicate (DUP)! ping packet cause mattsin Linux - Networking 0 10-17-2003 05:04 PM
Packet filtered can't ping henrymaher Linux - Networking 2 01-04-2002 09:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 08:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration