📄 gw_route_modify.c
字号:
/* The following software implements the tm driver test module for the * STRV-1d flight test */#include <stdio.h>#include <fcntl.h>#include <signal.h>#include <ctype.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <netdb.h>#include <sys/time.h> /* struct timeval */#include <stdlib.h>#include <string.h>#include <unistd.h>#include "gw_route_cmdr.h"extern char Usage [];extern unsigned char command;extern char *gateway_host;extern char *src_ip_host;extern unsigned int src_netmask_host;extern char *dst_ip_host;extern unsigned int dst_netmask_host;extern int route_id;extern struct sockaddr_in gw_route_server;extern int s_gw_route_cmdr;extern longword rate;extern longword min_rate;extern longword flow_control;extern longword mtu;extern longword smtu;extern int protocol_id;extern int cong_control;gateway_command_t route_mod;voidbuild_route_modify_cmd (){ route_mod.command = GW_COMMAND_ROUTE_MODIFY; route_mod.seq_num = 0x1; if (route_id >= 0) { route_mod.data.route_mod.route_id = route_id; } if (rate) { route_mod.data.route_mod.attrib_list |= GW_ROUTE_ATTRIB_RATE; route_mod.data.route_mod.rate = rate; } if (min_rate) { route_mod.data.route_mod.attrib_list |= GW_ROUTE_ATTRIB_MIN_RATE; route_mod.data.route_mod.min_rate = min_rate; } if (flow_control) { route_mod.data.route_mod.attrib_list |= GW_ROUTE_ATTRIB_FLOW_CONTROL; route_mod.data.route_mod.flow_control = flow_control; } if (mtu) { route_mod.data.route_mod.attrib_list |= GW_ROUTE_ATTRIB_MTU; route_mod.data.route_mod.mtu = mtu; } if (smtu) { route_mod.data.route_mod.attrib_list |= GW_ROUTE_ATTRIB_SMTU; route_mod.data.route_mod.smtu = smtu; } if (cong_control != -1) { route_mod.data.route_mod.attrib_list |= GW_ROUTE_ATTRIB_CONG_CONTROL; route_mod.data.route_mod.cong_control = cong_control; } } voidverify_route_modify (){ int error = 0; if (!gateway_host) { printf ("Address of the gateway is required\n"); error = 1; } if (route_id < 0) { printf ("Route_id is required\n"); error = 1; } if (error) { printf ("Fatal errors....\n"); printf ("Terminating the gateway route commander \n"); fprintf (stderr, Usage); exit(0); }}voidsend_route_modify_cmd (){ int rc; rc = send (s_gw_route_cmdr, &route_mod, sizeof (route_mod) , 0); if (rc <= 0) { perror ("Error in sending route to gateway"); } else { } }void recv_route_modify_resp () { fd_set read_set; int rc; struct timeval timeout; FD_ZERO (&read_set); FD_SET (s_gw_route_cmdr, &read_set); timeout.tv_sec = 10; timeout.tv_usec = 0; rc = select (10, &read_set, NULL, NULL, &timeout); if (rc == -1) { perror ("Error in select"); } if (FD_ISSET (s_gw_route_cmdr, &read_set)) { read_route_modify_resp (); } else { printf ("No response from gateway\n"); }}voidread_route_modify_resp (){ int rc; unsigned char buffer [MAX_PKT_SIZE]; unsigned char *pbuffer = buffer; gateway_command_t *resp; rc = recv (s_gw_route_cmdr, pbuffer, MAX_PKT_SIZE, 0x0); if (rc <= 0) { perror ("Error in reading data from the gateway"); } else { resp = (gateway_command_t *) buffer; printf ("Return code %d\n", resp->data.route_mod_resp.rc); }}voidroute_modify (){ verify_route_modify (); build_route_modify_cmd (); send_route_modify_cmd (); recv_route_modify_resp ();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -