Hello all, this is my first post. I've been working to add this remote IP functionality to my project. All the suggestions here and elsewhere have not worked. My project uses an UNO with an Ethernet2 shield. The original Ethernet libray worked fine except for the remote IP functionality. So, I dowmloaded the Ethernet2 library from somewhere and it did not have any code pertaining to remote IP. So I started poking at it with a stick. I got it to work today, finally. Here's what I did:
Ethernet2 Library Modifications
Modifications made to two files:
...\Arduino\libraries\Ethernet2-1.0.4\src\ EthernetClient.cpp
I added the follow bit of code to the very end of the file:
// Added by Stephen Kurth Feb 8, 2019
// returns the remote IP address:
IPAddress EthernetClient::getRemoteIP()
{
if (_sock >= MAX_SOCK_NUM) return IPAddress((uint32_t)0);
uint8_t remoteIParray[4];
SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE0));
w5500.readSnDIPR(_sock, remoteIParray);
SPI.endTransaction();
return IPAddress(remoteIParray);
}
I originallly pasted a copy of this code from the same .cpp file in the original Ethernet Library. Had to change a bunch of stuff in it though to get it compile. The shown code compiled and worked.
...\Arduino\libraries\Ethernet2-1.0.4\src\ EthernetClient.h
I added this code to this file in this location:
virtual bool operator!=(const EthernetClient& rhs) { return !this->operator==(rhs); };
// added by Stephen Kurth Feb 8, 2019
IPAddress getRemoteIP();
friend class EthernetServer;
Most of the other lines start with virtual but I don't really know what it does. By that point I was just poking it with a stick and seeing if it would compile. It did, finally.
The code in my Arduino sketch is:
client = server.available(); // try to get client
if (client) // got client?
{
IPAddress remoteIp = client.getRemoteIP();
Serial.print(F("Remote IP: "));
Serial.println(remoteIp);
boolean currentLineIsBlank = true;
while (client.connected())
{
if (client.available()) // client data available to read
{
I made all the library edits in Visual Studio 2017.
I just thought I'd share in case anyone else is trying to do this with the same hardware.