1 /* Copy of fd_bmsocket.c that creates UDP sockets instead of TCP sockets. */
4 #include <sys/socket.h>
10 #define MAX_BUFSIZE (32*1024*1024)
12 /*------------------------------------------------------------------*/
14 receive_argument(int control_fd, int *rcvbuf, int *sndbuf)
16 if (recv(control_fd, rcvbuf, sizeof(int), 0) != sizeof(int)) {
17 fprintf(stderr, "receiving the first argument failed\n");
20 if (recv(control_fd, sndbuf, sizeof(int), 0) != sizeof(int)) {
21 fprintf(stderr, "receiving the first argument failed\n");
25 /*------------------------------------------------------------------*/
27 main(int argc, char *argv[])
29 int control_channel_fd, magic_socket;
30 int rcvbufsize = 0, sndbufsize = 0;
33 printf("This script is called by vsys.\n");
37 sscanf(argv[2],"%d", &control_channel_fd);
39 /* receive paramaters: rcvbufsize and sndbufsize */
40 receive_argument(control_channel_fd, &rcvbufsize, &sndbufsize);
41 if (rcvbufsize > MAX_BUFSIZE)
42 rcvbufsize = MAX_BUFSIZE;
43 if (sndbufsize > MAX_BUFSIZE)
44 sndbufsize = MAX_BUFSIZE;
46 magic_socket = socket(AF_INET, SOCK_DGRAM, 0);
47 if (magic_socket == -1) {
48 fprintf(stderr, "Error creating socket: %d\n", errno);
52 /* buffer size <= 0 means we should ignore the parameter */
54 if (setsockopt(magic_socket,
57 &rcvbufsize, sizeof(unsigned int))) {
58 fprintf(stderr, "Error calling setsockopt for RCVBUFFORCE: %d\n",
64 if (setsockopt(magic_socket,
67 &sndbufsize, sizeof(unsigned int))) {
68 fprintf(stderr, "Error calling setsockopt for SNDBUFFORCE: %d\n",
74 send_fd(control_channel_fd, magic_socket);