Skip to content

Broadcast IP Datagram Discovery BAD Netmask Assumption #4

@cosmin2dor

Description

@cosmin2dor

Hi, I've notice this line of code
IPAddress broadcast_addr(remote_addr[0], remote_addr[1], remote_addr[2], 255);
So, it just happened that my netmask was 255.255.255.0 and it worked, but then I've changed it just to see if I will crash it. Indeed after the netmask change the app was not able to find my device.

I suggest changing that line with this:
IPAddress netmask(WiFi.subnetMask()); IPAddress broadcast_addr((unsigned char)(remote_addr[0] | ~netmask[0]), (unsigned char)(remote_addr[1] | ~netmask[1]), (unsigned char)(remote_addr[2] | ~netmask[2]), (unsigned char)(remote_addr[3] | ~netmask[3]));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions