andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone

Blame SOURCES/0003-Ticket-49361-Use-IPv6-friendly-network-functions.patch

232633
From a652ff67c89888a61ce3da7cc55c45fb1f63cf7f Mon Sep 17 00:00:00 2001
232633
From: Mark Reynolds <mreynolds@redhat.com>
232633
Date: Thu, 30 May 2019 16:52:58 -0400
232633
Subject: [PATCH] Ticket 49361 - Use IPv6 friendly network functions
232633
232633
Description:  We use these functions that are not reliable with IPv6:
232633
232633
                 - gethostbyname()
232633
                 - inet_ntoa()
232633
                 - inet_aton()
232633
                 - inet_addr()
232633
232633
              This patch replaces these calls using one of the following
232633
              preferred functions:
232633
232633
                  - inet_ntop()
232633
                  - inet_pton()
232633
232633
              Also fixed a few failures in the replication CI test
232633
              regression_test.py as replication uses code touched by this
232633
              patch.
232633
232633
ASAN approved
232633
232633
https://pagure.io/389-ds-base/issue/49361
232633
232633
Reviewed by: firstyear(Thanks!)
232633
---
232633
 Makefile.am                                   |   2 -
232633
 configure.ac                                  |   2 +-
232633
 .../suites/replication/regression_test.py     |  53 ++++---
232633
 include/base/util.h                           |   3 -
232633
 ldap/include/portable.h                       |  50 ------
232633
 ldap/servers/slapd/connection.c               |  70 +++++----
232633
 ldap/servers/slapd/localhost.c                |  61 ++++----
232633
 ldap/servers/slapd/tools/ldclt/repcheck.c     |  30 +++-
232633
 ldap/servers/slapd/tools/ldclt/repslave.c     |  25 ++-
232633
 lib/base/dns.cpp                              | 142 ------------------
232633
 lib/base/net.cpp                              |  66 --------
232633
 11 files changed, 134 insertions(+), 370 deletions(-)
232633
 delete mode 100644 lib/base/dns.cpp
232633
 delete mode 100644 lib/base/net.cpp
232633
232633
diff --git a/Makefile.am b/Makefile.am
232633
index de9e0c460..c23686ea3 100644
232633
--- a/Makefile.am
232633
+++ b/Makefile.am
232633
@@ -1260,12 +1260,10 @@ libns_dshttpd_la_SOURCES = lib/libaccess/access_plhash.cpp \
232633
 	lib/libadmin/template.c \
232633
 	lib/libadmin/util.c \
232633
 	lib/base/crit.cpp \
232633
-	lib/base/dns.cpp \
232633
 	lib/base/dnsdmain.cpp \
232633
 	lib/base/ereport.cpp \
232633
 	lib/base/file.cpp \
232633
 	lib/base/fsmutex.cpp \
232633
-	lib/base/net.cpp \
232633
 	lib/base/nscperror.c \
232633
 	lib/base/plist.cpp \
232633
 	lib/base/pool.cpp \
232633
diff --git a/configure.ac b/configure.ac
232633
index d329e84a9..0cc36fabe 100644
232633
--- a/configure.ac
232633
+++ b/configure.ac
232633
@@ -76,7 +76,7 @@ AC_FUNC_STAT
232633
 AC_FUNC_STRERROR_R
232633
 AC_FUNC_STRFTIME
232633
 AC_FUNC_VPRINTF
232633
-AC_CHECK_FUNCS([endpwent ftruncate getcwd gethostbyname inet_ntoa localtime_r memmove memset mkdir munmap putenv rmdir setrlimit socket strcasecmp strchr strcspn strdup strerror strncasecmp strpbrk strrchr strstr strtol tzset])
232633
+AC_CHECK_FUNCS([endpwent ftruncate getcwd getaddrinfo inet_pton inet_ntop localtime_r memmove memset mkdir munmap putenv rmdir setrlimit socket strcasecmp strchr strcspn strdup strerror strncasecmp strpbrk strrchr strstr strtol tzset])
232633
 
232633
 # These functions are *required* without option.
232633
 AC_CHECK_FUNCS([clock_gettime], [], AC_MSG_ERROR([unable to locate required symbol clock_gettime]))
232633
diff --git a/dirsrvtests/tests/suites/replication/regression_test.py b/dirsrvtests/tests/suites/replication/regression_test.py
232633
index cf34a1a6a..830ef63ab 100644
232633
--- a/dirsrvtests/tests/suites/replication/regression_test.py
232633
+++ b/dirsrvtests/tests/suites/replication/regression_test.py
232633
@@ -13,11 +13,9 @@ from lib389.idm.user import TEST_USER_PROPERTIES, UserAccounts
232633
 from lib389.utils import *
232633
 from lib389.topologies import topology_m2 as topo_m2, TopologyMain, topology_m3 as topo_m3, create_topology, _remove_ssca_db
232633
 from lib389._constants import *
232633
-from . import get_repl_entries
232633
 from lib389.idm.organizationalunit import OrganizationalUnits
232633
 from lib389.agreement import Agreements
232633
 from lib389.idm.user import UserAccount
232633
-from lib389 import Entry
232633
 from lib389.idm.group import Groups, Group
232633
 from lib389.replica import Replicas, ReplicationManager
232633
 from lib389.changelog import Changelog5
232633
@@ -40,6 +38,7 @@ else:
232633
     logging.getLogger(__name__).setLevel(logging.INFO)
232633
 log = logging.getLogger(__name__)
232633
 
232633
+
232633
 def find_start_location(file, no):
232633
     log_pattern = re.compile("slapd_daemon - slapd started.")
232633
     count = 0
232633
@@ -59,7 +58,7 @@ def find_start_location(file, no):
232633
 def pattern_errorlog(file, log_pattern, start_location=0):
232633
 
232633
     count = 0
232633
-    log.debug("_pattern_errorlog: start from the beginning" )
232633
+    log.debug("_pattern_errorlog: start from the beginning")
232633
     file.seek(start_location)
232633
 
232633
     # Use a while true iteration because 'for line in file: hit a
232633
@@ -76,6 +75,7 @@ def pattern_errorlog(file, log_pattern, start_location=0):
232633
     log.debug("_pattern_errorlog: complete (count=%d)" % count)
232633
     return count
232633
 
232633
+
232633
 def _move_ruv(ldif_file):
232633
     """ Move RUV entry in an ldif file to the top"""
232633
 
232633
@@ -108,16 +108,13 @@ def topo_with_sigkill(request):
232633
         subprocess.Popen(cmd, stdout=subprocess.PIPE)
