How to get source MAC and IP address when W5500 is receiving the packet

I would like to know the MAC and IP address of the source upon receiving data. In application for example, I want to create a blacklist of MAC addresses that I do not want to exchange data with, or only allow a specific IP address to access the data store in the system.

Which register should I read to get that information? Are they Socket n Destination Hardware Address and Socket n Destination IP Address in Socket Register Blocks?

DIPR and DPORT for UDP/TCP connection properties. But not sure for MAC address, logically it could be present in DHAR register, but datasheet does not state so.

W5300 datasheet states:

At the TCP, UDP and IPRAW mode, Sn_DHAR is set as destination hardware address that is acquired by ARP-process of CONNECT or SEND command. The host can acquire the destination hardware address through Sn_DHAR after successfully performing CONNET or SEND command.

Nothing about server mode when socket is listening and not actively connecting.

W6100 datasheet states:

Sn_DHAR indicates the destination hardware address after the connection is established (Sn_SR = SOCK_ESTABLISHED) with the destination in TCP4, TCP6, TCPD mode.

Thus you should be able to get MAC address after establishing connection in server mode. Most probably it also applies to w5500, but needs testing, and better confirmation from WIZnet.

1 Like