2 #include <sys/socket.h>
8 #define MAX_BUFSIZE (32*1024*1024)
10 /*------------------------------------------------------------------*/
12 receive_argument(int control_fd, int *rcvbuf, int *sndbuf)
14 if (recv(control_fd, rcvbuf, sizeof(int), 0) != sizeof(int)) {
15 fprintf(stderr, "receiving the first argument failed\n");
18 if (recv(control_fd, sndbuf, sizeof(int), 0) != sizeof(int)) {
19 fprintf(stderr, "receiving the first argument failed\n");
23 /*------------------------------------------------------------------*/
25 main(int argc, char *argv[])
27 int control_channel_fd, magic_socket;
28 int rcvbufsize = 0, sndbufsize = 0;
31 printf("This script is called by vsys.\n");
35 sscanf(argv[2],"%d", &control_channel_fd);
37 /* receive paramaters: rcvbufsize and sndbufsize */
38 receive_argument(control_channel_fd, &rcvbufsize, &sndbufsize);
39 if (rcvbufsize > MAX_BUFSIZE)
40 rcvbufsize = MAX_BUFSIZE;
41 if (sndbufsize > MAX_BUFSIZE)
42 sndbufsize = MAX_BUFSIZE;
44 magic_socket = socket(AF_INET, SOCK_STREAM, 0);
45 if (magic_socket == -1) {
46 fprintf(stderr, "Error creating socket: %d\n", errno);
50 /* buffer size <= 0 means we should ignore the parameter */
52 if (setsockopt(magic_socket,
55 &rcvbufsize, sizeof(unsigned int))) {
56 fprintf(stderr, "Error calling setsockopt for RCVBUFFORCE: %d\n",
62 if (setsockopt(magic_socket,
65 &sndbufsize, sizeof(unsigned int))) {
66 fprintf(stderr, "Error calling setsockopt for SNDBUFFORCE: %d\n",
72 send_fd(control_channel_fd, magic_socket);