Changeset 28ed2d89 in mainline for uspace/app/pcapctl/main.c
- Timestamp:
- 2024-12-13T08:44:05Z (10 months ago)
- Children:
- fb31682
- Parents:
- 31d2aee
- git-author:
- Nataliia Korop <n.corop08@…> (2024-11-23 08: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
r31d2aee r28ed2d89 38 38 #include <arg_parse.h> 39 39 #include <getopt.h> 40 #include <vfs/vfs.h> 40 41 41 42 #include "pcapdump_client.h" … … 43 44 #define NAME "pcapctl" 44 45 #define DEFAULT_DEV_NUM 0 46 #define DEFAULT_OPS_NUM 0 45 47 #define DECIMAL_SYSTEM 10 46 48 … … 96 98 { "list", no_argument, 0, 'l' }, 97 99 { "help", no_argument, 0, 'h' }, 98 { "outfile", required_argument, 0, ' f' },100 { "outfile", required_argument, 0, 'o' }, 99 101 { "start", no_argument, 0, 'r' }, 100 102 { "stop", no_argument, 0, 't' }, 101 { "ops", required_argument, 0, 'o' }, 103 { "ops", required_argument, 0, 'p' }, 104 { "force", no_argument, 0, 'f'}, 102 105 { 0, 0, 0, 0 } 103 106 }; 107 108 static bool file_exists(const char *path) 109 { 110 vfs_stat_t stats; 111 112 if (vfs_stat_path(path, &stats) != EOK) 113 return false; 114 115 return true; 116 } 104 117 105 118 static void usage(void) … … 122 135 bool start = false; 123 136 bool stop = false; 124 int dev_number = -1; 125 int ops_number = -1; 137 int dev_number = DEFAULT_DEV_NUM; 138 int ops_number = DEFAULT_OPS_NUM; 139 bool forced = false; 126 140 const char *output_file_name = ""; 127 141 int idx = 0; … … 132 146 } 133 147 while (ret != -1) { 134 ret = getopt_long(argc, argv, "d:lh f:rt", opts, &idx);148 ret = getopt_long(argc, argv, "d:lho:rtp:f", opts, &idx); 135 149 switch (ret) { 136 150 case 'd': … … 150 164 usage(); 151 165 return 0; 152 case ' f':166 case 'o': 153 167 output_file_name = optarg; 154 168 break; … … 159 173 stop = true; 160 174 break; 161 case ' o':175 case 'p': 162 176 char* ops_inval; 163 177 long ops_result = strtol(optarg, &ops_inval, DECIMAL_SYSTEM); 164 178 ops_number = (int)ops_result; 165 179 break; 180 case 'f': 181 forced = true; 182 break; 166 183 } 167 184 } … … 170 187 171 188 if (start) { 189 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); 193 return 0; 194 } 195 172 196 /* start with dev number and name */ 173 197 start_dumping(&dev_number, output_file_name, &ops_number); … … 175 199 /* stop with dev number */ 176 200 stop_dumping(&dev_number); 201 } else { 202 usage(); 177 203 } 178 204 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.