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);


==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


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).

  • Are you compiling with gcc? If so, what arguments are you passing to it?
    – Will
    Feb 16, 2016 at 19:16
  • All my files are compiled with gcc -Wall -Wunused: I changed the flag from NI_NAMEREQD ("If set, then an error is returned if the hostname cannot be determined": maybe that was the problem) to NI_NUMERICHOST | NI_NUMERICSERV: this time no crash, but it returns all the IP addresses as they were, no hostname resolved, and services are all 0. So, no resolve yet, but at least it doesn't crash.
    – elmazzun
    Feb 17, 2016 at 13:22
  • Ah, interesting. "Illegal instruction" has me suspecting it was maybe a -Ox optimization problem or something... Not sure about what's going on with getnameinfo(), but this might bring some clarification.
    – Will
    Feb 17, 2016 at 20:52

1 Answer 1


This sounds like a WONTFIX bug in valgrind that is discussed on StackOverflow thread. The fix for that bug, which works for me, is to comment out the line in a preloaded .so file to force the glibc version to be used. You could see if you can comment out the line in /usr/lib/arm-linux-gnueabihf/libarmmem.so to avoid the preload.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.