00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <stdio.h>
00019
00020 #ifdef HAVE_SYS_SOCKET_H
00021 # include <sys/socket.h>
00022 #endif
00023
00024 #ifdef HAVE_SYS_UN_H
00025 # include <sys/un.h>
00026 #endif
00027
00028 #ifdef HAVE_SYS_TYPES_H
00029 # include <sys/types.h>
00030 #endif
00031
00032 #if HAVE_SYS_WAIT_H
00033 # include <sys/wait.h>
00034 #endif
00035
00036 #if HAVE_ERRNO_DECL
00037 # include <errno.h>
00038 #else
00039 extern int errno;
00040 #endif
00041
00042 static int bind_socket(char const *filename)
00043 {
00044 int sock_fd;
00045 struct sockaddr_un name;
00046 size_t size;
00047
00048
00049 if ((sock_fd = socket(PF_LOCAL, SOCK_STREAM, 0)) < 0) {
00050 perror ("socket(PF_LOCAL, SOCK_STREAM)");
00051 exit(1);
00052 }
00053
00054
00055 name.sun_family = AF_LOCAL;
00056 strncpy(name.sun_path, filename, sizeof (name.sun_path));
00057
00058
00059
00060
00061
00062
00063
00064
00065 size = SUN_LEN(&name);
00066
00067
00068 if (bind(sock_fd, (struct sockaddr *) &name, size) < 0) {
00069 perror ("bind");
00070 exit(1);
00071 }
00072
00073 return sock_fd;
00074 }
00075
00076
00077 int main(void)
00078 {
00079 int sock_fd;
00080 int kid;
00081 char const *filename = "conftest.unixsock.sock";
00082
00083
00084 alarm(15);
00085
00086 if ((sock_fd = bind_socket(filename)) < 0)
00087 exit(1);
00088
00089
00090
00091
00092 exit(0);
00093 }