232633
 
232633
     def fin():
232633
+        # Kill the hanging process at the end of test to prevent failures in the following tests
232633
         if DEBUGGING:
232633
-            # Kill the hanging process at the end of test to prevent failures in the following tests
232633
             [_kill_ns_slapd(inst) for inst in topology]
232633
-            #[inst.stop() for inst in topology]
232633
         else:
232633
-            # Kill the hanging process at the end of test to prevent failures in the following tests
232633
             [_kill_ns_slapd(inst) for inst in topology]
232633
             assert _remove_ssca_db(topology)
232633
             [inst.delete() for inst in topology if inst.exists()]
232633
-
232633
     request.addfinalizer(fin)
232633
 
232633
     return topology
232633
@@ -167,6 +164,7 @@ def test_double_delete(topo_m2, create_entry):
232633
     repl.test_replication(m1, m2)
232633
     repl.test_replication(m2, m1)
232633
 
232633
+
232633
 @pytest.mark.bz1506831
232633
 def test_repl_modrdn(topo_m2):
232633
     """Test that replicated MODRDN does not break replication
232633
@@ -228,10 +226,10 @@ def test_repl_modrdn(topo_m2):
232633
     topo_m2.pause_all_replicas()
232633
 
232633
     log.info("Apply modrdn to M1 - move test user from OU A -> C")
232633
-    master1.rename_s(tuser_A.dn,'uid=testuser1',newsuperior=OU_C.dn,delold=1)
232633
+    master1.rename_s(tuser_A.dn, 'uid=testuser1', newsuperior=OU_C.dn, delold=1)
232633
 
232633
     log.info("Apply modrdn on M2 - move test user from OU B -> C")
232633
-    master2.rename_s(tuser_B.dn,'uid=testuser1',newsuperior=OU_C.dn,delold=1)
232633
+    master2.rename_s(tuser_B.dn, 'uid=testuser1', newsuperior=OU_C.dn, delold=1)
232633
 
232633
     log.info("Start Replication")
232633
     topo_m2.resume_all_replicas()
232633
@@ -252,7 +250,6 @@ def test_repl_modrdn(topo_m2):
232633
     repl.test_replication(master2, master1)
232633
 
232633
 
232633
-
232633
 def test_password_repl_error(topo_m2, create_entry):
232633
     """Check that error about userpassword replication is properly logged
232633
 
232633
@@ -329,7 +326,7 @@ def test_invalid_agmt(topo_m2):
232633
             'cn': 'whatever',
232633
             'nsDS5ReplicaRoot': DEFAULT_SUFFIX,
232633
             'nsDS5ReplicaBindDN': 'cn=replication manager,cn=config',
232633
-            'nsDS5ReplicaBindMethod': 'simple' ,
232633
+            'nsDS5ReplicaBindMethod': 'simple',
232633
             'nsDS5ReplicaTransportInfo': 'LDAP',
232633
             'nsds5replicaTimeout': '5',
232633
             'description': "test agreement",
232633
@@ -344,6 +341,7 @@ def test_invalid_agmt(topo_m2):
232633
     repl.test_replication(m1, m2)
232633
     repl.test_replication(m2, m1)
232633
 
232633
+
232633
 def test_fetch_bindDnGroup(topo_m2):
232633
     """Check the bindDNGroup is fetched on first replication session
232633
 
232633
@@ -380,13 +378,13 @@ def test_fetch_bindDnGroup(topo_m2):
232633
     M2 = topo_m2.ms['master2']
232633
 
232633
     # Enable replication log level. Not really necessary
232633
-    M1.modify_s('cn=config',[(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', b'8192')])
232633
-    M2.modify_s('cn=config',[(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', b'8192')])
232633
+    M1.modify_s('cn=config', [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', b'8192')])
232633
+    M2.modify_s('cn=config', [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', b'8192')])
232633
 
232633
     # Create a group and a user
232633
     PEOPLE = "ou=People,%s" % SUFFIX
232633
     PASSWD = 'password'
232633
-    REPL_MGR_BOUND_DN='repl_mgr_bound_dn'
232633
+    REPL_MGR_BOUND_DN = 'repl_mgr_bound_dn'
232633
 
232633
     uid = REPL_MGR_BOUND_DN.encode()
232633
     users = UserAccounts(M1, PEOPLE, rdn=None)
232633
@@ -396,14 +394,12 @@ def test_fetch_bindDnGroup(topo_m2):
232633
 
232633
     groups_M1 = Groups(M1, DEFAULT_SUFFIX)
232633
     group_properties = {
232633
-        'cn' : 'group1',
232633
-        'description' : 'testgroup'}
232633
+        'cn': 'group1',
232633
+        'description': 'testgroup'}
232633
     group_M1 = groups_M1.create(properties=group_properties)
232633
     group_M2 = Group(M2, group_M1.dn)
232633
     assert(not group_M1.is_member(create_user.dn))
232633
 
232633
-
232633
-
232633
     # Check that M1 and M2 are in sync
232633
     repl = ReplicationManager(DEFAULT_SUFFIX)
232633
     repl.wait_for_replication(M1, M2, timeout=20)
232633
@@ -414,13 +410,11 @@ def test_fetch_bindDnGroup(topo_m2):
232633
     replica.apply_mods([(ldap.MOD_REPLACE, 'nsDS5ReplicaBindDnGroupCheckInterval', '60'),
232633
                         (ldap.MOD_REPLACE, 'nsDS5ReplicaBindDnGroup', group_M1.dn)])
232633
 
232633
-
232633
     replicas = Replicas(M2)
232633
     replica = replicas.list()[0]
232633
     replica.apply_mods([(ldap.MOD_REPLACE, 'nsDS5ReplicaBindDnGroupCheckInterval', '60'),
232633
                         (ldap.MOD_REPLACE, 'nsDS5ReplicaBindDnGroup', group_M1.dn)])
232633
 
232633
-
232633
     # Then pause the replication agreement to prevent them trying to acquire
232633
     # while the user is not member of the group
232633
     topo_m2.pause_all_replicas()
232633
@@ -432,7 +426,6 @@ def test_fetch_bindDnGroup(topo_m2):
232633
         agmt.replace('nsDS5ReplicaBindDN', create_user.dn.encode())
232633
         agmt.replace('nsds5ReplicaCredentials', PASSWD.encode())
232633
 
232633
-
232633
     # Key step
232633
     # The restart will fetch the group/members define in the replica
232633
     #
232633
@@ -451,8 +444,8 @@ def test_fetch_bindDnGroup(topo_m2):
232633
     topo_m2.resume_all_replicas()
232633
 
232633
     # trigger updates to be sure to have a replication session, giving some time
232633
-    M1.modify_s(create_user.dn,[(ldap.MOD_ADD, 'description', b'value_1_1')])
232633
-    M2.modify_s(create_user.dn,[(ldap.MOD_ADD, 'description', b'value_2_2')])
232633
+    M1.modify_s(create_user.dn, [(ldap.MOD_ADD, 'description', b'value_1_1')])
232633
+    M2.modify_s(create_user.dn, [(ldap.MOD_ADD, 'description', b'value_2_2')])
232633
     time.sleep(10)
232633
 
232633
     # Check replication is working
232633
@@ -494,12 +487,13 @@ def test_fetch_bindDnGroup(topo_m2):
232633
     count = pattern_errorlog(errorlog_M1, regex, start_location=restart_location_M1)
232633
     assert(count <= 1)
232633
     count = pattern_errorlog(errorlog_M2, regex, start_location=restart_location_M2)
232633
-    assert(count <=1)
232633
+    assert(count <= 1)
232633
 
232633
     if DEBUGGING:
232633
         # Add debugging steps(if any)...
232633
         pass
232633
 
232633
+
232633
 def test_cleanallruv_repl(topo_m3):
232633
     """Test that cleanallruv could not break replication if anchor csn in ruv originated in deleted replica
