IP Filtering Usage

We are using W5200 for ethernet communication. Microcontroller and w5200 are interfaced through SPI. We want to implement IP filtering in our firmware. Once connection is established we our read out the destination ip address (i.e read out DIPR0-3) and check it against our vaild ip address. Is it the correct procedure to verify the incoming connection request ip address?

Once it is identified incoming connection ip address is not valid what are the sequence of operations to accept new connection?
What I planned to do is write 0.0.0.0 to DIPR registers and zeros to DHAR registers and close the socket. Then open the socket again move to listen mode and wait for new connection. is this sequence correct ? is there any more operations required?

The above mechanism was in the context of TCP connection. What would be the mechanism for UDP connection?

Hi, anoopbabu.

Your procedure is correct but you don’t need to set destination IP and destination MAC as zero.
Because when connection established, it is changed automatically. Just close.

And UDP has no connection. After open, just send data and receive data. So you need to parse target IP when received packet and then drop packet.

Best regards.

Thank you very much for the inputs