Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getnameinfo's signature changes between glibc versions, how can I match it?

Tags:

c

linux

posix

gcc

I need to match the signature for the call getnameinfo so I can write a wrapper around that call. Unfortunately the signature changes between hosts.

Things were working and going find until I tried to compile on the latest CentOS, 6.3, which gives the error:

error: conflicting types for 'getnameinfo' 

Huh?

It turns out that the final argument, flags, is listed as an unsigned int on CentOS (glibc-headers-2.12-1.80) but is just an int on Fedora (glibc-headers-2.15-58). (Note that the man pages on both hosts say it should be an int.)

extern int getnameinfo ( /*cut*/, unsigned int __flags);

vs

extern int getnameinfo ( /*cut*/, int __flags);

Some searching leads me to believe that the standard has changed the type of the flags argument.

It looks like I need to change the type of flags in my function to match the host's definition. What's the best way to deal with this problem? Is this an autoconf-type issue or is there some simpler solution? I hoped that the compiler (gcc) would have some macro I could leverage but I can't find anything.

like image 890
Paul Rubel Avatar asked Oct 22 '22 17:10

Paul Rubel


1 Answers

you could check the __GLIBC_MINOR__ macro defined in features.h and pass the arguments accordingly, example:

#include <features.h>

#if __GLIBC_MINOR__ > 12 
    getnameinfo(..., flags);
#else 
    getnameinfo(..., (unsigned) flags);
#endif
like image 101
iabdalkader Avatar answered Oct 27 '22 10:10

iabdalkader