Adding KyoungSoo's changes for setting buffer sizes
[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 CreateLargeBufSocket(int recvbuf, int sndbuf)
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     /* passing the parameters */
35     if (send(sfd, &recvbuf, sizeof(recvbuf), 0) != sizeof(recvbuf)) {
36         perror("Could not connect to Vsys control socket");
37         exit(-1);
38
39     }
40     if (send(sfd, &sndbuf, sizeof(sndbuf), 0) != sizeof(sndbuf)) {
41         perror("Could not connect to Vsys control socket");
42         exit(-1);
43     }
44
45     remotefd = receive_fd(sfd);
46     return remotefd;
47 }
48