232633
     :id: 46faba9a-897e-45b8-98dc-aec7fa8cec9a
232633
@@ -546,7 +540,7 @@ def test_cleanallruv_repl(topo_m3):
232633
     user_props = TEST_USER_PROPERTIES.copy()
232633
 
232633
     user_props.update({'uid': "testuser10"})
232633
-    user10 =  users_m1.create(properties=user_props)
232633
+    user10 = users_m1.create(properties=user_props)
232633
 
232633
     user_props.update({'uid': "testuser20"})
232633
     user20 = users_m2.create(properties=user_props)
232633
@@ -587,7 +581,7 @@ def test_cleanallruv_repl(topo_m3):
232633
     # ClearRuv is launched but with Force
232633
     M3.stop()
232633
     M1.tasks.cleanAllRUV(suffix=SUFFIX, replicaid='3',
232633
-                        force=True,args={TASK_WAIT: False})
232633
+                         force=True, args={TASK_WAIT: False})
232633
 
232633
     # here M1 should clear 31
232633
     M2.start()
232633
@@ -595,11 +589,16 @@ def test_cleanallruv_repl(topo_m3):
232633
     M1.agreement.resume(m1_m2[0].dn)
232633
     time.sleep(10)
232633
 
232633
-    #Check the users after CleanRUV
232633
+    # Check the users after CleanRUV
232633
     expected_m1_users = [user31.dn, user11.dn, user21.dn, user32.dn, user33.dn, user12.dn]
232633
+    expected_m1_users = [x.lower() for x in expected_m1_users]
232633
     expected_m2_users = [user31.dn, user11.dn, user21.dn, user12.dn]
232633
+    expected_m2_users = [x.lower() for x in expected_m2_users]
232633
+
232633
     current_m1_users = [user.dn for user in users_m1.list()]
232633
+    current_m1_users = [x.lower() for x in current_m1_users]
232633
     current_m2_users = [user.dn for user in users_m2.list()]
232633
+    current_m2_users = [x.lower() for x in current_m2_users]
232633
 
232633
     assert set(expected_m1_users).issubset(current_m1_users)
232633
     assert set(expected_m2_users).issubset(current_m2_users)
232633
diff --git a/include/base/util.h b/include/base/util.h
232633
index 94506d5e0..8ad5ddfbb 100644
232633
--- a/include/base/util.h
232633
+++ b/include/base/util.h
232633
@@ -36,8 +36,6 @@
232633
 
232633
 NSPR_BEGIN_EXTERN_C
232633
 
232633
-NSAPI_PUBLIC char *INTutil_hostname(void);
232633
-
232633
 NSAPI_PUBLIC int INTutil_itoa(int i, char *a);
232633
 
232633
 NSAPI_PUBLIC
