From 21fd0a0f6261fb511488e391349ecdb0bf93e12d Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Tue, 26 Jun 2001 07:44:02 +0000 Subject: Add check for working AF_LOCAL sockets, which are borken on RH7.0 with _LARGEFILE64_SOURCE, and probably not present on non-Unix systems like VMS. (This used to be commit 8b0a5bc436fb44f5123d037b102f2d2c4d3287e8) --- source3/tests/.cvsignore | 1 + source3/tests/unixsock.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 source3/tests/unixsock.c (limited to 'source3/tests') diff --git a/source3/tests/.cvsignore b/source3/tests/.cvsignore index e69de29bb2..b6c1f01120 100644 --- a/source3/tests/.cvsignore +++ b/source3/tests/.cvsignore @@ -0,0 +1 @@ +unixsock diff --git a/source3/tests/unixsock.c b/source3/tests/unixsock.c new file mode 100644 index 0000000000..f2765d68f6 --- /dev/null +++ b/source3/tests/unixsock.c @@ -0,0 +1,93 @@ +/* -*- c-file-style: "linux" -*- + * + * Try creating a Unix-domain socket, opening it, and reading from it. + * The POSIX name for these is AF_LOCAL/PF_LOCAL. + * + * This is used by the Samba autoconf scripts to detect systems which + * don't have Unix-domain sockets, such as (probably) VMS, or systems + * on which they are broken under some conditions, such as RedHat 7.0 + * (unpatched). We can't build WinBind there at the moment. + * + * Coding standard says to always use exit() for this, not return, so + * we do. + * + * Martin Pool , June 2000. */ + +/* TODO: Look for AF_LOCAL (most standard), AF_UNIX, and AF_FILE. */ + +#include + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif + +#ifdef HAVE_SYS_UN_H +# include +#endif + +#ifdef HAVE_SYS_TYPES_H +# include +#endif + +#if HAVE_SYS_WAIT_H +# include +#endif + +#if HAVE_ERRNO_DECL +# include +#else +extern int errno; +#endif + +static int bind_socket(char const *filename) +{ + int sock_fd; + struct sockaddr_un name; + size_t size; + + /* Create the socket. */ + if ((sock_fd = socket(PF_LOCAL, SOCK_STREAM, 0)) < 0) { + perror ("socket(PF_LOCAL, SOCK_STREAM)"); + exit(1); + } + + /* Bind a name to the socket. */ + name.sun_family = AF_LOCAL; + strncpy(name.sun_path, filename, sizeof (name.sun_path)); + + /* The size of the address is + the offset of the start of the filename, + plus its length, + plus one for the terminating null byte. + Alternatively you can just do: + size = SUN_LEN (&name); + */ + size = SUN_LEN(&name); + /* XXX: This probably won't work on unfriendly libcs */ + + if (bind(sock_fd, (struct sockaddr *) &name, size) < 0) { + perror ("bind"); + exit(1); + } + + return sock_fd; +} + + +int main(void) +{ + int sock_fd; + int kid; + char const *filename = "conftest.unixsock.sock"; + + /* abolish hanging */ + alarm(15); /* secs */ + + if ((sock_fd = bind_socket(filename)) < 0) + exit(1); + + /* the socket will be deleted when autoconf cleans up these + files. */ + + exit(0); +} -- cgit