EtherCard icon indicating copy to clipboard operation
EtherCard copied to clipboard

Can't send udp packet to local network without gateway.

Open bestpika opened this issue 7 years ago • 4 comments

I can't send udp packet to local network without gateway. But can send to broadcast address (255.255.255.255).

#define PORT 5000

#include <EtherCard.h>
#include <IPAddress.h>

uint8_t macAddr[] = { 0, 0, 0, 0, 255, 1 };
uint8_t ipAddr[] = { 172, 16, 255, 1 };
uint8_t netMask[] = { 255, 255, 0, 0 };

uint8_t distAddr[] = { 255, 255, 255, 255 }; // I can't send packet to 172.16.255.2.

byte Ethernet::buffer[256];

void setup() {
  ether.begin(sizeof(Ethernet::buffer), macAddr);
  ether.staticSetup(ipAddr, 0, 0, netMask);
  ether.printIp("", ether.myip);
}

void loop() {
  char c[] = { 'h', 'i' };
  ether.sendUdp(c, sizeof(c), PORT, distAddr, PORT);
  delay(1000);
}

bestpika avatar Apr 18 '17 08:04 bestpika

This may need a fix similar to #167.

But udp already does this https://github.com/jcw/ethercard/blob/master/tcpip.cpp#L377

Can you confirm you are using the latest version of the library?

solarkennedy avatar Apr 18 '17 14:04 solarkennedy

I use git clone https://github.com/jcw/ethercard.git to clone this repo. So I think I get the latest version.

bestpika avatar Apr 19 '17 02:04 bestpika

It is possible that we have a /24 assumption somewhere in the code.

Can you get a packet capture (tcpdump -s 1500) of the thing trying to transmit packets? (I know this is difficult if they are not arriving at 172.16.255.2, but maybe they are being sent out incorrectly)

solarkennedy avatar Apr 21 '17 00:04 solarkennedy

Same problem with repo clone today.

Tzoreol avatar May 20 '17 16:05 Tzoreol