232633
@@ -75,7 +73,6 @@ NSAPI_PUBLIC int INTutil_strncasecmp(CASECMPARG_T char *one, CASECMPARG_T char *
232633
 
232633
 NSPR_END_EXTERN_C
232633
 
232633
-#define util_hostname INTutil_hostname
232633
 #define util_itoa INTutil_itoa
232633
 #define util_vsprintf INTutil_vsprintf
232633
 #define util_sprintf INTutil_sprintf
232633
diff --git a/ldap/include/portable.h b/ldap/include/portable.h
232633
index 63cc4d461..fddc9c80e 100644
232633
--- a/ldap/include/portable.h
232633
+++ b/ldap/include/portable.h
232633
@@ -241,30 +241,9 @@ int strncasecmp(const char *, const char *, size_t);
232633
 #endif /* SNI || LINUX1_2 */
232633
 
232633
 #if defined(_WINDOWS) || defined(macintosh)
232633
-#define GETHOSTBYNAME(n, r, b, l, e) gethostbyname(n)
232633
 #define CTIME(c, b, l) ctime(c)
232633
 #define STRTOK(s1, s2, l) strtok(s1, s2)
232633
 #else /* UNIX */
232633
-#if defined(sgi) || defined(HPUX9) || defined(LINUX1_2) || defined(SCOOS) || \
232633
-    defined(UNIXWARE) || defined(SUNOS4) || defined(SNI) || defined(BSDI) || \
232633
-    defined(NCR) || defined(OSF1) || defined(NEC) ||                         \
232633
-    (defined(HPUX10) && !defined(_REENTRANT)) || defined(HPUX11) ||          \
232633
-    defined(UnixWare) || defined(LINUX) || defined(__FreeBSD__)
232633
-#define GETHOSTBYNAME(n, r, b, l, e) gethostbyname(n)
232633
-#elif defined(AIX)
232633
-#define GETHOSTBYNAME_BUF_T struct hostent_data
232633
-#define GETHOSTBYNAME(n, r, b, l, e) \
232633
-    (memset(&b, 0, l), gethostbyname_r(n, r, &b) ? NULL : r)
232633
-#elif defined(HPUX10)
232633
-#define GETHOSTBYNAME_BUF_T struct hostent_data
232633
-#define GETHOSTBYNAME(n, r, b, l, e) nsldapi_compat_gethostbyname_r(n, r, (char *)&b, l, e)
232633
-#else
232633
-#include <stdio.h> /* BUFSIZ */
232633
-typedef char GETHOSTBYNAME_buf_t[BUFSIZ /* XXX might be too small */];
232633
-#define GETHOSTBYNAME_BUF_T GETHOSTBYNAME_buf_t
232633
-#define GETHOSTBYNAME(n, r, b, l, e) gethostbyname_r(n, r, b, l, e)
232633
-#endif
232633
-
232633
 /*
232633
  * XXXmcs: GETHOSTBYADDR() is only defined for IRIX/SGI and Solaris for now.
232633
  */
232633
@@ -319,35 +298,6 @@ extern char *strdup();
232633
 #include <arpa/inet.h> /* for inet_addr() */
232633
 #endif                 /* SOLARIS */
232633
 
232633
-#ifdef SUNOS4
232633
-#include <pcfs/pc_dir.h> /* for toupper() */
232633
-int fprintf(FILE *, char *, ...);
232633
-int fseek(FILE *, long, int);
232633
-int fread(char *, int, int, FILE *);
232633
-int fclose(FILE *);
232633
-int fflush(FILE *);
232633
-int rewind(FILE *);
232633
-void *memmove(void *, const void *, size_t);
232633
-int strcasecmp(char *, char *);
232633
-int strncasecmp(char *, char *, int);
232633
-time_t time(time_t *);
232633
-void perror(char *);
232633
-int fputc(char, FILE *);
232633
-int fputs(char *, FILE *);
232633
-int LDAP_CALL re_exec(char *);
232633
-int socket(int, int, int);
232633
-void bzero(char *, int);
232633
-unsigned long inet_addr(char *);
232633
-char *inet_ntoa(struct in_addr);
232633
-int getdtablesize();
232633
-int connect(int, struct sockaddr *, int);
232633
-#endif /* SUNOS4 */
232633
-
232633
-/* #if defined(SUNOS4) || defined(SNI) */
232633
-#if defined(SUNOS4)
232633
-int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
232633
-#endif /* SUNOS4 || SNI */
232633
-
232633
 /*
232633
  * SAFEMEMCPY is an overlap-safe copy from s to d of n bytes
232633
  */
232633
diff --git a/ldap/servers/slapd/connection.c b/ldap/servers/slapd/connection.c
232633
index 1dc53434c..4a611e7f4 100644
232633
--- a/ldap/servers/slapd/connection.c
232633
+++ b/ldap/servers/slapd/connection.c
232633
@@ -244,6 +244,28 @@ connection_cleanup(Connection *conn)
232633
     conn->c_ns_close_jobs = 0;
232633
 }
232633
 
232633
+static char *
232633
+get_ip_str(struct sockaddr *addr, char *str)
232633
+{
232633
+    switch(addr->sa_family) {
232633
+        case AF_INET:
232633
+            if (sizeof(str) < INET_ADDRSTRLEN) {
232633
+                break;
232633
+            }
232633
+            inet_ntop(AF_INET, &(((struct sockaddr_in *)addr)->sin_addr), str, INET_ADDRSTRLEN);
232633
+            break;
232633
+
232633
+        case AF_INET6:
232633
+            if (sizeof(str) < INET6_ADDRSTRLEN) {
232633
+                break;
232633
+            }
232633
+            inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)addr)->sin6_addr), str, INET6_ADDRSTRLEN);
232633
+            break;
232633
+    }
232633
+
232633
+    return str;
232633
+}
232633
+
232633
 /*
232633
  * Callers of connection_reset() must hold the conn->c_mutex lock.
232633
  */
