int twiperf_parse_arguments(struct iperf_test *test, int argc, char **argv) { int server_flag, client_flag, udp_flag, ethernet_flag; printf("role %d type %d",test->role,test->protocol_id); static struct option longopts[] = { {"udp", no_argument, NULL, 'u'}, {"ethernet", no_argument, NULL, 'e'}, {"server", no_argument, NULL, 's'}, {"client", no_argument, NULL, 'c'}, {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0} }; int flag; server_flag = client_flag = udp_flag = ethernet_flag = 0; while ((flag = getopt_long(argc, argv, "ue:cs:h:", longopts, NULL)) != -1) { switch (flag) { case 'c': client_flag = 1; test->role = 2; break; case 's': server_flag = 1; test->role = 1; break; case 'e': ethernet_flag = 1; test->protocol_id = 1; break; case 'u': udp_flag = 1; test->protocol_id = 2; break; case 'h': twiperf_usage(); exit(1); break; } } if(server_flag == 1 && client_flag == 1 || udp_flag == 1 && ethernet_flag == 1 ) { twiperf_usage(); exit(1); } if(server_flag == 0 && client_flag == 0 || udp_flag == 0 && ethernet_flag == 0 ) { twiperf_usage(); exit(1); } printf("role %d type %d",test->role,test->protocol_id); return 0; }
int twiperf_parse_arguments(struct iperf_test *test, int argc, char **argv) /*parsing user given arguments*/ { int udp_flag, ethernet_flag; static struct option longopts[] = { { "udp", no_argument, NULL, 'u' }, { "ethernet", no_argument, NULL, 'e' }, { "server", no_argument, NULL, 's' }, { "client", required_argument, NULL, 'c' }, { "help", no_argument, NULL, 'h' }, { "port", required_argument, NULL, 'p' }, { "bytes", required_argument, NULL, 'n' }, { "bandwith", required_argument, NULL, 'b'}, { NULL, 0, NULL, 0 } }; int flag; server_flag = client_flag = udp_flag = ethernet_flag = 0; test->packet_size = 1500; //initialized to default value of 64 bytes pcket size test->server_port = 5001; //initialized to default port of 5001 test->client_port = 7777; //initialized to default port of 5001 test->test_runtime = 0; //initialized to default infinite runtime udp_flag = 1; test->protocol_id = 2; while ((flag = getopt_long(argc, argv, "b:n:p:uec:hs", longopts, NULL)) != -1) { switch (flag) { case 'p': test->server_port = atoi(optarg); break; case 'n': test->packet_size = atoi(optarg); break; case 'b': test->rate = unit_atof_rate(optarg); rate_flag = 1; client_flag = 1; break; case 'c': client_flag = 1; test->role = 2; test->client_mac = tw_get_ether_addr("tw0"); test->server_ip = tw_cpu_to_be_32(tw_convert_ip_str_to_dec(strdup(optarg))); if(test->server_ip == 0) { twiperf_usage(); exit(1); } test->client_ip = tw_cpu_to_be_32(tw_get_ip_addr("tw0")); break; case 's': server_flag = 1; test->role = 1; test->server_mac = tw_get_ether_addr("tw0"); test->server_ip = tw_cpu_to_be_32(tw_get_ip_addr("tw0")); break; case 'e': ethernet_flag = 1; udp_flag = 0; test->protocol_id = 1; break; case 'u': udp_flag = 1; test->protocol_id = 2; break; case 'h': twiperf_usage(); exit(1); break; default: twiperf_usage(); exit(1); } } if(server_flag == 1 && client_flag == 1 || udp_flag == 1 && ethernet_flag == 1) { twiperf_usage(); exit(1); } if(server_flag == 0 && client_flag == 0 || udp_flag == 0 && ethernet_flag == 0) { twiperf_usage(); exit(1); } if((test->role != 1) && (test->role != 2)) { i_errno = IENOROLE; return -1; } if(udp_flag == 1 && test->packet_size > MAX_UDP_BLOCKSIZE) { i_errno = IEUDPBLOCKSIZE; return -1; } return 0; }