Pages: [1]   Go Down
Author Topic: Web server client IP  (Read 854 times)
0 Members and 1 Guest are viewing this topic.
Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5377
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It may be helpful to some if the ethernet library included a way to retrieve the client ip when using the server code. It can be used as a primitive firewall, preventing unauthorized client access. My library code changes to do this are already working.
http://arduino.cc/forum/index.php/topic,135082.0.html
The modified ethernet library code is attached to reply #1. It uses the new ip address format (IPAddress) in the same manner as the other ip functions in Ethernet.cpp.

Code:
IPAddress clientIP = client.remoteIP();

edit: This is the total code added. Nothing else changed.

Code added to EthernetClient module:
Code:
// EthernetClient.h
IPAddress remoteIP();

// EthernetClient.cpp
IPAddress EthernetClient::remoteIP() {
    return Ethernet.remoteIP(_sock);
}

Code added to Ethernet module:
Code:
// Ethernet.h
IPAddress remoteIP(uint8_t s);

// Ethernet.cpp
IPAddress EthernetClass::remoteIP(uint8_t s) {
  IPAddress ret;
  W5100.readSnDIPR(s,ret.raw_address());
  return ret;
}
« Last Edit: December 02, 2012, 09:34:18 pm by SurferTim » Logged

Pages: [1]   Go Up
Jump to: