- replace gethostbyname with getaddrinfo

This commit is contained in:
Tomas Smetana 2007-10-12 13:25:59 +00:00
parent b021c51f2e
commit 658bb27ff4
2 changed files with 44 additions and 1 deletions

View File

@ -0,0 +1,38 @@
--- smartmontools-5.37/smartd.cpp.addrinfo 2007-10-12 13:09:55.000000000 +0200
+++ smartmontools-5.37/smartd.cpp 2007-10-12 13:11:41.000000000 +0200
@@ -499,14 +499,28 @@
char* dnsdomain(const char* hostname) {
char *p = NULL;
#ifdef HAVE_GETHOSTBYNAME
- struct hostent *hp;
-
- if ((hp = gethostbyname(hostname))) {
- // Does this work if gethostbyname() returns an IPv6 name in
- // colon/dot notation? [BA]
- if ((p = strchr(hp->h_name, '.')))
- p++; // skip "."
+ /* This is a Fedora specific patch. We KNOW that there is getaddrinfo
+ * and getnameinfo. This part is not portable. */
+ static char canon_name[NI_MAXHOST];
+ struct addrinfo *info;
+ int err;
+
+ if (err = getaddrinfo(hostname, NULL, NULL, &info)) {
+ PrintOut(LOG_CRIT, "Error retrieving info for %s: %s\n",
+ hostname, gai_strerror(err));
+ return NULL;
+ }
+ canon_name[0] = '\0';
+ if (err = getnameinfo(info->ai_addr, sizeof(struct sockaddr),
+ canon_name, sizeof(canon_name), NULL, 0, 0)) {
+ PrintOut(LOG_CRIT, "Error retrieving name info for %s: %s\n",
+ hostname, gai_strerror(err));
+ return NULL;
}
+ freeaddrinfo(info);
+ p = canon_name;
+ if ((p = strchr(p, '.')))
+ p++;
#else
ARGUSED(hostname);
#endif

View File

@ -1,7 +1,7 @@
Summary: Tools for monitoring SMART capable hard disks
Name: smartmontools
Version: 5.37
Release: 6%{?dist}
Release: 7%{?dist}
Epoch: 1
Group: System Environment/Base
License: GPLv2+
@ -12,6 +12,7 @@ Source2: smartd-conf.py
Source3: smartmontools.sysconf
Patch1: smartmontools-5.37-cloexec.patch
Patch2: smartmontools-5.37-3ware.patch
Patch3: smartmontools-5.37-addrinfo.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-root
PreReq: /sbin/chkconfig /sbin/service
@ -41,6 +42,7 @@ the /etc/smartd.conf configuration file.
%setup -q
%patch1 -p1 -b .cloexec
%patch2 -p1 -b .3ware
%patch3 -p1 -b .addrinfo
%build
%configure
@ -91,6 +93,9 @@ exit 0
%exclude %{_sbindir}/smartd-conf.py[co]
%changelog
* Fri Oct 12 2007 Tomas Smetana <tsmetana@redhat.com> - 1:5.37-7
- replace gethostbyname with getaddrinfo
* Tue Sep 04 2007 Tomas Smetana <tsmetana@redhat.com> - 1:5.37-6
- fix #271741 - smartd-conf.py should allow customization of parameters
- fix #253753 - service starting by default, perhaps shouldn't