njh / EtherCard

EtherCard is an IPv4 driver for the ENC28J60 chip, compatible with Arduino IDE

Home Page:https://www.aelius.com/njh/ethercard/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wrong MAC when sending broadcast

thefrip opened this issue · comments

Hello,

When sending a broadcast packet (255.255.255.255) the recipient MAC remains to 00:00:00:00:00:00. If not wrong, it should be also set to the broadcast MAC (as for the WOL packets for instance).

I made the following fix in tcpip.cpp, function EtherCard::udpPrepare:

replaced
if ((dip[0] & 0xF0) == 0xE0) // multicast address

by
if ((dip[0] & 0xF0) == 0xE0 || *((long *) dip) == 0xFFFFFFFF) // multicast or broadcast address

Seems to work.

Rgds,

L.

Committed, thanks.

Hi there!

First post so: thanks a lot for the work, I'm using this lib for a while now! Best one IMO :-)

I was actually using the following hack to cope with this issue, because I want to send the packets to the network broadcast IP, not full broadcast (i.e. 192.168.1.255) :

if ((dip[0] & 0xF0) == 0xE0 || dip[3] == 0xFF)

Thanks!
R.

Indeed, works as well. But I thought the partial broadcast was not
working on the card, only the full one?

Le 01/11/2012 20:54, RaphYot a écrit :

Hi there!

First post so: thanks a lot for the work, I'm using this lib for a
while now! Best one IMO :-)

I was actually using the following hack to cope with this issue,
because I want to send the packets to the network broadcast IP, not
full broadcast (i.e. 192.168.1.255) :

if ((dip[0] & 0xF0) == 0xE0 || dip[3] == 0xFF)

Thanks!
R.


Reply to this email directly or view it on GitHub
#59 (comment).

You are welcome.

Le 01/11/2012 10:19, Jean-Claude Wippler a écrit :

Committed, thanks.


Reply to this email directly or view it on GitHub
#59 (comment).

I can send broadcast packet that way without issue. The only problem I see is that it's just a partial solution as without the mask you don't know the real broadcast address.

What kind of issue do you mean? With the new lib it seems I'm not receiving my network broadcast anymore on the arduino (although I enabled broadcast), but it was working on an older project so I suppose this should be feasible.

I'd be happy to change it to a single-byte check, and just make 255.255.255.0 the default netmask that way. Ought to work for msot cases.

I am having problem with sendUdp() and I traced the problem to this line
if ((dip[0] & 0xF0) == 0xE0 || ((long) dip) == 0xFFFFFFFF)
EtherCard::copyMac(gPB + ETH_DST_MAC, allOnes);
After commenting out this line, and sendUdp() works nicely. With this line, the sending would fail. The problem is reported in the following post by others as well...
http://jeelabs.net/boards/7/topics/1179

Does anyone know what the problem is?

I'm try use sendTcp() and doesn't work, but if comment the line proposed for shagru, then works OK.
Thanks for your trick, but why is not change in the library?

The problem @shagru has might be related to the multicast check (I don't know) but @jnogues makes no sense, those lines are unrelated to sendTcp()

I also have the problem that UDP broadcast has a mac of 0x00000000, and the proposed fix doesn't work for me because I do

  ether.sendUdp((char*) buf, pos, srcport, ether.broadcastip, dstport);

Would the fix be more correct if the check was for ether.broadcastip?

    if ((dip[0] & 0xF0) == 0xE0 || *((unsigned long*) dip) == 0xFFFFFFFF 
            || (memcmp(dip, EtherCard::broadcastip, 4) == 0)) //not subnet broadcast
        EtherCard::copyMac(gPB + ETH_DST_MAC, allOnes);

?