[rbldnsd] [patch] getnameinfo() fails on Solaris 9

Michael Tokarev mjt at tls.msk.ru
Thu Jan 22 01:26:50 MSK 2004


Leandro Santi wrote:
> Hi,
> 
> It seems that getnameinfo() fails on (at least) Solaris 9, but rbldnsd
> doesn't test for failure.

The real question is: why it fails?

getnameinfo() as used supposed to convert a sockaddr into ascii format
of an IP address.  There should be no error return except when the buffer
provided is too small (but the buffer used by rbldnsd is sufficient in
size - this is why NX_MAXHOST and NI_MAXSERV are defined by library and
used.  How the routine may fail?

Maybe it is a time to invent reimplementation of getnameinfo()
(which is trivial anyway)?

[]
> Newer, up-to-date systems, on the other hand, won't fill neither host
> or serv when getnameinfo() fails (this will just make rbldnsd print
> some garbage at daemon startup).

Again, where it's failing?
Note that this is not the only place where getnameinfo() is used.
Another place is logging.

> patch: http://webs.sinectis.com.ar/lesanti/misc/rbldnsd-0.991-getnameinfo.patch
> 
> Comments ?

Sure.

First of all, I made the whole IPv6 stuff in rbldnsd without ANY
knowlege about IPv6.  I looked how it is done in other programs
and just repeat the code, and it seems to be working  (I even
don't have a machine where IPv6 stack is compiled into the kernel).

In particular, I don't know what is NI_WITHSCOPEID constant and
what it does.  I saw it is used in conjunction with getnameinfo()
in one program (don't remember which one).  When I wrote the
code I noticied it does not want to compile on certain systems
(solaris included if memory serves me right), so I added an
#ifndef NI_WITHSCOPEID to define it to 0.  And since you tweak
it (redefine it to 0) if BROKEN_GETNAMEINFO is defined, the
question is - why, and what it really does.

Second, I don't understand why the test code ("autoconf"
fragment) does what it does.

int main(void)
{
   char host[1024];
   char serv[1024];
   struct sockaddr_in sin;
   memset(&sin, 0, sizeof(sin));
   sin.sin_family = AF_INET;
   sin.sin_port = htons(53);
   if (getnameinfo((struct sockaddr*)&sin, sizeof(sin),
                   host, sizeof(host), serv, sizeof(serv),
                   NI_NUMERICHOST|NI_WITHSCOPEID|NI_NUMERICSERV))
     return 1;
   return 0;
}

Why the hell may it fail?!  The only possible explanation I
see is that same NI_WITHSCOPEID which may be unsupported on
solaris...

And 3rd, when going this route, you forgot about the logging
code as i mentioned above.  Note again that it just should not
fail, period - what to log if we wasn't able to translate
long integer into dotted-quad?  Commit suicide due to abnormal
system environment? ;)

Please try the code w/o NI_WITHSCOPEID.. if you don't know
already what it does... ;)  It seems this should fix the
problem.

> Thanks [for rbldnsd] ;)

You're welcome.
But I wish we where living in a world where such a software
will not be useful... ;)

/mjt



More information about the rbldnsd mailing list