[reSIProcate] DnsUtils improvement
Hi there,
from ym own experiences with sipsak http://sipsak.org I would conclude that
the current implementation of DnsUtils::getLocalHostName will fail on many
*nix systems. Unfortunately the result of gethostname() hardly depends on the
configuration of the system.
The idea of the attached improvement is taken from the hostname binary
(net-tools 1.60).
Secondly IMHO the function getLocalDomainName is also more or less broken,
because on many systems getdomainname returns the NIS domain (which can be
any given string) if it returns anything at all. Should I provide a similar
fix for that, although it is currently not used anywhere?
At last a question: what is the reason that a DNS name is used in the
Record-Route headers of repro instead of the IP address like in the Via?
Besides for high availability scenarios I can not find any good argument for
inserting this extra DNS lookup step.
Regards
Nils
Index: DnsUtil.cxx
===================================================================
--- DnsUtil.cxx (revision 4501)
+++ DnsUtil.cxx (working copy)
@@ -7,6 +7,7 @@
#include <sys/ioctl.h>
#include <net/if.h>
#include <errno.h>
+#include <netdb.h>
#endif
#include <stdio.h>
@@ -44,6 +45,12 @@
throw Exception("could not find local hostname",__FILE__,__LINE__);
}
}
+ struct hostent* he;
+ if ((he = gethostbyname(buffer)) != NULL) {
+ if (strchr(he->h_name, '.') != NULL) {
+ strncpy(buffer, he->h_name, 256);
+ }
+ }
return Data(buffer);
}