Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

EthernetClient.cpp doesn't close socket when IP Address is 0.0.0.0 or 255.255.255.255 #5911

Closed
Labels
@gtaspider

Description

When you try to connect to 0.0.0.0 or 255.255.255.255 multiply times, you won't be able to connect to anything anymore after the 4th try (because of the limitation of 4 sockets per w5100)
This is because in EthernetClient.cpp there is at line 57:
if (!::connect(_sock, rawIPAddress(ip), port)) { _sock = MAX_SOCK_NUM; return 0; }

and the connect function in socket.cpp at line 82:
if ( ((addr[0] == 0xFF) && (addr[1] == 0xFF) && (addr[2] == 0xFF) && (addr[3] == 0xFF)) || ((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) || (port == 0x00) ) return 0;

So, if the IP is 0.0.0.0 or 255.255.255.255 the socket will be opend, the status will be set to SnSR::INIT but the socket will not close after it fails because of the IP so it will be in INIT State forever.

To fix this simply add close(_sock) in the if statement:
if (!::connect(_sock, rawIPAddress(ip), port)) { close(_sock); _sock = MAX_SOCK_NUM; return 0; }

Greetings,
Spider

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /