People should never write open source libraries with private data members in classes, as you may know, this prevents you from deriving the class and adding your own extensions to it. This is what has happened to the Ethernet library, you cannot access private members needed to retrieve the remote IP.
You can mod the core yourself ( and every time you update the IDE ) using the intructions here: How to obtain the remote client IP address when using the Ethernet Shield - Networking, Protocols, and Devices - Arduino Forum
However I have a tiny library for use with your Arduino Ethernet shield projects that allows you to get this information without modifying the core libraries.
There is one function RemoteIP, it takes a reference to an EthernetClient object and returns an IPAddress object.
The IPAddress structure is part of the core and is printable.
EthernetClient client = server.available();
//...
Serial.print( "Remote IP: );
Serial.println( RemoteIP( client ) );
The library, create a new library folder called EthernetFix and a .h file with the same name. Then copy the code below into it.
You can just copy it into the sketch, however a library is more convenient for multiple projects.
//Requires your sketch to include Ethernet.h
#include <Arduino.h>
#include <utility/w5100.h>
template<typename Tag, typename Tag::type M>
struct AccessMember{
friend typename Tag::type get( Tag ){ return M; }
};
struct EthernetClient_Socket{
typedef uint8_t EthernetClient::*type;
friend type get( EthernetClient_Socket );
};
template struct AccessMember< EthernetClient_Socket, &EthernetClient::_sock >;
IPAddress RemoteIP( EthernetClient &c ){
byte remoteIP[ 4 ];
W5100.readSnDIPR( c.*get( EthernetClient_Socket() ), remoteIP );
return ( remoteIP );
}
Using the output from surfer tims web server I got this result:
Client request #1: GET / HTTP/1.1
file = /
file type =
method = GET
params =
protocol = HTTP/1.1
Remote IP: 192.168.1.100
Home page SD file
filename format ok
File not found
disconnected
SRAM = 6483
SRAM = 6483
Happy programming!
NOTE: To use the library in multiple C++ files you may need to move the RemoteIP function to a cpp file with only the prototype in the header. Ask if you need help with this.