LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-26-2010, 02:57 PM   #1
knonaka
LQ Newbie
 
Registered: Apr 2010
Posts: 4

Rep: Reputation: 0
Need help with injecting raw ethernet frames using TAP interface


Hi all, I have UDP packets generated on Machine A that are addressed to Machine B (unicast) that I capture with PCAP. After transporting this raw data to Machine B (via RF modem) I'm trying to reinject the original UDP on Machine B through a tap0 interface. The capture and transport are all working fine. BUT once on the destination machine, the reinjected ethernet packets are NOT being received by a local UDP server. this is my socket creation (removed error checking for brevity) :

Code:
   outputSocket = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));

   struct ifreq s_ifr;
   strcpy(s_ifr.ifr_name, "tap0");

   // get interface index of interface
   ioctl(outputSocket, SIOCGIFINDEX, &s_ifr);

   struct sockaddr_ll outputServer;
   memset(&outputServer, 0, sizeof (struct sockaddr_ll));

   outputServer.sll_family = AF_PACKET;
   outputServer.sll_protocol = htons(ETH_P_ALL);
   outputServer.sll_ifindex = s_ifr.ifr_ifindex;
   outputServer.sll_halen = ETH_ALEN;  // 6

   // is this needed for writing RAW ethernet out, even as client???
   bind(outputSocket, (struct sockaddr *) & outputServer, sizeof (outputServer));
and this is how I'm writing the byte array to the tap interface :

Code:
   int bytesSent = 0;
   bytesSent = write(outputSocket, (const void *) data, dataSize);

   fprintf(stderr, "sent %d bytes to network\n", bytesSent);
"data" is an unsigned char array that contains the original packet data received from pcap, which includes the ethernet header, ip header, udp header, and payload data.

after the call to write() completes, Wireshark on Machine B sees a correctly formatted (checksums and all) UDP packet when listening to tap0 - ie. no lines highlighted in red. *BUT* - a UDP server i have running on Machine B never receives the reinjected UDP datagram. (I have verified that this server works, by using a simple local udp generator app.)

is there something wrong with how I'm creating the socket and/or writing the data back out to the tap0?

Thanks in advance!
Keith
 
Old 04-29-2010, 02:31 AM   #2
TimothyEBaldwin
Member
 
Registered: Mar 2009
Posts: 249

Rep: Reputation: 27
You have it backwards - you should not be using a socket. Read the tutorial at: http://backreference.org/2010/03/26/...face-tutorial/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
RAW receive Socket also delivers sent frames baddad Programming 22 11-27-2013 12:44 PM
Receive Ethernet VLAN frame on the native ethernet interface (raw packet socket) scottbiker Linux - Networking 0 07-13-2009 03:49 AM
Bridge between ethernet interface and tap interface jayadhanesh Linux - Networking 3 04-12-2009 11:32 PM
Ethernet driver - kernel crashes after passing a few Ethernet frames to upper layers AustinMarton Linux - Kernel 0 03-12-2009 06:27 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:33 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration