Author Topic: fnAddARP  (Read 16999 times)

Offline hervé

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
fnAddARP
« on: February 10, 2011, 01:39:32 PM »
Hi Mark,

When I send a UDP broadcast from a network IP outside my board mask, it can be read but not replied : It was not added into the arp table.
Is it absolutely necessary to not include the broadcast sender ip ?

Thanks

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3240
    • View Profile
    • uTasker
Re: fnAddARP
« Reply #1 on: February 10, 2011, 04:28:10 PM »
Hi Hervé

If you receive an IP frame from somewhere outside of the local sub-net the address will not be cached in ARP; ARP will only cache addresses in its sub-net.

When sending to an IP address outside the sub-net it will always be sent to the gateway and therefore it is only necessary to cache the gateway's IP/MAC address in the ARP cache.

Regards

Mark

Offline hervé

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
Re: fnAddARP
« Reply #2 on: February 11, 2011, 12:06:38 PM »
Thanks Mark,

It looks normal, but if I want to reply to every broadcast discovery message (detected by my specific protocol); Do I only have to add the fnAddARP() function before sending my reply?

At this time(inside fnUDPListner) I know the IP of the sender but no more it's  MAC address, how can I recover this MAC address ?

Regards

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3240
    • View Profile
    • uTasker
Re: fnAddARP
« Reply #3 on: February 11, 2011, 03:27:58 PM »
Hi Hervé

When you send a UDP frame you need only konw its IP address. If the MAC address of this is not in the cache, the ARP task will automatically try to resolve it. It will resolve it by ARP requests of the IP address is within the local sub-net or it will send it to the gateway's MAC address if not (if the gateway is not cached it will resolve it first).

If the UDP frame could be sent the function fnSendUDP() will return the length fo the frame sent. In this case the IP address was already in cache.
If fnSendUDP() returns 0 it means that the ARP task needs to resolve it and you ust be prepated to repeat the UDè frame once thsi is completed.

ARP_RESOLUTION_FAILED will be received as message if ARP could not resolve the address.
ARP_RESOLUTION_SUCCESS will be received once the address has been resolved - and here is where you need to try again.

Therefore, normally, you should never need to know the MAC address of the received when working with UDP.

In the case of a listern, which has just received a UDP frame, the sender's IP address (or gateway if it arrived via a gateway) should always be cached.

If it is a broadcast UDP frame outside of the sub-net it could have arrived directly (not via gateway) in which case an attempt will be made to send it through the default gateway. This may be your problem, since the gateway may not be able to deliver it to the local IP addresses outside of it's own sub-net - you may need to ensure that its sub-net contains the sender(?)

Eg.
Your device has sub-net 255.255.255.0 - eg. 192.168.0.99
The broadcasting device has 255.255.254.0 - eg. 192.168.1.100
Your gateway has 255.255.254.0 (eg. 192.168.0.1) - this shoud be able to route your replies to it to the sender.
However, if the gateway has 255.255.255.0 it will also not be able to communicate with the broadcasting device since it is not in its sub-net.


Does this correspond to your experiences?

Regards

Mark

Offline hervé

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
Re: fnAddARP
« Reply #4 on: February 11, 2011, 04:22:53 PM »
Hi Mark,

Thanks for your explanations.
Let's suppose I have boards installed at customer plant with a correct IP Mapping.
The network administrator wants to change the network mapping for administration purpose (or move the board to another part of the location with a different subnet)
I want to make a tool which could located all my boards even if they are not in the correct subnet (so I can access then remotely)

I saw they can listen my broadcast.

To reply to it, if fnSendUDP() returns ARP_RESOLUTION_FAILED, I want to force the ARP table with the {IP,MAC} couple; then try again to reply.

At this time I only know the IP address, and I do need the MAC also to fill in the ARP table. No?

Regards
Hervé



Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3240
    • View Profile
    • uTasker
Re: fnAddARP
« Reply #5 on: February 11, 2011, 04:33:16 PM »
Hervé

Can you check why you get ARP_RESOLUTION_FAILED?
fnSendUDP() will not return this as a return parameter but instead ARP sends it as a messaage after it has attempted to resolve the address. Do you see ARP trying to resolve? Usually ARP_RESOLUTION_FAILED is received about a second later after ARP has made a few attempts.


Regards

Mark

Offline hervé

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
Re: fnAddARP
« Reply #6 on: February 11, 2011, 04:53:49 PM »
Mark,

Sorry I didn't correctly explained.
At this time I thought I had to call fnAddARP() before fnSendUDP().
From your last post I understood that after calling fnSendUDP() I will get an ARP_RESOLUTION_FAILED that I could use to then call fnAddARP().

My last post was only a project, trying to do what I want.


Regards.
Hervé