ESP32_ping icon indicating copy to clipboard operation
ESP32_ping copied to clipboard

'inet_addr_to_ipaddr' was not declared in this scope [SOLVED]

Open wieb18 opened this issue 6 years ago • 16 comments

Thanks a lot for excellent library.

It works fine on ESP32, no compiler error.

Because something wrong on my PC, I did fresh install Windows 10 and Arduino IDE 1.8.8.

But after fresh install, ESP32 Ping doesn't work anymore.

Arduino IDE Compiler error in Ping.cpp line:

inet_addr_from_ipaddr(&to.sin_addr, addr);

The error message: 'inet_addr_to_ipaddr' was not declared in this scope

It seems this error cause by broken lwip library.

ESP32 Ping use 2 separate lwip libraries (Arduino library in C:\Program Files (x86)\Arduino and ESP32 library in C:\Users\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.1\tools\sdk\include\lwip\lwip folder).

But somehow the library connection is broken and cause 'inet_addr_to_ipaddr' was not declared in this scope error

Instead using Board Manager to install ESP32 package, also tried install ESP32 package by using git, but didn't help either. Still 'inet_addr_to_ipaddr' was not declared in this scope error

How to fix this error?

Please help...

wieb18 avatar Jan 17 '19 18:01 wieb18

Tried very dumb solution by adding these lines:

#define inet_addr_from_ipaddr 
#define inet_addr_to_ipaddr 

in Ping.cpp.

No compiler error and able upload the sketch into ESP32.

But ping doesn't work because it didn't find inet_addr_from_ipaddr and inet_addr_to_ipaddr functions.

How to fix this?

Please help...

wieb18 avatar Jan 17 '19 18:01 wieb18

Done this steps:

1. Uninstall Arduino IDE 1.8.8
2. Delete C:\Users\AppData\Local\
3. Rename C:\Users\Documents\Arduino into C:\Users\Documents\Arduino_OLD
4. Restart the PC
5. Install Arduino IDE 1.8.8
6. Install ESP32 Core version 1.0.0 using Boards Manager

Then.... compile my sketch.

And now.... it WORKS.... :) :) :)

My previous mistake is not installing ESP32 Core version 1.0.0.

I did it by installing version 1.0.1 - the Boards Manager default version - which didn't work.

It seems some change in ESP32 Core version 1.0.1 broke ESP32 Ping library connection.

wieb18 avatar Jan 18 '19 05:01 wieb18

Ping.cpp does not include the header that defines this function, you can alter the library to add the following to fix this likely:

#include <lwip/inet.h>

atanisoft avatar Mar 14 '19 19:03 atanisoft

I added #include <lwip/inet.h> to Ping.cpp.. Compilation with Core 1.0.1 resulted in the same error.

bill-orange avatar Mar 15 '19 00:03 bill-orange

The "function" is defined in that file, additional code may be required but I don't have this library setup on my system but I do use this function in my own code without issues.

atanisoft avatar Mar 15 '19 00:03 atanisoft

a fix for this: https://github.com/PotatoX/ESP32_ping/commit/4b8688e013933af6459b3816bafb6b3a0debb371

atanisoft avatar Mar 15 '19 12:03 atanisoft

@atanisoft That works, thanks! I use ping to test for a live internet connection.

bill-orange avatar Mar 15 '19 17:03 bill-orange

When will PotatoX fix be merged to mater? I am getting the same issue with ESP core 1.0.1 right now.

dachshund-digital avatar Mar 23 '19 19:03 dachshund-digital

Found another bug, typo...

In Ping.cpp... free() call is malformed, missing ";"... throws errors on compile.

if ((err = sendto(s, iecho, ping_size, 0, (struct sockaddr*)&to, sizeof(to)))) {
	transmitted++;
}
free(iecho)
return (err ? ERR_OK : ERR_VAL);

dachshund-digital avatar Mar 23 '19 20:03 dachshund-digital

to make this work for v1.01 just change

inet_addr_from_ipaddr to inet_addr_from_ip4addr inet_addr_to_ipaddr to inet_addr_to_ip4addr

in file Ping.cpp in your library path

Thats it

chillitomato avatar Mar 27 '19 16:03 chillitomato

The solution that works for me is changing the following lines:

to.sin_addr = *(in_addr *) addr; // inet_addr_from_ipaddr (&to.sin_addr, addr);

fromaddr = *(ip4_addr_t *) &from.sin_addr; // inet_addr_to_ipaddr (&fromaddr, &from.sin_addr);

BojanJurca avatar Nov 24 '19 08:11 BojanJurca

I'm using ESP 1.0.4 and could not easily get any of the above methods to work, but I have gotten it to work using ip4addr_aton(AF_INET, &to.sin_addr, inet_addr(addr));

Please test with my fork at https://github.com/pvint/ESP32_ping and let me know if it works with your version(s)

pvint avatar Dec 04 '19 23:12 pvint

Thanks @pvint, that totally worked for me (using ESP 1.0.4 here). Saved me a bunch of time, much appreciated.

zyklone92 avatar Mar 11 '20 20:03 zyklone92

Good to hear @zyklone92 (and thanks for the feedback!) I've been running a few devices for a few months now with those changes - I'll have another look at my code tomorrow to make sure it looks clean and submit a PR. It's a great library, but it looks like it may possibly be abandoned. I foresee using this a lot for a long time... @pbecchi : Do you have plans to maintain this in the future? If so, I'm glad to help out, and if not, I'd be happy to take it over (if you so desire) or simply do some maintenance/bugfixes on my fork.

Cheers Paul

pvint avatar Mar 11 '20 22:03 pvint

https://github.com/marian-craciunescu/ESP32Ping not abandoned input may is welcomed

marian-craciunescu avatar Mar 23 '20 09:03 marian-craciunescu