1 /* -*- c-file-style: "linux" -*-
3 * Try creating a Unix-domain socket, opening it, and reading from it.
4 * The POSIX name for these is AF_LOCAL/PF_LOCAL.
6 * This is used by the Samba autoconf scripts to detect systems which
7 * don't have Unix-domain sockets, such as (probably) VMS, or systems
8 * on which they are broken under some conditions, such as RedHat 7.0
9 * (unpatched). We can't build WinBind there at the moment.
11 * Coding standard says to always use exit() for this, not return, so
14 * Martin Pool <mbp@samba.org>, June 2000. */
16 /* TODO: Look for AF_LOCAL (most standard), AF_UNIX, and AF_FILE. */
20 #ifdef HAVE_SYS_SOCKET_H
21 # include <sys/socket.h>
28 #ifdef HAVE_SYS_TYPES_H
29 # include <sys/types.h>
33 # include <sys/wait.h>
42 static int bind_socket(char const *filename
)
45 struct sockaddr_un name
;
48 /* Create the socket. */
49 if ((sock_fd
= socket(PF_LOCAL
, SOCK_STREAM
, 0)) < 0) {
50 perror ("socket(PF_LOCAL, SOCK_STREAM)");
54 /* Bind a name to the socket. */
55 name
.sun_family
= AF_LOCAL
;
56 strncpy(name
.sun_path
, filename
, sizeof (name
.sun_path
));
58 /* The size of the address is
59 the offset of the start of the filename,
61 plus one for the terminating null byte.
62 Alternatively you can just do:
63 size = SUN_LEN (&name);
65 size
= SUN_LEN(&name
);
66 /* XXX: This probably won't work on unfriendly libcs */
68 if (bind(sock_fd
, (struct sockaddr
*) &name
, size
) < 0) {
81 char const *filename
= "conftest.unixsock.sock";
86 if ((sock_fd
= bind_socket(filename
)) < 0)
89 /* the socket will be deleted when autoconf cleans up these