# strstr problem

• 09-08-2009
Kempelen
strstr problem
I have this code:

Code:

```while (readIP()) {       printf("IP: %s -> ",ip);         if (strstr(ip,"10.99.137.42")!=NULL) strcpy(ip,"APLIC_2_4_05"); // Prosa         else if (strstr,(ip,"10.99.138.25")!=NULL) strcpy(ip,"APLIC_3_13"); // SICOSS         else if (strstr,(ip,"10.99.138.28")!=NULL) strcpy(ip,"APLIC_3_13"); // SICOSS         else if (strstr,(ip,"10.99.138.3")!=NULL) strcpy(ip,"APLIC_3_13"); // SICOSS         else if (strstr,(ip,"10.99.178.6")!=NULL) strcpy(ip,"APLIC_3_18"); // PLANIFICADOR         else if (strstr,(ip,"10.99.178.7")!=NULL) strcpy(ip,"APLIC_3_18"); // PLANIFICADOR         else if (strstr,(ip,"10.99.1.189")!=NULL) strcpy(ip,"SOFTW_7_08"); // LOTUS NOTES         else if (strstr,(ip,"10.99.1.244")!=NULL) strcpy(ip,"SOFTW_7_08"); // LOTUS NOTES         else if (strstr,(ip,"10.99.145.11")!=NULL) strcpy(ip,"APLIC_3_15"); // CRM         else if (strstr,(ip,"10.99.145.21")!=NULL) strcpy(ip,"APLIC_3_15"); // CRM         else if (strstr,(ip,"10.99.1.203")!=NULL) strcpy(ip,"HARDW_7_05"); // SERVIDORES DE FICHERO E IMPRESION         else if (strstr,(ip,"10.99.177.146")!=NULL) strcpy(ip,"HARDW_7_11"); // COMUNICACIONES         else if (strstr,(ip,"10.99.138.7")!=NULL) strcpy(ip,"HARDW_5_05"); // HOST         else if (strstr,(ip,"10.99.138.75")!=NULL) strcpy(ip,"HARDW_5_05"); // HOST         else if (strstr,(ip,"10.99.147.44")!=NULL) strcpy(ip,"RED_7_09"); // RED         else if (strstr,(ip,"10.99.133.84")!=NULL) strcpy(ip,"BBDD_5_30"); // BBDD PROSA         else if (strstr,(ip,"10.99.30.230")!=NULL) strcpy(ip,"BBDD_5_18"); // BBDD REMESAS RED         else if (strstr,(ip,"10.99.186.2")!=NULL) strcpy(ip,"BBDD_5_16"); // BBDD Q+         else if (strstr,(ip,"10.99.147.36")!=NULL) strcpy(ip,"APLIC_2_4_04"); // PORTAL INTRANET         else if (strstr,(ip,"10.99.137.133")!=NULL) strcpy(ip,"APLIC_2_4_03"); // JACADA         else {printf("IP No reconocida -> %s\n",ip);continue;}       printf("%s\n",ip); }```
And I am getting this output:

Code:

```IP: 10.99.133.84 -> APLIC_3_13 IP: 10.99.137.133 -> APLIC_3_13 IP: 10.99.145.11 -> APLIC_3_13 IP: 10.99.30.230 -> APLIC_3_13 IP: 10.99.133.84 -> APLIC_3_13 IP: 10.99.137.133 -> APLIC_3_13 IP: 10.99.145.11 -> APLIC_3_13 IP: 10.99.30.230 -> APLIC_3_13 IP: 10.99.133.84 -> APLIC_3_13 IP: 10.99.145.11 -> APLIC_3_13 IP: 10.99.137.133 -> APLIC_3_13 IP: 10.99.145.11 -> APLIC_3_13 IP: 10.99.30.230 -> APLIC_3_13 IP: 10.99.133.84 -> APLIC_3_13 IP: 10.99.137.133 -> APLIC_3_13 IP: 10.99.1.203 -> APLIC_3_13 IP: 10.99.133.84 -> APLIC_3_13 IP: 10.99.145.11 -> APLIC_3_13 IP: 10.99.133.84 -> APLIC_3_13 IP: 10.99.137.133 -> APLIC_3_13 IP: 10.99.30.230 -> APLIC_3_13 IP: 10.99.133.84 -> APLIC_3_13 IP: 10.99.137.133 -> APLIC_3_13 IP: 10.99.145.11 -> APLIC_3_13 IP: 10.99.30.230 -> APLIC_3_13 IP: 10.99.133.84 -> APLIC_3_13 IP: 10.99.137.133 -> APLIC_3_13 IP: 10.99.145.11 -> APLIC_3_13 IP: 10.99.147.44 -> APLIC_3_13 IP: 10.99.147.36 -> APLIC_3_13 IP: 10.99.30.230 -> APLIC_3_13 IP: 10.99.137.133 -> APLIC_3_13 IP: 10.99.145.11 -> APLIC_3_13 IP: 10.99.30.230 -> APLIC_3_13 IP: 10.99.147.44 -> APLIC_3_13 IP: 10.99.133.84 -> APLIC_3_13 IP: 10.99.145.11 -> APLIC_3_13 IP: 10.99.30.230 -> APLIC_3_13 IP: 10.99.133.84 -> APLIC_3_13```
This is of course bad, because I have to get correct ip_name and not always APLIC_3_13

What do you think is happening?

Thanks
FS
• 09-08-2009
whiteflags
Carefully look at this and related lines:

else if (strstr,(ip,"10.99.138.25")!=NULL) strcpy(ip,"APLIC_3_13");

now strstr is probably being interpreted as a function pointer because of the comma, which is already wrong. For some reason the condition is always true and thus "APLIC_3_13" is always copied.

I think it's actually comparing the IP != NULL which is always true.
• 09-08-2009
Sebastiani
You've got a spurious comma in there:

strstr,(ip,"10.99.138.3")

EDIT:
Nevermind. Much too slow. :p