Changeset fb31682 in mainline for uspace/app/pcapctl/main.c


Ignore:
Timestamp:
2024-12-13T08:44:05Z (10 months ago)
Author:
Nataliia Korop <n.corop08@…>
Children:
87b490e3
Parents:
28ed2d89
git-author:
Nataliia Korop <n.corop08@…> (2024-11-29 10:41:19)
git-committer:
Nataliia Korop <n.corop08@…> (2024-12-13 08:44:05)
Message:

user friendly options, trying to start while dumping → err msg

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/pcapctl/main.c

    r28ed2d89 rfb31682  
    4444#define NAME "pcapctl"
    4545#define DEFAULT_DEV_NUM 0
    46 #define DEFAULT_OPS_NUM 0
    4746#define DECIMAL_SYSTEM 10
     47
     48#define DEFAULT_FILE_OPS 0
     49#define SHORT_FILE_OPS 1
     50#define APPEND_FILE_OPS 2
     51#define USB_FILE_OPS 3
    4852
    4953static errno_t start_dumping(int *dev_number, const char *name, int *ops_index)
     
    5660
    5761        rc = pcapctl_is_valid_ops_number(ops_index, sess);
    58         if (rc != EOK)
    59         {
     62        if (rc != EOK) {
    6063                printf("Wrong number of ops: %d.\n", *ops_index);
    6164                pcapctl_dump_close(sess);
     
    6568        rc = pcapctl_dump_start(name, ops_index, sess);
    6669        if (rc != EOK) {
     70                if (rc == EBUSY) {
     71                        printf("Dumping for device %d is in process, stop to start dumping to file %s.\n", *dev_number, name);
     72                }
    6773                printf("Starting the dumping was not successful.\n");
    6874        }
     
    95101 */
    96102static const struct option opts[] = {
     103        { "append", required_argument, 0, 'A' }, // file as argument and ops 0 if not exist and 2 if exists
     104        { "new", required_argument, 0, 'N' }, // file name as argument
     105        { "truncated", required_argument, 0, 'T' }, // truncated ops
     106        { "usb", required_argument, 0, 'U' }, //??
    97107        { "device", required_argument, 0, 'd' },
    98108        { "list", no_argument, 0, 'l' },
     
    102112        { "stop", no_argument, 0, 't' },
    103113        { "ops", required_argument, 0, 'p' },
    104         { "force", no_argument, 0, 'f'},
     114        { "force", no_argument, 0, 'f' },
    105115        { 0, 0, 0, 0 }
    106116};
     
    109119{
    110120        vfs_stat_t stats;
    111 
    112     if (vfs_stat_path(path, &stats) != EOK)
    113         return false;
    114 
    115     return true;
     121        if (vfs_stat_path(path, &stats) != EOK) {
     122                return false;
     123        } else {
     124                return true;
     125        }
    116126}
    117127
     
    121131            NAME " --list | -l \n"
    122132            "\tList of devices\n"
    123             NAME " --start | -r --device= | -d <device number from list> --outfile= | -f <outfile>\n"
     133            NAME " --start | -r --device= | -d <device number from list> --outfile= | -o <outfile> --ops= | p <ops index>\n"
    124134            "\tPackets dumped from device will be written to <outfile>\n"
    125             NAME " --stop | -t --device= | -d <device>\n"
     135            NAME " --stop | -t --device= | -d <device number from list>\n"
    126136            "\tDumping from <device> stops\n"
    127             NAME " --start | -s --outfile= | -f <outfile>\n"
     137            NAME " --start | -r --outfile= | -o <outfile>\n"
    128138            "\tPackets dumped from the 0. device from the list will be written to <outfile>\n"
    129139            NAME " --help | -h\n"
    130             "\tShow this application help.\n");
     140            "\tShow this application help.\n"
     141            NAME " --force | -f"
     142            "\tTo open existing file and write to it.\n");
    131143}
    132144
     
    136148        bool stop = false;
    137149        int dev_number = DEFAULT_DEV_NUM;
    138         int ops_number = DEFAULT_OPS_NUM;
     150        int ops_number = DEFAULT_FILE_OPS;
    139151        bool forced = false;
    140152        const char *output_file_name = "";
     
    146158        }
    147159        while (ret != -1) {
    148                 ret = getopt_long(argc, argv, "d:lho:rtp:f", opts, &idx);
     160                ret = getopt_long(argc, argv, "A:N:T:U:d:lho:rtp:f", opts, &idx);
    149161                switch (ret) {
    150162                case 'd':
     
    158170                        }
    159171                        break;
     172                case 'A':
     173                        output_file_name = optarg;
     174                        if (file_exists(output_file_name)) {
     175                                ops_number = APPEND_FILE_OPS;
     176                        }
     177                        break;
     178                case 'N':
     179                        output_file_name = optarg;
     180                        break;
     181                case 'T':
     182                        output_file_name = optarg;
     183                        ops_number = SHORT_FILE_OPS;
     184                        break;
     185                case 'U':
     186                        output_file_name = optarg;
     187                        ops_number = USB_FILE_OPS;
     188                        break;
    160189                case 'l':
    161190                        list_devs();
     
    174203                        break;
    175204                case 'p':
    176                         char* ops_inval;
     205                        char *ops_inval;
    177206                        long ops_result = strtol(optarg, &ops_inval, DECIMAL_SYSTEM);
    178207                        ops_number = (int)ops_result;
     
    184213        }
    185214
    186         printf("%s: HelenOS Packet Dumping utility: device - %d.\n", NAME, dev_number);
     215        if (!str_cmp(output_file_name, "") && start) {
     216                printf("Dumping destination was not specified. Specify with --outfile | -o\n");
     217                return 1;
     218        }
     219
     220        printf("%s: HelenOS Packet Dumping utility: device - %d, ops - %d.\n", NAME, dev_number, ops_number);
    187221
    188222        if (start) {
    189223
    190                 if (file_exists(output_file_name) && !forced)
    191                 {
    192                         printf("File %s already exists. If you want to write to it, then use flag --force.\n", output_file_name);
     224                if (file_exists(output_file_name) && !forced && ops_number != 2) {
     225                        printf("File %s already exists. If you want to overwrite to it, then use flag --force.\n", output_file_name);
    193226                        return 0;
    194227                }
     
    201234        } else {
    202235                usage();
     236                return 1;
    203237        }
    204238        return 0;
Note: See TracChangeset for help on using the changeset viewer.