diff options
author | Andrew Tridgell <tridge@samba.org> | 2003-08-13 01:53:07 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2003-08-13 01:53:07 +0000 |
commit | cc3a6ea9920f30925a678c566b4af417da6d455b (patch) | |
tree | 60015a1a5f4b47ac3d133bdbbe32b75815595d4d /source4/tests/unixsock.c | |
parent | 4d1f9d1def5bf5fea64722626028d94da49c654c (diff) | |
parent | ef2e26c91b80556af033d3335e55f5dfa6fff31d (diff) | |
download | samba-cc3a6ea9920f30925a678c566b4af417da6d455b.tar.gz samba-cc3a6ea9920f30925a678c566b4af417da6d455b.tar.bz2 samba-cc3a6ea9920f30925a678c566b4af417da6d455b.zip |
This commit was generated by cvs2svn to compensate for changes in r30,
which included commits to RCS files with non-trunk default branches.
(This used to be commit 3a69cffb062d4f1238b8cae10481c1f2ea4d3d8b)
Diffstat (limited to 'source4/tests/unixsock.c')
-rw-r--r-- | source4/tests/unixsock.c | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/source4/tests/unixsock.c b/source4/tests/unixsock.c new file mode 100644 index 0000000000..f2765d68f6 --- /dev/null +++ b/source4/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 <mbp@samba.org>, June 2000. */ + +/* TODO: Look for AF_LOCAL (most standard), AF_UNIX, and AF_FILE. */ + +#include <stdio.h> + +#ifdef HAVE_SYS_SOCKET_H +# include <sys/socket.h> +#endif + +#ifdef HAVE_SYS_UN_H +# include <sys/un.h> +#endif + +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif + +#if HAVE_SYS_WAIT_H +# include <sys/wait.h> +#endif + +#if HAVE_ERRNO_DECL +# include <errno.h> +#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); +} |