232633
@@ -252,7 +274,8 @@ connection_reset(Connection *conn, int ns, PRNetAddr *from, int fromLen __attrib
232633
 {
232633
     char *pTmp = is_SSL ? "SSL " : "";
232633
     char *str_ip = NULL, *str_destip;
232633
-    char buf_ip[256], buf_destip[256];
232633
+    char buf_ip[INET6_ADDRSTRLEN + 1] = {0};
232633
+    char buf_destip[INET6_ADDRSTRLEN + 1] = {0};
232633
     char *str_unknown = "unknown";
232633
     int in_referral_mode = config_check_referral_mode();
232633
 
232633
@@ -288,10 +311,10 @@ connection_reset(Connection *conn, int ns, PRNetAddr *from, int fromLen __attrib
232633
                 (from->ipv6.ip.pr_s6_addr32[1] != 0) ||
232633
                 (from->ipv6.ip.pr_s6_addr32[2] != 0) ||
232633
                 (from->ipv6.ip.pr_s6_addr32[3] != 0)) ||
232633
-               ((conn->c_prfd != NULL) && (PR_GetPeerName(conn->c_prfd, from) == 0))) {
232633
+               ((conn->c_prfd != NULL) && (PR_GetPeerName(conn->c_prfd, from) == 0)))
232633
+    {
232633
         conn->cin_addr = (PRNetAddr *)slapi_ch_malloc(sizeof(PRNetAddr));
232633
         memcpy(conn->cin_addr, from, sizeof(PRNetAddr));
232633
-
232633
         if (PR_IsNetAddrType(conn->cin_addr, PR_IpAddrV4Mapped)) {
232633
             PRNetAddr v4addr = {{0}};
232633
             v4addr.inet.family = PR_AF_INET;
232633
@@ -305,7 +328,7 @@ connection_reset(Connection *conn, int ns, PRNetAddr *from, int fromLen __attrib
232633
     } else {
232633
         /* try syscall since "from" was not given and PR_GetPeerName failed */
232633
         /* a corner case */
232633
-        struct sockaddr_in addr = {0}; /* assuming IPv4 */
232633
+        struct sockaddr addr = {0};
232633
 #if (defined(hpux))
232633
         int addrlen;
232633
 #else
232633
@@ -315,23 +338,15 @@ connection_reset(Connection *conn, int ns, PRNetAddr *from, int fromLen __attrib
232633
         addrlen = sizeof(addr);
232633
 
232633
         if ((conn->c_prfd == NULL) &&
232633
-            (getpeername(conn->c_sd, (struct sockaddr *)&addr, &addrlen) == 0)) {
232633
+            (getpeername(conn->c_sd, (struct sockaddr *)&addr, &addrlen) == 0))
232633
+        {
232633
             conn->cin_addr = (PRNetAddr *)slapi_ch_malloc(sizeof(PRNetAddr));
232633
             memset(conn->cin_addr, 0, sizeof(PRNetAddr));
232633
             PR_NetAddrFamily(conn->cin_addr) = AF_INET6;
232633
             /* note: IPv4-mapped IPv6 addr does not work on Windows */
232633
-            PR_ConvertIPv4AddrToIPv6(addr.sin_addr.s_addr, &(conn->cin_addr->ipv6.ip));
232633
-            PRLDAP_SET_PORT(conn->cin_addr, addr.sin_port);
232633
-
232633
-            /* copy string equivalent of address into a buffer to use for
232633
-             * logging since each call to inet_ntoa() returns a pointer to a
232633
-             * single thread-specific buffer (which prevents us from calling
232633
-             * inet_ntoa() twice in one call to slapi_log_access()).
232633
-             */
232633
-            str_ip = inet_ntoa(addr.sin_addr);
232633
-            strncpy(buf_ip, str_ip, sizeof(buf_ip) - 1);
232633
-            buf_ip[sizeof(buf_ip) - 1] = '\0';
232633
-            str_ip = buf_ip;
232633
+            PR_ConvertIPv4AddrToIPv6(((struct sockaddr_in *)&addr)->sin_addr.s_addr, &(conn->cin_addr->ipv6.ip));
232633
+            PRLDAP_SET_PORT(conn->cin_addr, ((struct sockaddr_in *)&addr)->sin_port);
232633
+            str_ip = get_ip_str(&addr, buf_ip);
232633
         } else {
232633
             str_ip = str_unknown;
232633
         }
232633
@@ -367,38 +382,27 @@ connection_reset(Connection *conn, int ns, PRNetAddr *from, int fromLen __attrib
232633
     } else {
232633
         /* try syscall since c_prfd == NULL */
232633
         /* a corner case */
232633
-        struct sockaddr_in destaddr = {0}; /* assuming IPv4 */
232633
+        struct sockaddr destaddr = {0}; /* assuming IPv4 */
232633
 #if (defined(hpux))
232633
         int destaddrlen;
232633
 #else
232633
         socklen_t destaddrlen;
232633
 #endif
232633
-
232633
         destaddrlen = sizeof(destaddr);
232633
 
232633
-        if ((getsockname(conn->c_sd, (struct sockaddr *)&destaddr, &destaddrlen) == 0)) {
232633
+        if ((getsockname(conn->c_sd, &destaddr, &destaddrlen) == 0)) {
232633
             conn->cin_destaddr = (PRNetAddr *)slapi_ch_malloc(sizeof(PRNetAddr));
232633
             memset(conn->cin_destaddr, 0, sizeof(PRNetAddr));
232633
             PR_NetAddrFamily(conn->cin_destaddr) = AF_INET6;
232633
-            PRLDAP_SET_PORT(conn->cin_destaddr, destaddr.sin_port);
232633
+            PRLDAP_SET_PORT(conn->cin_destaddr, ((struct sockaddr_in *)&destaddr)->sin_port);
232633
             /* note: IPv4-mapped IPv6 addr does not work on Windows */
232633
-            PR_ConvertIPv4AddrToIPv6(destaddr.sin_addr.s_addr, &(conn->cin_destaddr->ipv6.ip));
232633
-
232633
-            /* copy string equivalent of address into a buffer to use for
232633
-             * logging since each call to inet_ntoa() returns a pointer to a
232633
-             * single thread-specific buffer (which prevents us from calling
232633
-             * inet_ntoa() twice in one call to slapi_log_access()).
232633
-             */
232633
-            str_destip = inet_ntoa(destaddr.sin_addr);
232633
-            strncpy(buf_destip, str_destip, sizeof(buf_destip) - 1);
232633
-            buf_destip[sizeof(buf_destip) - 1] = '\0';
232633
-            str_destip = buf_destip;
232633
+            PR_ConvertIPv4AddrToIPv6(((struct sockaddr_in *)&destaddr)->sin_addr.s_addr, &(conn->cin_destaddr->ipv6.ip));
232633
+            str_destip = get_ip_str(&destaddr, buf_destip);
232633
         } else {
232633
             str_destip = str_unknown;
232633
         }
232633
     }
232633
 
232633
-
232633
     if (!in_referral_mode) {
232633
         /* create a sasl connection */
232633
         ids_sasl_server_new(conn);
232633
diff --git a/ldap/servers/slapd/localhost.c b/ldap/servers/slapd/localhost.c
232633
index f2aff28f4..993143cbd 100644
232633
--- a/ldap/servers/slapd/localhost.c
232633
+++ b/ldap/servers/slapd/localhost.c
232633
@@ -17,6 +17,7 @@
232633
 #include <string.h>
232633
 #include <sys/param.h>
232633
 #include <sys/socket.h>
232633
+#include <netdb.h>
232633
 #include <netinet/in.h>
232633
 #include <arpa/inet.h>
232633
 #include <netdb.h>
232633
@@ -45,22 +46,14 @@
232633
 static char *
232633
 find_localhost_DNS(void)
232633
 {
232633
-    /* This implementation could (and should) be entirely replaced by:
232633
-       dns_ip2host ("127.0.0.1", 1); defined in ldapserver/lib/base/dns.c
232633
-     */
232633
     char hostname[MAXHOSTNAMELEN + 1];
232633
-    struct hostent *hp;
232633
-#ifdef GETHOSTBYNAME_BUF_T
232633
-    struct hostent hent;
232633
-    GETHOSTBYNAME_BUF_T hbuf;
232633
-    int err;
232633
-#endif
232633
-    char **alias;
232633
     FILE *f;
232633
     char *cp;
232633
     char *domain;
232633
     char line[MAXHOSTNAMELEN + 8];
232633
-
232633
+    int gai_result;
232633
+    struct addrinfo hints = {0};
232633
+    struct addrinfo *info = NULL, *p = NULL;
232633
     if (gethostname(hostname, MAXHOSTNAMELEN)) {
232633
         int oserr = errno;
232633
 
232633
@@ -69,32 +62,34 @@ find_localhost_DNS(void)
232633
                       oserr, slapd_system_strerror(oserr));
232633
         return NULL;
232633
     }
232633
-    hp = GETHOSTBYNAME(hostname, &hent, hbuf, sizeof(hbuf), &err;;
232633
-    if (hp == NULL) {
232633
-        int oserr = errno;
232633
 
232633
-        slapi_log_err(SLAPI_LOG_ERR,
232633
-                      "find_localhost_DNS - gethostbyname(\"%s\") failed, error %d (%s)\n",
232633
-                      hostname, oserr, slapd_system_strerror(oserr));
232633
-        return NULL;
232633
-    }
232633
-    if (hp->h_name == NULL) {
232633
+    hints.ai_family = AF_UNSPEC;
232633
+    hints.ai_socktype = SOCK_STREAM;
232633
+    hints.ai_flags = AI_CANONNAME;
232633
+    if ((gai_result = getaddrinfo(hostname, NULL, &hints, &info)) != 0) {
232633
         slapi_log_err(SLAPI_LOG_ERR, "find_localhost_DNS",
232633
-                      "gethostbyname(\"%s\")->h_name == NULL\n", hostname);
232633
+                "getaddrinfo: %s\n", gai_strerror(gai_result));
232633
         return NULL;
232633
     }
232633
-    if (strchr(hp->h_name, '.') != NULL) {
232633
-        slapi_log_err(SLAPI_LOG_CONFIG, "find_localhost_DNS", "h_name == %s\n", hp->h_name);
232633
-        return slapi_ch_strdup(hp->h_name);
232633
-    } else if (hp->h_aliases != NULL) {
232633
-        for (alias = hp->h_aliases; *alias != NULL; ++alias) {
232633
-            if (strchr(*alias, '.') != NULL &&
232633
-                strncmp(*alias, hp->h_name, strlen(hp->h_name))) {
232633
-                slapi_log_err(SLAPI_LOG_CONFIG, "find_localhost_DNS", "h_alias == %s\n", *alias);
232633
-                return slapi_ch_strdup(*alias);
232633
-            }
232633
+
232633
+    if (strchr(info->ai_canonname, '.') != NULL) {
232633
+        char *return_name = slapi_ch_strdup(info->ai_canonname);
232633
+        freeaddrinfo(info);
232633
+        slapi_log_err(SLAPI_LOG_CONFIG, "find_localhost_DNS", "initial ai_canonname == %s\n", return_name);
232633
+        return return_name;
232633
+    }
232633
+    for(p = info; p != NULL; p = p->ai_next) {
232633
+        if (strchr(p->ai_canonname, '.') != NULL &&
232633
+            strncmp(p->ai_canonname, info->ai_canonname, strlen(info->ai_canonname)))
232633
+        {
232633
+            char *return_name = slapi_ch_strdup(p->ai_canonname);
232633
+            freeaddrinfo(info);
232633
+            slapi_log_err(SLAPI_LOG_CONFIG, "find_localhost_DNS", "next ai_canonname == %s\n", return_name);
232633
+            return return_name;
232633
         }
232633
     }
232633
+
232633
+
232633
     /* The following is copied from dns_guess_domain(),
232633
        in ldapserver/lib/base/dnsdmain.c */
232633
     domain = NULL;
232633
@@ -134,9 +129,10 @@ find_localhost_DNS(void)
232633
     }
232633
 #endif
232633
     if (domain == NULL) {
232633
+        freeaddrinfo(info);
232633
         return NULL;
232633
     }
232633
-    PL_strncpyz(hostname, hp->h_name, sizeof(hostname));
232633
+    PL_strncpyz(hostname, info->ai_canonname, sizeof(hostname));
232633
     if (domain[0] == '.')
232633
         ++domain;
232633
     if (domain[0]) {
232633
@@ -144,6 +140,7 @@ find_localhost_DNS(void)
232633
         PL_strcatn(hostname, sizeof(hostname), domain);
232633
     }
232633
     slapi_log_err(SLAPI_LOG_CONFIG, "find_localhost_DNS", "hostname == %s\n", hostname);
232633
+    freeaddrinfo(info);
232633
     return slapi_ch_strdup(hostname);
232633
 }
232633
 
232633
diff --git a/ldap/servers/slapd/tools/ldclt/repcheck.c b/ldap/servers/slapd/tools/ldclt/repcheck.c
232633
index 4340055e5..05ea65a8b 100644
232633
--- a/ldap/servers/slapd/tools/ldclt/repcheck.c
232633
+++ b/ldap/servers/slapd/tools/ldclt/repcheck.c
232633
@@ -19,6 +19,10 @@
232633
 #include "remote.h"
232633
 #include "lber.h"
232633
 #include "ldap.h"
232633
+#include <sys/types.h>
232633
+#include <sys/socket.h>
232633
+#include <netdb.h>
232633
+
232633
 
232633
 enum
232633
 {
232633
@@ -90,13 +94,15 @@ send_op(char *s, int sfd)
232633
 
232633
 main(int argc, char **argv)
232633
 {
232633
-    int i, port = 16000;
232633
-    int sockfd;
232633
+    struct sockaddr_in srvsaddr;
232633
     static char logline[512];
232633
     char **tmp;
232633
-    struct hostent *serveraddr;
232633
-    struct sockaddr_in srvsaddr;
232633
     char *p;
232633
+    struct addrinfo hints = {0};
232633
+    struct addrinfo *info = NULL;
232633
+    int gai_result = 0;
232633
+    int i, port = 16000;
232633
+    int sockfd;
232633
 
232633
     while ((i = getopt(argc, argv, "p:")) != EOF) {
232633
         switch (i) {
232633
@@ -105,15 +111,25 @@ main(int argc, char **argv)
232633
             break;
232633
         }
232633
     }
232633
-    serveraddr = gethostbyname(argv[optind]);
232633
-    srvsaddr.sin_addr.s_addr = htonl(*((u_long *)(serveraddr->h_addr_list[0])));
232633
+
232633
+    hints.ai_family = AF_UNSPEC;
232633
+    hints.ai_socktype = SOCK_STREAM;
232633
+    hints.ai_flags = AI_CANONNAME;
232633
+    if ((gai_result = getaddrinfo(argv[optind], NULL, &hints, &info)) != 0) {
232633
+        slapi_log_err(SLAPI_LOG_ERR, "ldclt",
232633
+                "getaddrinfo: %s\n", gai_strerror(gai_result));
232633
+        return NULL;
232633
+    }
232633
+
232633
+    srvsaddr.sin_addr.s_addr = htonl(*((u_long *)(info->ai_addr)));
232633
     srvsaddr.sin_family = AF_INET;
232633
     srvsaddr.sin_port = htons(port);
232633
+    freeaddrinfo(info);
232633
     maxop = npend = 0;
232633
     pendops = (Optype *)malloc(sizeof(Optype) * 20);
232633
     sigset(SIGPIPE, SIG_IGN);
232633
     while (fgets(logline, sizeof(logline), stdin)) {
232633
-        if (p = strchr(logline, '\n')) {
232633
+        if ((p = strchr(logline, '\n'))) {
232633
             *p = 0;
232633
         }
232633
         if (!connected) {
232633
diff --git a/ldap/servers/slapd/tools/ldclt/repslave.c b/ldap/servers/slapd/tools/ldclt/repslave.c
232633
index a04a73f5c..8df2a0ace 100644
232633
--- a/ldap/servers/slapd/tools/ldclt/repslave.c
232633
+++ b/ldap/servers/slapd/tools/ldclt/repslave.c
232633
@@ -62,6 +62,9 @@ dd/mm/yy | Author    | Comments
232633
 #include "remote.h"
232633
 #include "lber.h"
232633
 #include "ldap.h"
232633
+#include <sys/types.h>
232633
+#include <sys/socket.h>
232633
+#include <netdb.h>
232633
 
232633
 /*
232633
  * Enumeration for internal list
232633
@@ -221,7 +224,8 @@ main(int argc, char **argv)
232633
     int sockfd, log = 0;
232633
     static char logline[512];
232633
     char **tmp, *hn, *hp, *hf;
232633
-    struct hostent *serveraddr;
232633
+    struct addrinfo hints = {0};
232633
+    struct addrinfo *info = NULL;
232633
 
232633
     while ((i = getopt(argc, argv, "tdP:s:")) != EOF) {
232633
         switch (i) {
232633
@@ -251,12 +255,17 @@ main(int argc, char **argv)
232633
             /*
232633
              * Get master address, just the first.
232633
              */
232633
-            if ((serveraddr = gethostbyname(hn)) == NULL) {
232633
+
232633
+            hints.ai_family = AF_UNSPEC;
232633
+            hints.ai_socktype = SOCK_STREAM;
232633
+            hints.ai_flags = AI_CANONNAME;
232633
+            if (getaddrinfo(hn, NULL, &hints, &info) != 0) {
232633
                 printf("Unknown host %s\n", hn);
232633
                 break;
232633
             }
232633
+
232633
             srvlist = (Towho *)realloc(srvlist, (nsrv + 1) * sizeof(Towho));
232633
-            srvlist[nsrv].addr.sin_addr.s_addr = htonl(*((u_long *)(serveraddr->h_addr_list[0])));
232633
+            srvlist[nsrv].addr.sin_addr.s_addr = htonl(*((u_long *)(info->ai_addr)));
232633
             srvlist[nsrv].addr.sin_family = AF_INET;
232633
             srvlist[nsrv].addr.sin_port = htonl((hp == hf ? port : atoi(hp)));
232633
             if ((srvlist[nsrv].filter = regcmp(hf, NULL)) == NULL)
232633
@@ -264,6 +273,7 @@ main(int argc, char **argv)
232633
             srvlist[nsrv].fd = open_cnx((struct sockaddr *)&srvlist[nsrv].addr);
232633
             srvlist[nsrv].hname = strdup(hn);
232633
             nsrv++;
232633
+            freeaddrinfo(info);
232633
             break;
232633
         }
232633
     }
232633
@@ -273,18 +283,19 @@ main(int argc, char **argv)
232633
             printf("\t-t\tprints input on stdout.\n\t-d\tdebug mode.\n");
232633
             exit(1);
232633
         }
232633
-        srvlist = (Towho *)malloc(sizeof(Towho));
232633
-        if ((serveraddr = gethostbyname(argv[optind])) == NULL) {
232633
-            printf("Unknown host %s\n", argv[optind]);
232633
+        if (getaddrinfo(argv[optind], NULL, &hints, &info) != 0) {
232633
+            printf("Unknown host %s\n", hn);
232633
             exit(1);
232633
         }
232633
-        srvlist[nsrv].addr.sin_addr.s_addr = htonl(*((u_long *)(serveraddr->h_addr_list[0])));
232633
+        srvlist = (Towho *)malloc(sizeof(Towho));
232633
+        srvlist[nsrv].addr.sin_addr.s_addr = htonl(*((u_long *)(info->ai_addr)));
232633
         srvlist[nsrv].addr.sin_family = AF_INET;
232633
         srvlist[nsrv].addr.sin_port = htons(port);
232633
         srvlist[nsrv].filter = NULL;
232633
         srvlist[nsrv].fd = open_cnx((struct sockaddr *)&srvlist[nsrv].addr);
232633
         srvlist[nsrv].hname = strdup(argv[optind]);
232633
         nsrv++;
232633
+        freeaddrinfo(info);
232633
     }
232633
     maxop = npend = 0;
232633
     pendops = (Optype *)malloc(sizeof(Optype) * 20);
232633
diff --git a/lib/base/dns.cpp b/lib/base/dns.cpp
232633
deleted file mode 100644
232633
index e704094db..000000000
232633
--- a/lib/base/dns.cpp
232633
+++ /dev/null
232633
@@ -1,142 +0,0 @@
232633
-/** BEGIN COPYRIGHT BLOCK
232633
- * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
232633
- * Copyright (C) 2005 Red Hat, Inc.
232633
- * All rights reserved.
232633
- *
232633
- * License: GPL (version 3 or any later version).
232633
- * See LICENSE for details. 
232633
- * END COPYRIGHT BLOCK **/
232633
-
232633
-#ifdef HAVE_CONFIG_H
232633
-#  include <config.h>
232633
-#endif
232633
-
232633
-/*
232633
- * dns.c: DNS resolution routines
232633
- * 
232633
- * Rob McCool
232633
- */
232633
-#define DNS_GUESSING
232633
-
232633
-#include "netsite.h"
232633
-#include "systems.h"
232633
-
232633
-/* Under NT, these are taken care of by net.h including winsock.h */
232633
-#include <arpa/inet.h>  /* inet_ntoa */
232633
-#include <netdb.h>  /* struct hostent */
232633
-#ifdef NEED_GHN_PROTO
232633
-extern "C" int gethostname (char *name, size_t namelen);
232633
-#endif
232633
-#include <stdio.h>
232633
-#include <nspr.h>
232633
-
232633
-/* ---------------------------- dns_find_fqdn ----------------------------- */
232633
-
232633
-
232633
-/* defined in dnsdmain.c */
232633
-extern "C"  NSAPI_PUBLIC char *dns_guess_domain(char * hname);
232633
-
232633
-char *net_find_fqdn(PRHostEnt *p)
232633
-{
232633
-    int x;
232633
-
232633
-    if((!p->h_name) || (!p->h_aliases))
232633
-        return NULL;
232633
-
232633
-    if(!strchr(p->h_name, '.')) {
232633
-        for(x = 0; p->h_aliases[x]; ++x) {
232633
-            if((strchr(p->h_aliases[x], '.')) && 
232633
-               (!strncmp(p->h_aliases[x], p->h_name, strlen(p->h_name))))
232633
-            {
232633
-                return STRDUP(p->h_aliases[x]);
232633
-            }
232633
-        }
232633
-#ifdef DNS_GUESSING
232633
-	return dns_guess_domain(p->h_name);
232633
-#else
232633
-	return NULL;
232633
-#endif /* DNS_GUESSING */
232633
-    } 
232633
-    else 
232633
-        return STRDUP(p->h_name);
232633
-}
232633
-
232633
-
232633
-/* ----------------------------- dns_ip2host ------------------------------ */
232633
-
232633
-
232633
-char *dns_ip2host(char *ip, int verify)
232633
-{
232633
-    /*    struct in_addr iaddr;  */
232633
-    PRNetAddr iaddr;
232633
-    char *hn;
232633
-    static unsigned long laddr = 0;
232633
-    static char myhostname[256];
232633
-    PRHostEnt   hent;
232633
-    char        buf[PR_NETDB_BUF_SIZE];
232633
-    PRStatus    err;
232633
-
232633
-
232633
-    err = PR_InitializeNetAddr(PR_IpAddrNull, 0, &iaddr);
232633
-
232633
-	/* richm: ipv6 cleanup - use inet_aton or other more appropriate function
232633
-	   instead of inet_addr */
232633
-    if((iaddr.inet.ip = inet_addr(ip)) == (in_addr_t)-1)
232633
-        goto bong;
232633
-
232633
-    /*
232633
-     * See if it happens to be the localhost IP address, and try
232633
-     * the local host name if so.
232633
-     */
232633
-    if (laddr == 0) {
232633
-	laddr = inet_addr("127.0.0.1");
232633
-	myhostname[0] = 0;
232633
-	PR_GetSystemInfo(PR_SI_HOSTNAME, myhostname, sizeof(myhostname));
232633
-    }
232633
-
232633
-    /* Have to match the localhost IP address and have a hostname */
232633
-    if ((iaddr.inet.ip == laddr) && (myhostname[0] != 0)) {
232633
-        /*
232633
-         * Now try for a fully-qualified domain name, starting with
232633
-         * the local hostname.
232633
-         */
232633
-        err =  PR_GetHostByName(myhostname,
232633
-				buf,
232633
-				PR_NETDB_BUF_SIZE,
232633
-				&hent);
232633
-
232633
-        /* Don't verify if we get a fully-qualified name this way */
232633
-        verify = 0;
232633
-    }
232633
-    else {
232633
-      err = PR_GetHostByAddr(&iaddr, 
232633
-			     buf,
232633
-			     PR_NETDB_BUF_SIZE,
232633
-			     &hent);
232633
-    }
232633
-
232633
-    if ((err == PR_FAILURE) || !(hn = net_find_fqdn(&hent))) goto bong;
232633
-
232633
-
232633
-    if(verify) {
232633
-        char **haddr = 0;
232633
-       	err = PR_GetHostByName(hn,
232633
-			       buf,
232633
-			       PR_NETDB_BUF_SIZE,
232633
-			       &hent);
232633
- 
232633
-        if(err == PR_SUCCESS) {
232633
-            for(haddr = hent.h_addr_list; *haddr; haddr++) {
232633
-                if(((struct in_addr *)(*haddr))->s_addr == iaddr.inet.ip)
232633
-                    break;
232633
-            }
232633
-        }
232633
-
232633
-        if((err == PR_FAILURE) || (!(*haddr)))
232633
-            goto bong;
232633
-    }
232633
-
232633
-    return hn;
232633
-  bong:
232633
-    return NULL;
232633
-}
232633
diff --git a/lib/base/net.cpp b/lib/base/net.cpp
232633
deleted file mode 100644
232633
index 7227d9584..000000000
232633
--- a/lib/base/net.cpp
232633
+++ /dev/null
232633
@@ -1,66 +0,0 @@
232633
-/** BEGIN COPYRIGHT BLOCK
232633
- * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
232633
- * Copyright (C) 2005 Red Hat, Inc.
232633
- * All rights reserved.
232633
- *
232633
- * License: GPL (version 3 or any later version).
232633
- * See LICENSE for details. 
232633
- * END COPYRIGHT BLOCK **/
232633
-
232633
-#ifdef HAVE_CONFIG_H
232633
-#  include <config.h>
232633
-#endif
232633
-
232633
-/*
232633
- * net.c: sockets abstraction and DNS related things
232633
- * 
232633
- * Note: sockets created with net_socket are placed in non-blocking mode,
232633
- *       however this API simulates that the calls are blocking.
232633
- *
232633
- * Rob McCool
232633
- */
232633
-
232633
-
232633
-#include "netsite.h"
232633
-#include <nspr.h>
232633
-
232633
-#include "util.h"
232633
-#include <string.h>
232633
-#include <arpa/inet.h>  /* inet_ntoa */
232633
-#include <netdb.h>      /* hostent stuff */
232633
-#ifdef NEED_GHN_PROTO
232633
-extern "C" int gethostname (char *name, size_t namelen);
232633
-#endif
232633
-#ifdef LINUX
232633
-#include <sys/ioctl.h> /* ioctl */
232633
-#endif
232633
-
232633
-#include "libadmin/libadmin.h"
232633
-
232633
-/* ---------------------------- util_hostname ----------------------------- */
232633
-
232633
-
232633
-#include <sys/param.h>
232633
-
232633
-/* Defined in dns.cpp */
232633
-char *net_find_fqdn(PRHostEnt *p);
232633
-
232633
-NSAPI_PUBLIC char *util_hostname(void)
232633
-{
232633
-    char str[MAXHOSTNAMELEN];
232633
-    PRHostEnt   hent;
232633
-    char        buf[PR_NETDB_BUF_SIZE];
232633
-    PRStatus    err;
232633
-
232633
-    gethostname(str, MAXHOSTNAMELEN);
232633
-    err = PR_GetHostByName(
232633
-                str,
232633
-                buf,
232633
-                PR_NETDB_BUF_SIZE,
232633
-                &hent);
232633
-
232633
-    if (err == PR_FAILURE) 
232633
-        return NULL;
232633
-    return net_find_fqdn(&hent);
232633
-}
232633
-
232633
-- 
232633
2.21.0
232633