Picture of mitop
Registered 3 years 151 days
mitop Friday, 2 December 2022, 12:55 PM
netdb.h and gethostbyname function, does it work when called from an app?
Hi all,

while in the process of integrating some open source libraries that try to use the "gethostbyname/gethostbyname_r" function located in "..\innovaphone\sdk\app-platform-libs\8\x86_64\usr\include\netdb.h", the following problem arises: The libraries included try to connect to another system and fetch some data, doing this by handing over an ip address works fine. Trying the same with the name of the machine returns only empty string/nullptr if calling "gethostbyname/gethostbyname_r" function (These calls are located within the libraries). So the questions are: Does gethostbyname work at all? Has anyone had any experience with this?

Kind regards
Mladen
Picture of Daniel Deterding (innovaphone)
Moderator Registered 14 years 345 days
Daniel Deterding (innovaphone) Friday, 2 December 2022, 01:08 PM
1 of 1 users consider this post helpful
Re: netdb.h and gethostbyname function, does it work when called from an app?
Hi Mladen,

gethostbyname is obsolete and getaddrinfo should be used instead. This is also what the IDns interface of our SDK does.

But what do you mean with "the name of the machine" which is handed to gethostbyname? Is this a valid DNS name?

Greetings,
Daniel
Picture of mitop
Registered 3 years 151 days
mitop Friday, 2 December 2022, 01:15 PM
Re: netdb.h and gethostbyname function, does it work when called from an app?
Hi Daniel,

thank you for your respond. Yes it is a valid DNS with a prefix and a port number given that represents the machine name. The libraries prepare the name and try to resolve the dns what actually fails. Hmm...maybe i can replace the function inside the libraries with "getaddrinfo" and give it a try (after lunch smile)
Picture of Daniel Deterding (innovaphone)
Moderator Registered 14 years 345 days
Daniel Deterding (innovaphone) Friday, 2 December 2022, 01:25 PM
1 of 1 users consider this post helpful
Re: netdb.h and gethostbyname function, does it work when called from an app?
Hi Mladen,

did you test a ping to this DNS name inside a shell on the AP to test if the standard resolution works?

You could also try to use our IDns for a short test to see if the resolution to this specific name succeeds or not.

Greetings,
Daniel
Picture of mitop
Registered 3 years 151 days
mitop Friday, 2 December 2022, 02:53 PM
Re: netdb.h and gethostbyname function, does it work when called from an app?
Hi Daniel,

thank you for that hint. Neither ping nor nslookup works from command line for the requested dns (other dns work). The IDns interface works with a valid dns too. So i will check my network settings first, replace the gethostbyname function and give it a try and let you know.

Greetings
Mladen
Picture of mitop
Registered 3 years 151 days
mitop Friday, 2 December 2022, 03:05 PM
Re: netdb.h and gethostbyname function, does it work when called from an app?
I had forgotten to mention, the file include here seems to be wrong: https://sdk.innovaphone.com/13r3/sdk/common/interface/dns.htm

Should be "common/interface/dns.h", or do i need the "common/interface/timezone.h" include too?
Picture of Daniel Deterding (innovaphone)
Moderator Registered 14 years 345 days
Daniel Deterding (innovaphone) Friday, 2 December 2022, 03:15 PM
Re: netdb.h and gethostbyname function, does it work when called from an app?
The file is wrong, I'll fix this smile
Picture of mitop
Registered 3 years 151 days
mitop Friday, 2 December 2022, 03:59 PM in response to Daniel Deterding (innovaphone)
Re: netdb.h and gethostbyname function, does it work when called from an app?
Hi Daniel,

after checking the network settings (never underestimate the network dangers in home office) the "gethostbyname" function resolves the dns as expected smile. I can ping the dns from AP shell (nslookup seems not to work, cannot even lookup google) and the IDns interface works fine.
Since "gethostbyname" is obsolete, will it soon no longer be available? If so, I would have to replace the function with "getaddrinfo " and from what I have just seen, it is not quite trivial...but if absolutely necessary, I'll do it right away

Greetings
Mladen
Picture of Daniel Deterding (innovaphone)
Moderator Registered 14 years 345 days
Daniel Deterding (innovaphone) Friday, 2 December 2022, 05:46 PM
Re: netdb.h and gethostbyname function, does it work when called from an app?
Hi Mladen,

I just read this on the man page:
https://man7.org/linux/man-pages/man3/gethostbyname.3.html

I have no idea if or when this function won't be available anymore ...

Greetings,
Daniel
Picture of mitop
Registered 3 years 151 days
mitop Monday, 5 December 2022, 08:45 AM
Re: netdb.h and gethostbyname function, does it work when called from an app?
Hi Daniel,

i think it should be up to the creators of the open source libraries to decide when these system functions should be replaced in the code, as it should be in their interest that the software continues to run. From our point of view, after a certain app platform version, the apps are upgraded again and the latest version of the libraries is used. I would rather invest my time in an automated upgrade process so that new versions of the open source libraries can be updated with "one click". In return, I should keep the changes to the original code as small as possible.

Many thanks for your help

Greetings
Mladen
← You can define your color theme preference here