EthernetUdp problem: with Arduino Ethernet: receiving wrong packets

Hi everyone!

I think I have a problem with my Ethernet Arduino.

My question: Is possible that Ethernet Arduino in Udp mode receive packets not strictly directed to him, and when I use the Udp.parsePacket() he catchs a packet directed to another IP address?

I explain:

Suppose I have a Sender and two Receivers (R1, R2). The Sender first sends a packet P1 destined to R1 (with IP for example 192.168.1.100) and then a packet P2 to R2 (with IP for example 192.168.1.101).

When R2 performs Udp.parsePacket() he actually read the packet P1 and after that (with another Udp.parsePacket call) there are no traces of packet P2 (?!).

It's very strange, there are two questions inside:

Is possible that R2 can read also the packets destined to R1?
Where is now the packet P2?

Thank you for your kindness.

My question: Is possible that Ethernet Arduino in Udp mode receive packets not strictly directed to him, and when I use the Udp.parsePacket() he catchs a packet directed to another IP address?

I have never seen that happen here, and I use UDP a lot.

You do use different mac addresses for each ethernet shield, correct? That could cause a problem like that if they had the same mac address.

You do use different mac addresses for each ethernet shield, correct?

Yes, I do. There are different MAC address for each device but I use the same port number for each.

(Tried with different ports but nothing is changed)
I have new results.

The problem exists when the R1 node is down. Thus R2 receive the P1 packet, but not P2.

Obviously this situation is interchangeable.

The fact is that, when I have the presence of both R1 and R2, the system works fine!

But, is that possible? I would like to have the system working also with one of the two nodes down (could be an actual possibility)!!

Have I discovered some bug?

Thanks everyone for your help.

Are you evaluating the return value from UDP.endPacket() for each send? It returns 1 on success and 0 on fail. Is the send reporting a successful send to the receiver that is down?

edit: Is the sender an Arduino? I presume both receivers are Arduinos, correct?

And all are on the same localnet?

The reason I ask this is the ethernet shield does an ARP request for every packet sent, requesting the mac address for the destination IP. If the ARP request fails, the packet is never sent.

Now I have evaluated the return value of Udp.endpacket(), and when the R1 device is down, the value is zero. But then when he sends the other packet to the R2 device online, the return value is 1, but as you know, R2 will read the wrong packet (P1).

The Sender is Arduino Uno with Eth Shield, the receivers R1 and R2 are two Arduino Ethernet.

All the devices are in the same localnet.

Thanks.

You should post your code for the sender.

The return value of 0 normally means the ARP request failed and the sender never even attempted to send the UDP packet itself. You can’t “accidentally” receive a packet that was never sent.

edit: If you have WireShark or any other packet sniffer application, maybe you should watch the network for the packet sends. Maybe that will help you discover the problem.

I think some network devices can be put in a "promiscuous" mode which receives everything that is being sent on its ethernet connection. your issue might be something similar.

SurferTim:
You should post your code for the sender.

here it is:

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>

byte macSender[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ipSender(192, 168, 1, 177);
IPAddress ipDevice1(192, 168, 1, 20);  
IPAddress ipDevice2(192, 168, 1, 22);  
IPAddress ipDevice3(192, 168, 1, 24);  
unsigned int localPort = 6666;
EthernetUDP Udp;
byte state;
void setup() {

  Serial.begin(9600);
  Ethernet.begin(macSender, ipSender);
  Udp.begin(localPort);

}
void loop() {
  int id_dev;
	//[...]
    Serial.println("Send pck to display");
    sendPckDev(id_dev);   //send P1 to R1
    sendPckExtDev();      //send P2 to R2
	//[...]
}

void sendPckDev(int id_dev) {
  byte messageIntDev[5];
  IPAddress ipReceiver;

  messageIntDev[0] = 0xFF;

  if(id_dev == 0) {
	messageIntDev[1] = 1;
  	ipReceiver = ipDevice1;
  }
  else if (id_dev == 1) {
	messageIntDev[1] = 2;
	ipReceiver = ipDevice2;
  }
  messageIntDev[2] = 0xFC;                  
  messageIntDev[3] = 1;                   
  messageIntDev[4] = state;

  Udp.beginPacket(ipReceiver,localPort);
  Udp.write(messageIntDev,5);
  int result = Udp.endPacket();
  Serial.println(result);
}

void sendPckExtDev() {
  byte message[] = { 255 , 3 , 221 , 1 , state };
  Udp.beginPacket(ipDevice3,localPort);
  Udp.write(message,5);
  int result = Udp.endPacket();
  Serial.println(result);
}

zoomkat:
I think some network devices can be put in a “promiscuous” mode which receives everything that is being sent on its ethernet connection. your issue might be something similar.

may I should modify something in the ethernet hub?

Thanks again.

any suggestions?

Have you considered starting 2 UDP sockets? You must use 2 different ports, but that should not be a problem.

// in global area
EthernetUDP Udp;
EthernetUDP Udp2;

unsigned int localPort = 6666;
unsigned int localPort2 = 6667;

// in setup
Udp.begin(localPort);
Udp2.begin(localPort2);