/* * RCU Command line parsing * with thanks to Hunter Goatley for ZIP source code - * portions based on ZIP file CMDLINE.c */ #include #include #include #include #include #include #include #include #include "cmdline.h" /* ** "Macro" to initialize a dynamic string descriptor. */ #define init_dyndesc(dsc) {\ dsc.dsc$w_length = 0;\ dsc.dsc$b_dtype = DSC$K_DTYPE_T;\ dsc.dsc$b_class = DSC$K_CLASS_D;\ dsc.dsc$a_pointer = NULL;} /* * Define descriptors for all the CLI parameters and qualifiers */ $DESCRIPTOR(cli_address, "ADDRESS"); $DESCRIPTOR(cli_port, "PORT"); $DESCRIPTOR(cli_switch, "SWITCH"); $DESCRIPTOR(cli_direction, "DIRECTION"); $DESCRIPTOR(cli_interface, "INTERFACE"); $DESCRIPTOR(cli_machine, "MACHINE"); /* * This method uses the CLI$ library to parse command line * options and populate the 'options' parameter with the parsing * results (which must be allocated). */ unsigned long parse_cmdline(struct rcu_options *options) { unsigned long status = SS$_NORMAL; struct dsc$descriptor_d work_str; init_dyndesc(work_str); /* check for ADDRESS value, e.g: 192.168.1.199 */ status = cli$present(&cli_address); if (status & 1) { options->address_flag = 1; status = cli$get_value(&cli_address, &work_str); int len = (work_str.dsc$w_length <= MAX_ADDRESS_LEN) ? work_str.dsc$w_length : MAX_ADDRESS_LEN; strncpy(options->address_value, work_str.dsc$a_pointer, len); options->address_value[len] = '\0'; } /* check for MACHINE value, e.g: VAX90K */ status = cli$present(&cli_machine); if (status & 1) { options->machine_flag = 1; status = cli$get_value(&cli_machine, &work_str); int len = (work_str.dsc$w_length <= MAX_MACHINE_NAME_LEN) ? work_str.dsc$w_length : MAX_MACHINE_NAME_LEN; strncpy(options->machine_value, work_str.dsc$a_pointer, len); options->machine_value[len] = '\0'; } /* check for the PORT value, normally: 80 */ status = cli$present(&cli_port); if (status & 1) { options->port_flag = 1; status = cli$get_value(&cli_port, &work_str); if (status & 1) { /** 3rd argument '2' specifies a 2-byte word as target */ status = ots$cvt_tu_l(&work_str, &options->port_value, 2); } } /* check for the DIRECTION value */ status = cli$present(&cli_direction); if (status & 1) { options->direction_flag = 1; status = cli$get_value(&cli_direction, &work_str); if (status & 1) { /** 3rd argument '2' specifies a 2-byte word as target */ status = ots$cvt_tu_l(&work_str, &options->direction_value, 2); } } /* check for SWITCH value, e.g: OFF,ON,TOGGLE */ status = cli$present(&cli_switch); if (status & 1) { options->switch_flag = 1; status = cli$get_value(&cli_switch, &work_str); if (strncmp(work_str.dsc$a_pointer, "OFF", 3) == 0) { options->switch_value = SWITCH_OFF; } else if (strncmp(work_str.dsc$a_pointer, "ON", 2) == 0) { options->switch_value = SWITCH_ON; } else if (strncmp(work_str.dsc$a_pointer, "TOGGLE", 3) == 0) { options->switch_value = SWITCH_OFF; } } /* check for INTERFACE value, e.g: CLI,SMG,DECW */ status = cli$present(&cli_interface); if (status & 1) { options->interface_flag = 1; status = cli$get_value(&cli_interface, &work_str); if (strncmp(work_str.dsc$a_pointer, "CLI", 3) == 0) { options->interface_value = INTERFACE_CLI; } else if (strncmp(work_str.dsc$a_pointer, "SMG", 3) == 0) { options->interface_value = INTERFACE_SMG; } else if (strncmp(work_str.dsc$a_pointer, "DECW", 4) == 0) { options->switch_value = INTERFACE_DECW; } } return status; }