Client-side library for big sockets.
[vsys-wrappers.git] / bmsocket / bmsocket.c
1 #include <sys/socket.h>
2 #include <sys/un.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include "fdpass.h"
7
8 #define VSYS_BMSOCKET "/vsys/fd_bmsocket.control"
9
10 int socket(int domain, int type, int protocol)
11 {
12     int sfd;
13     struct sockaddr_un addr;
14     int remotefd;
15
16     sfd = socket(AF_UNIX, SOCK_STREAM, 0);
17     if (sfd == -1) {
18         perror("Could not create UNIX socket\n");
19         exit(-1);
20     }
21
22     memset(&addr, 0, sizeof(struct sockaddr_un));
23     /* Clear structure */
24     addr.sun_family = AF_UNIX;
25     strncpy(addr.sun_path, VSYS_BMSOCKET,
26             sizeof(addr.sun_path) - 1);
27
28     if (connect(sfd, (struct sockaddr *) &addr,
29                 sizeof(struct sockaddr_un)) == -1) {
30         perror("Could not connect to Vsys control socket");
31         exit(-1);
32     }
33
34
35     remotefd = receive_fd(sfd);
36     return remotefd;
37 }
38