Changeset fb31682 in mainline for uspace/app/pcapctl/main.c
- Timestamp:
- 2024-12-13T08:44:05Z (10 months ago)
- 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/pcapctl/main.c
r28ed2d89 rfb31682 44 44 #define NAME "pcapctl" 45 45 #define DEFAULT_DEV_NUM 0 46 #define DEFAULT_OPS_NUM 047 46 #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 48 52 49 53 static errno_t start_dumping(int *dev_number, const char *name, int *ops_index) … … 56 60 57 61 rc = pcapctl_is_valid_ops_number(ops_index, sess); 58 if (rc != EOK) 59 { 62 if (rc != EOK) { 60 63 printf("Wrong number of ops: %d.\n", *ops_index); 61 64 pcapctl_dump_close(sess); … … 65 68 rc = pcapctl_dump_start(name, ops_index, sess); 66 69 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 } 67 73 printf("Starting the dumping was not successful.\n"); 68 74 } … … 95 101 */ 96 102 static 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' }, //?? 97 107 { "device", required_argument, 0, 'd' }, 98 108 { "list", no_argument, 0, 'l' }, … … 102 112 { "stop", no_argument, 0, 't' }, 103 113 { "ops", required_argument, 0, 'p' }, 104 { "force", no_argument, 0, 'f' },114 { "force", no_argument, 0, 'f' }, 105 115 { 0, 0, 0, 0 } 106 116 }; … … 109 119 { 110 120 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 } 116 126 } 117 127 … … 121 131 NAME " --list | -l \n" 122 132 "\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" 124 134 "\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" 126 136 "\tDumping from <device> stops\n" 127 NAME " --start | - s --outfile= | -f<outfile>\n"137 NAME " --start | -r --outfile= | -o <outfile>\n" 128 138 "\tPackets dumped from the 0. device from the list will be written to <outfile>\n" 129 139 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"); 131 143 } 132 144 … … 136 148 bool stop = false; 137 149 int dev_number = DEFAULT_DEV_NUM; 138 int ops_number = DEFAULT_ OPS_NUM;150 int ops_number = DEFAULT_FILE_OPS; 139 151 bool forced = false; 140 152 const char *output_file_name = ""; … … 146 158 } 147 159 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); 149 161 switch (ret) { 150 162 case 'd': … … 158 170 } 159 171 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; 160 189 case 'l': 161 190 list_devs(); … … 174 203 break; 175 204 case 'p': 176 char *ops_inval;205 char *ops_inval; 177 206 long ops_result = strtol(optarg, &ops_inval, DECIMAL_SYSTEM); 178 207 ops_number = (int)ops_result; … … 184 213 } 185 214 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); 187 221 188 222 if (start) { 189 223 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); 193 226 return 0; 194 227 } … … 201 234 } else { 202 235 usage(); 236 return 1; 203 237 } 204 238 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.