[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 329
  • Last Modified:

Packet Transfering at Datalink Layer

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?
0
krkc
Asked:
krkc
  • 3
  • 2
  • 2
2 Solutions
 
sunnycoderCommented:
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

Sunnycoder
0
 
krkcAuthor Commented:
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.
0
 
sunnycoderCommented:
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
krkcAuthor Commented:
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.
0
 
kevinnguyenCommented:
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 !

kevinnguyen

0
 
krkcAuthor Commented:
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
        newbuf[0]=0x00;
        newbuf[1]=0x80;
        newbuf[2]=0x48;
        newbuf[3]=0x24;
        newbuf[4]=0xE3;
        newbuf[5]=0x9D;

        newbuf[6]=0x00;
        newbuf[7]=0x80;
        newbuf[8]=0x48;
        newbuf[9]=0x1E;
        newbuf[10]=0x3A;
        newbuf[11]=0x7E;

//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.
0
 
kevinnguyenCommented:
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

IMPORTANT:

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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now