X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=fd_tos.c;fp=fd_tos.c;h=970bafa70f4dae3fdef3ebbcd38d71b65154c944;hb=405ae7f1be68ee97dadeeec10b46e6474d2a95b2;hp=0000000000000000000000000000000000000000;hpb=d193f8623085acefe88052ba03db237891a267f0;p=vsys-scripts.git diff --git a/fd_tos.c b/fd_tos.c new file mode 100644 index 0000000..970bafa --- /dev/null +++ b/fd_tos.c @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include + +#include "fdpass.h" + +/* + * Definitions for IP type of service + */ +#define IPTOS_LOWDELAY 0x10 +#define IPTOS_THROUGHPUT 0x08 +#define IPTOS_RELIABILITY 0x04 +#define IPTOS_MINCOST 0x02 +#define IPTOS_NORMALSVC 0x00 + +static void receive_argument(int control_fd, int *TOS_value) +{ + if (recv(control_fd, TOS_value, sizeof(int), 0) != sizeof(int)) { + fprintf(stderr, "receiving the IP_TOS argument failed\n"); + exit(-1); + } +} + +int main(int argc, char *argv[]) +{ + int control_channel_fd, magic_socket; + int TOS_value = IPTOS_NORMALSVC; + + if (argc < 3) { + printf("This script is called by vsys.\n"); + exit(1); + } + + control_channel_fd = atoi(argv[2]); + + /* receive IP_TOS paramater */ + receive_argument(control_channel_fd, &TOS_value); + + switch (TOS_value) + { + case IPTOS_NORMALSVC: + case IPTOS_MINCOST: + case IPTOS_RELIABILITY: + case IPTOS_THROUGHPUT: + case IPTOS_LOWDELAY: + break; + default: + fprintf(stderr, "IP_TOS value not known: %d\n", errno); + exit(1); + } + + magic_socket = receive_fd(control_channel_fd); + if (magic_socket == -1) { + fprintf(stderr, "Error creating socket: %d\n", errno); + exit(1); + } + + if (setsockopt(magic_socket, IPPROTO_IP, IP_TOS, &TOS_value, sizeof(TOS_value)) < 0 ) { + fprintf(stderr, "Error calling setsockopt for IPPROTO_IP: %d\n", errno); + exit(1); + } + + send_fd(control_channel_fd, magic_socket); +}