libreplace: Add tests for connect and gethostbyname.
authorMichael Adam <obnox@samba.org>
Tue, 26 Feb 2008 12:24:54 +0000 (13:24 +0100)
committerMichael Adam <obnox@samba.org>
Tue, 26 Feb 2008 15:41:09 +0000 (16:41 +0100)
Provide dummy replacements when a function isnt found.
The functions are also searched for in certain libraries,
and variables SOCKET_LIBS and NSL_LIBS are set accordingly.

One purpose of this is to fix the getifaddrs tests on
systems where e.g. the socket calls require special libs
for linking.

Michael
(This used to be commit 900d17acb95f1becfc46656a12c107336c027ef7)

source4/lib/replace/libreplace.m4
source4/lib/replace/replace.h
source4/lib/replace/socket.c [new file with mode: 0644]
source4/lib/replace/socket.m4 [new file with mode: 0644]
source4/lib/replace/system/network.h

index 2e0cd34f4ac6d5ac0d917713289c66c29ed30038..e0cc57f4c80c6cd340ae63d5dd9872516683d29b 100644 (file)
@@ -344,6 +344,7 @@ m4_include(getpass.m4)
 m4_include(strptime.m4)
 m4_include(win32.m4)
 m4_include(timegm.m4)
+m4_include(socket.m4)
 m4_include(inet_ntop.m4)
 m4_include(inet_pton.m4)
 m4_include(getaddrinfo.m4)
index 3f91544e9782f914c1d898ebf7b5c8f50da5b843..0d16f4ffd0a797ad6f959eb07612a6419a1b698b 100644 (file)
@@ -340,6 +340,16 @@ ssize_t rep_pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offset)
 /* prototype is in "system/network.h" */
 #endif
 
+#ifndef HAVE_CONNECT
+#define connect rep_connect
+/* prototype is in "system/network.h" */
+#endif
+
+#ifndef HAVE_GETHOSTBYNAME
+#define gethostbyname rep_gethostbyname
+/* prototype is in "system/network.h" */
+#endif
+
 #ifndef HAVE_GETIFADDRS
 #define getifaddrs rep_getifaddrs
 /* prototype is in "system/network.h" */
diff --git a/source4/lib/replace/socket.c b/source4/lib/replace/socket.c
new file mode 100644 (file)
index 0000000..35e975f
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Unix SMB/CIFS implementation.
+ *
+ * Dummy replacements for socket functions.
+ *
+ * Copyright (C) Michael Adam <obnox@samba.org> 2008
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "replace.h"
+#include "system/network.h"
+
+int rep_connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen)
+{
+       errno = ENOSYS;
+       return -1;
+}
+
+struct hostent *rep_gethostbyname(const char *name)
+{
+       errno = ENOSYS;
+       return NULL;
+}
diff --git a/source4/lib/replace/socket.m4 b/source4/lib/replace/socket.m4
new file mode 100644 (file)
index 0000000..c0c8f93
--- /dev/null
@@ -0,0 +1,40 @@
+dnl The following test is roughl taken from the cvs sources.
+dnl
+dnl If we can't find connect, try looking in -lsocket, -lnsl, and -linet.
+dnl The Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has
+dnl libsocket.so which has a bad implementation of gethostbyname (it
+dnl only looks in /etc/hosts), so we only look for -lsocket if we need
+dnl it.
+AC_CHECK_FUNCS(connect)
+if test x"$ac_cv_func_connect" = x"no"; then
+       AC_CHECK_LIB_EXT(nsl_s, SOCKET_LIBS, connect)
+       AC_CHECK_LIB_EXT(nsl, SOCKET_LIBS, connect)
+       AC_CHECK_LIB_EXT(socket, SOCKET_LIBS, connect)
+       AC_CHECK_LIB_EXT(inet, SOCKET_LIBS, connect)
+       dnl We can't just call AC_CHECK_FUNCS(connect) here,
+       dnl because the value has been cached.
+       if test x"$ac_cv_lib_ext_nsl_s_connect" = x"yes" ||
+               test x"$ac_cv_lib_ext_nsl_connect" = x"yes" ||
+               test x"$ac_cv_lib_ext_socket_connect" = x"yes" ||
+               test x"$ac_cv_lib_ext_inet_connect" = x"yes"
+       then
+               AC_DEFINE(HAVE_CONNECT,1,[Whether the system has connect()])
+       fi
+fi
+
+AC_CHECK_FUNCS(gethostbyname)
+if test x"$ac_cv_func_gethostbyname" = x"no"; then
+       AC_CHECK_LIB_EXT(nsl_s, NSL_LIBS, gethostbyname)
+       AC_CHECK_LIB_EXT(nsl, NSL_LIBS, gethostbyname)
+       AC_CHECK_LIB_EXT(socket, NSL_LIBS, gethostbyname)
+       dnl We can't just call AC_CHECK_FUNCS(gethostbyname) here,
+       dnl because the value has been cached.
+       if test x"$ac_cv_lib_ext_nsl_s_gethostbyname" = x"yes" ||
+               test x"$ac_cv_lib_ext_nsl_gethostbyname" = x"yes" ||
+               test x"$ac_cv_lib_ext_socket_gethostbyname" = x"yes"
+       then
+               AC_DEFINE(HAVE_GETHOSTBYNAME,1,
+                         [Whether the system has gethostbyname()])
+       fi
+fi
+
index a84b22e5d086ffc18345c6652f9074e125e48dd7..410c6d7cca2904d12e738c470cc90a6cc581a5ac 100644 (file)
@@ -103,6 +103,16 @@ int rep_inet_pton(int af, const char *src, void *dst);
 const char *rep_inet_ntop(int af, const void *src, char *dst, socklen_t size);
 #endif
 
+#ifndef HAVE_CONNECT
+/* define is in "replace.h" */
+int rep_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
+#endif
+
+#ifndef HAVE_GETHOSTBYNAME
+/* define is in "replace.h" */
+struct hostent *rep_gethostbyname(const char *name);
+#endif
+
 #ifdef HAVE_IFADDRS_H
 #include <ifaddrs.h>
 #endif