2 * -*- c-file-style: "linux" -*-
4 * Try creating a Unix-domain socket, opening it, and reading from it.
5 * The POSIX name for these is AF_LOCAL/PF_LOCAL.
7 * This is used by the Samba autoconf scripts to detect systems which
8 * don't have Unix-domain sockets, such as (probably) VMS, or systems
9 * on which they are broken under some conditions, such as RedHat 7.0
10 * (unpatched). We can't build WinBind there at the moment.
12 * Martin Pool <mbp@samba.org>, June 2000.
15 /* TODO: Look for AF_LOCAL (most standard), AF_UNIX, and AF_FILE. */
19 #if defined(HAVE_UNISTD_H)
23 #ifdef HAVE_SYS_SOCKET_H
24 # include <sys/socket.h>
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
36 # include <sys/wait.h>
45 static int bind_socket(char const *filename
)
48 struct sockaddr_un name
;
51 /* Create the socket. */
52 if ((sock_fd
= socket(PF_LOCAL
, SOCK_STREAM
, 0)) < 0) {
53 perror ("socket(PF_LOCAL, SOCK_STREAM)");
57 /* Bind a name to the socket. */
58 name
.sun_family
= AF_LOCAL
;
59 strncpy(name
.sun_path
, filename
, sizeof (name
.sun_path
));
61 /* The size of the address is
62 the offset of the start of the filename,
64 plus one for the terminating null byte.
65 Alternatively you can just do:
66 size = SUN_LEN (&name);
68 size
= SUN_LEN(&name
);
69 /* XXX: This probably won't work on unfriendly libcs */
71 if (bind(sock_fd
, (struct sockaddr
*) &name
, size
) < 0) {
84 char const *filename
= "conftest.unixsock.sock";
89 if ((sock_fd
= bind_socket(filename
)) < 0)
92 /* the socket will be deleted when autoconf cleans up these