This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Modified library to get Client IP Address from CC3000

Modification of Adafruit's CC3000 library; original POST:  "Arduino Stack Exchange by TisteAndii" 

This function is not built-in so you'll have to modify the library slightly. This is one way to do it, I think:

Navigate to the class Adafruit_CC3000_ClientRef in the file Adafruit_CC3000_Server.h. In the class definition, just before the private methods and attributes are defined, you will add a new public attribute as follows:

uint8_t ip_addr[4];  // assuming a typical IPv4 address

It will hold the IP address of each ClientRef instance as the connection is accepted.
Go to Adafruit_CC3000_Server::acceptNewConnections() near the end of Adafruit_CC3000_Server.cpp. A few lines will be added to get the IP address from the CC3000 and store it temporarily in the appropriate struct:
static sockaddr tSocketClientAddr;  // file scope
static socklen_t addr_len;

// Accept new connections and update the connected clients.
bool Adafruit_CC3000_Server::acceptNewConnections() {
  bool newClientCreated = false;
  // For any unconnected client, see if new connections are pending and accept
  // them as a new client.
  for (int i = 0; i < MAX_SERVER_CLIENTS; ++i) {
    if (!_clients[i].connected()) {
      // Note: Because the non-blocking option was set for the listening
      // socket this call will not block and instead return SOC_IN_PROGRESS (-2) 
      // if there are no pending client connections. Also, the address of the 
      // connected client is not needed, so those parameters are set to NULL.
      cc3k_int_poll();
      addr_len = sizeof(tSocketClientAddr);
      int soc = accept(_listenSocket, &tSocketClientAddr, &addr_len);
      if (soc > -1) {
        _clients[i] = Adafruit_CC3000_Client(soc);
        newClientCreated = true;
      }
      // else either there were no sockets to accept or an error occured.
    }
  }
  return newClientCreated;
}
You'll also edit the getClientRef() method in Adafruit_CC3000_Server.cpp:

Adafruit_CC3000_ClientRef Adafruit_CC3000_Server::getClientRef(int8_t clientIndex) {
  if (clientIndex != -1) {
    Adafruit_CC3000_ClientRef newClient =  Adafruit_CC3000_ClientRef(&_clients[clientIndex]);
    // at least 2 (family) + 2 (port) + 4 (ip_addr) bytes expected
    // also check if address is standard ipv4
    if ((addr_len >= 8) && (tSocketClientAddr.sa_family == AF_INET)){
       // copy address into array; in network byte order  
       memcpy(newClient.ip_addr, &(tSocketClientAddr.sa_data[2]), 4);
    }
    return newClient;
  }

  // Couldn't find a client ready to read, so return a client that is not 
  // connected to signal no clients are available for reading (convention
  // used by the Ethernet library).
  return Adafruit_CC3000_ClientRef(NULL);
}
Save all the files.
Now the address is stored in an array for each client and can be accessed from your sketch. For example, you can access the address in your sketch like this:

In the loop() of the the HttpServer example:
 Adafruit_CC3000_ClientRef client = httpServer.available();
 if (client) {
   Serial.println(F("Client connected."));
   for (int i = 0; i < 3; i++){
     Serial.print(client.ip_addr[i]);
     Serial.print('.');
   }
   Serial.println(client.ip_addr[3]); 
   // other code
 }
Completely untested. Good luck.

Modified library is producing inconsistent results; correct Client IP Address is given part of the time, rest of the time, it returns the Client IP Address of 0.0.0.0.

My experience level lacks the required skill to find a solution for this problem.

William