[Webinar] Streamline your web hosting managementRegister Today


Packet Transfering at Datalink Layer

Posted on 2004-04-21
Medium Priority
Last Modified: 2010-04-22
Hello Everyone, This is my first post.

Iam doing a new project which will transfer the data from one LAN to another LAN. These LAN's are connected by using routers(Linux Machines).

Iam capturing the packets at Datalink Layer of Router1, and Iam modifing the MAC ID's of the Packet and retransferring to the other Router2. From Router2 the packet will be send to the Corresponding LAN2 Machine. A Reply will be send back by the Router2 to Router1 which again will be send as acknowledgement to the LAN1 Machine.

The Problem is that Iam able to get only few acknowledgements, as for every 100 packets send Iam getting reply for only 40 packets. And for remaining Iam getting "Request Timmed Out".

How can i get 100% reply. What kind of socket options i have to use?
Question by:krkc
  • 3
  • 2
  • 2
LVL 45

Expert Comment

ID: 10885719
Hi krkc,

I am not sure if this is your problem but it is a very probable cause ... Several protocols send an ACK for n packets and not every packet ... n depends on how many packets they can get in a reasonable time frame which will not cause a retransmit ... so it is more time dependent and not number of packets dependent ... Also if communication is two way, ACKs are often piggybacked on the data packets


Author Comment

ID: 10885750
ya i do accept that several protocols send an ACK for n packets. But at Datalink layer how can i make sure that the packet which was received was an ACK packet or DATA Packet?

Iam using a Raw Socket to connect to the ethernet card. And using the SendTo option to send the packet.

Can you give me any kind of Example.
LVL 45

Accepted Solution

sunnycoder earned 100 total points
ID: 10885799
You are not supposed to know that at L2 !!! This has to be determined by the higher layers ... that is the whole point of layering

Still if you insist then determining this at L2 will require moving a good amount of code from higher layers to L2
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Author Comment

ID: 10886066
I think you have not understood my actual problem. Here iam giving the exact senario of my project.

LanA -> Gateway1 -> Router1 -> Router2 -> Gateway2 -> LanB

LanB -> Gateway2 -> Router2 -> Router1 -> Gateway1 -> LanA

When i ping from LanA to LanB then my ping request first goes to Gateway1, from there it goes to Router1, there my application will receive the packet and sends to the Router2. From Router2 again my application will receive the packet and sends to Gateway2. And finally Gateway2 will automatically sends the packet to the exact destination of LanB. Where again LanB will send ACK to Gateway2 -> Router2 ->MyApp2-> Router1 ->MyApp1-> Gateway1-> LanA.

Now i think you got my query. My application will sit in Router1 and Router2 doing the transmitting job.

Here iam facing some problems getting the ACK for all the ping requests i made.

Expert Comment

ID: 10906250
One of reasons for "Requested timeout" message could be that both MyApp1 and MyApp2 running on Router1 and Router 2 respectively add a time delay to DATA and ACK packets sent to/from LanA and LanB.

Try to increase performance of MyApp1 and MyApp2. A lot of I/O operations to STDOUT may cause some time delays because they are time-consuming.

Good Luck !



Author Comment

ID: 10916861
Iam not using the STDOUT or printf Statements.

My Applications job is just to receive the data and send it to another Network Interface Card.

Iam receving the Packet as
        bufsize = recvfrom(sock,buff,1514,0(struct sockaddr*)&myaddr,&myaddrlen);

//Modify the MAC Addresses


//Send to the Other NIC
        snd=sendto(rmtHost,newbuf,sizeof(newbuf),0,(struct sockaddr*)&addr,sizeof(addr));

This is all my app. does.

so no storing of buffer, no printf statements and GUI. Just transfer from one NIC to another NIC. My code is giving me only 20% replies with i ping from Lan A to Lan B.

Assisted Solution

kevinnguyen earned 100 total points
ID: 10945805
I assume the following:

1) There are at least two computers on each LAN which they are connected together using a HUB. 2) With a HUB on each LAN, all computers on the same LAN will see each other's packets

Here are a few of my thoughts:

1) MyApp1 running on Router1 changes MAC address of outgoing packets originating from computer A on LAN A and forwards these packets to LAN B.
    a) What does MyApp1 do to packets receiving from LAN B ?
    b) Does MyApp1 append MAC address to those packets based on their destination IP address ?

2) The same issue applies to MyApp2


a) Two routers exchange packets using source and destination IP address in IP header of packets.
When a packet on Router1 is forwared to Router2, its MAC address will be stripped off. Whether you changes packet's MAC address or not, Router2 will not receive packet with MAC address upon receiving it.

b) Only HUB and SWITCH uses MAC address inside packets to deliver packets to appropriate recipients on the same LAN. They don't go by source and destination IP address.

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question