Adding a test for fd passing capability.
[vsys.git] / tests / socket.c
1 #include <sys/socket.h>
2 #include <sys/un.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <string.h>
6
7
8 int
9 main(int argc, char *argv[])
10 {
11     int sfd;
12     struct sockaddr_un addr;
13
14     sfd = socket(AF_UNIX, SOCK_STREAM, 0);
15     if (sfd == -1) {
16         perror("socket");
17         exit(EXIT_FAILURE);
18     }
19
20     memset(&addr, 0, sizeof(struct sockaddr_un));
21     /* Clear structure */
22     addr.sun_family = AF_UNIX;
23     strncpy(addr.sun_path, argv[1],
24             sizeof(addr.sun_path) - 1);
25
26     if (connect(sfd, (struct sockaddr *) &addr,
27                 sizeof(struct sockaddr_un)) == -1) {
28         perror("bind");
29         exit(EXIT_FAILURE);
30     }
31
32     printf("Connected\n");
33
34 }
35