LinuxQuestions.org
Review your favorite Linux distribution.
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 08-03-2011, 06:46 AM   #1
Sekhar417
LQ Newbie
 
Registered: Jul 2011
Posts: 5

Rep: Reputation: Disabled
Sending Ethernet Frames using dev_queue_xmit


Hi,

I have written a sample code to receive and send the Ethernet Packets from/to another machine.

I am able to receive the packet successfully from another machine, but sending packet is not seen on another machine. Even i checked the tcpdump in both machines after sending, i don't see any packet dumps. I even checked the frame drops, but nothing was there.

I am sending the packet the using dev_queue_xmit(skb), with proper dev name setting as eth0.

After receiving the packet, i am just changing the MAC address and sending.

Please correct my code, what is wrong here.

#include <linux/kernel.h>
#include <linux/config.h>
#include <linux/types.h>
#include <linux/sched.h>
#include <linux/mm.h>
#include <linux/fcntl.h>
#include <linux/socket.h>
#include <linux/in.h>
#include <linux/inet.h>
#include <linux/skbuff.h>
#include <linux/if_arp.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>

int mpls_packet_recv (struct sk_buff *skb, struct net_device *dev );

static struct packet_type my_packet_type;

int SendData(struct sk_buff *skb, struct net_device *dev);

/* Recieve Packet */
int mpls_packet_recv (struct sk_buff *skb,
struct net_device *dev);

{
struct sk_buff *sk = skb;
dev = sk->dev;
/* send the Data */
SendData(skb, dev);
return 0;
}
int SendData(struct sk_buff *skb, struct net_device *dev)
{
int ret;
int i;

skb->pkt_type = PACKET_OUTGOING;
skb->dev = dev; //eth0

/*changing Mac address */
unsigned char srcaddr[6];
struct ethhdr *eth = eth_hdr(skb);
memcpy(srcaddr, eth->h_source, ETH_ALEN);
memcpy(eth->h_source, eth->h_dest, ETH_ALEN);
memcpy(eth->h_dest, srcaddr, ETH_ALEN);

/* send the packet */
ret = dev_queue_xmit(skb);
printk(KERN_DEBUG "\ndev_queue_xmit returned %d\n", ret);

return ret;

}
static int __init nf_init(void)
{
my_packet_type.type = htons(ETH_P_ALL);
my_packet_type.func = mpls_packet_recv;
my_packet_type.dev = NULL;
dev_add_pack(&my_packet_type);

return 0;
}
static void __exit nf_exit(void)
{
dev_remove_pack(&my_packet_type);
}


Thanks
--sekhar
 
Old 08-04-2011, 02:55 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
You need to debug deeper. Is the source address the address compatible with the MAC address associated with the interface?
 
Old 05-29-2013, 06:35 PM   #3
lazarobankini
LQ Newbie
 
Registered: Oct 2009
Posts: 3

Rep: Reputation: 0
Have you solved this? i'm having the same problem.. it seems that when i'm using the broadcast address everything is fine, but unicast is not, the receiver does not receive the data... I'm stuck.
 
  


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
Need help with injecting raw ethernet frames using TAP interface knonaka Programming 1 04-29-2010 02:31 AM
why doesn't dev_queue_xmit actually transmit the packet? drblmb Programming 1 09-17-2009 01:05 PM
Ethernet driver - kernel crashes after passing a few Ethernet frames to upper layers AustinMarton Linux - Kernel 0 03-12-2009 06:27 PM
Possible to create a frames effect in an HTML page without using frames? furfurdemon666 General 10 12-12-2004 06:52 AM
ethernet to ethernet frames alaios Linux - Networking 0 08-28-2004 04:32 PM

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

All times are GMT -5. The time now is 10:18 AM.

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