Compare client.remoteIP() to ipHOST

if (strcmp(client.remoteIP()),  ipHOST)==0)

Trying to Compare client.remoteIP() to ipHOST; however, compiler issues this error:

invalid user-defined conversion from 'IPAddress' to 'const char*' [-fpermissive]

When client.remoteIP() returns 192.168.1.71 and it is equal to my host ip of 192.168.1.71 code will exit current point in sketch.

How can this be correctly coded?

Special Ethernet library with client.remoteIP():

William

 virtual IPAddress remoteIP();

remoteIP() does not return a string. Using the string compare function does not make sense.

IPAddress is class. It has a == operator defined. You would have to make ipHost an instance of IPAddress, too.

@ PaulS

 virtual IPAddress remoteIP();

remoteIP() does not return a string. Using the string compare function does not make sense.

IPAddress is class. It has a == operator defined. You would have to make ipHost an instance of IPAddress, too.

Please, could you explain how the above code is used?

Thank you PaulS!

William

You can't compare different data types. This works.

#include <SPI.h>
#include <Ethernet.h>

IPAddress ip(192,168,0,2);
IPAddress ip2(192,168,0,2);
IPAddress ip3(192,168,0,3);

void setup() {
  Serial.begin(115200);
  // put your setup code here, to run once:

  if(ip == ip2) Serial.println("ip2 match");
  else Serial.println("ip2 no match");

  if(ip == ip3) Serial.println("ip3 match");
  else Serial.println("ip3 no match");
  
}

void loop() {
  // put your main code here, to run repeatedly:

}

Serial.print and Serial.println convert the parameter to a string before printing.

@ Surfer Tim

I follow your code!

Here is what I am trying to do:

Host computer has ip address of 192.168.1.47, client ip address is unknown.

When I get the value of the client ip address (client.remoteIP()); trying to compare it to see if value is the same as host computer ip address, if so exit.

Is there any way to do this?

My apologies Surfer Tim; I did too quick of a read of you code. Your handling of IPAddress was just what I was looking for, thank you! :slight_smile:

Thanks Surfer Tim!

William