I have a Raspberry Pi 2, running Raspbian.
I'm trying to get informations by IP addresses, such as aliase(s), hostname(s) and so on.
According to the man, gethostbyaddr
is obsolete: better use getnameinfo()
.
No matter what I try, valgrind
detects a SIGILL
during a getnameinfo()
call.
I checked the proper filling of sockaddr_in sa
fields, the actual value of the IP address I want to resolve, the returning value of getnameinfo()
, all the necessary #include
.
Yet, executing the code below with valgrind
int temp_ret = 0;
struct sockaddr_in sa;
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
sa.sin_family = AF_INET;
/* temp is a personal struct; saddr is an unsigned long int */
sa.sin_addr.s_addr = htonl(temp->saddr);
temp_ret = getnameinfo((struct sockaddr*)&sa, sizeof(sa), hbuf,
sizeof(hbuf), sbuf, sizeof(sbuf), NI_NAMEREQD);
if(temp_ret > 0) {
/* handle error */
}
/* printf below is not reached */
printf("%s %s\n", hbuf, sbuf);
returns
==742==
==742== Process terminating with default action of signal 4 (SIGILL)
==742== Illegal opcode at address 0x485F6F4
==742== at 0x485F6F4: ??? (in /usr/lib/arm-linux-gnueabihf/libarmmem.so)
By executing the code without valgrind
, it simply crashes doing things fine before calling getnameinfo()
.
The error code above was made by 3.11.0 version: I updated valgrind
from the 3.6 version I found in the repositories to the 3.11.0 downloaded from the site; the error simply changed layout but the content was still the same.
I hope this is not because of something wrong with getnameinfo()
; anyway, the following are my system informations:
$ uname -a
Linux raspberrypi 4.1.7-v7+ #817 SMP PREEMPT Sat Sep 19 15:32:00 BST 2015 armv7l GNU/Linux
$ cat /etc/debian_version
8.0
Any advice would be really appreciated.
Edit 1: on my laptop running Ubuntu, calling getnameinfo()
returns no error, even with valgrind
activated.
Edit 2: running ldd --version
on both my RPi and my laptop I get respectively:
ldd (Debian GLIBC 2.19-18+deb8u1) 2.19
ldd (Ubuntu EGLIBC 2.19-0ubuntu6.6) 2.19
So, getnameinfo()
has issues with GLIBC (RPi) but works fine with EGLIBC (Ubuntu).
gcc
? If so, what arguments are you passing to it?gcc -Wall -Wunused
: I changed the flag fromNI_NAMEREQD
("If set, then an error is returned if the hostname cannot be determined": maybe that was the problem) toNI_NUMERICHOST | NI_NUMERICSERV
: this time no crash, but it returns all the IP addresses as they were, no hostname resolved, and services are all0
. So, no resolve yet, but at least it doesn't crash.-Ox
optimization problem or something... Not sure about what's going on withgetnameinfo()
, but this might bring some clarification.