* Parse and handle the command line args * * \param [out] cfg Reference to config options - Will be updated based on cli * * \returns true if error, false if no error * */
| 185 | * |
| 186 | */ |
| 187 | bool ReadCmdArgs(int argc, char **argv, Config &cfg) { |
| 188 | |
| 189 | // Make sure we have the correct number of required args |
| 190 | if (argc > 1 and !strcmp(argv[1], "-v")) { // Version |
| 191 | cout << "openbmpd (www.openbmp.org) version : " << OPENBMPD_VERSION << endl; |
| 192 | exit(0); |
| 193 | } |
| 194 | |
| 195 | else if (argc > 1 and !strcmp(argv[1], "-h")) { |
| 196 | Usage(argv[0]); |
| 197 | exit(0); |
| 198 | } |
| 199 | |
| 200 | // Loop through the args |
| 201 | for (int i=1; i < argc; i++) { |
| 202 | |
| 203 | if (!strcmp(argv[i], "-h")) { // Help message |
| 204 | Usage(argv[0]); |
| 205 | exit(0); |
| 206 | |
| 207 | } else if (!strcmp(argv[i], "-p")) { |
| 208 | // We expect the next arg to be a port |
| 209 | if (i + 1 >= argc) { |
| 210 | cout << "INVALID ARG: -p expects a port number" << endl; |
| 211 | return true; |
| 212 | } |
| 213 | |
| 214 | cfg.bmp_port = atoi(argv[++i]); |
| 215 | |
| 216 | // Validate the port |
| 217 | if (cfg.bmp_port < 25 || cfg.bmp_port > 65535) { |
| 218 | cout << "INVALID ARG: port '" << cfg.bmp_port |
| 219 | << "' is out of range, expected range is 100-65535" << endl; |
| 220 | return true; |
| 221 | } |
| 222 | |
| 223 | } else if (!strcmp(argv[i], "-hi")) { |
| 224 | if (i + 1 >= argc) { |
| 225 | cout << "INVALID ARG: -hi expects minutes" << endl; |
| 226 | return true; |
| 227 | } |
| 228 | |
| 229 | cfg.heartbeat_interval = atoi(argv[++i]) * 60; |
| 230 | |
| 231 | // Validate range |
| 232 | if (cfg.heartbeat_interval < 60 || cfg.heartbeat_interval > 86400) { |
| 233 | cout << "INVALID ARG: heartbeat interval '" << cfg.heartbeat_interval << |
| 234 | "' is out of range, expected range is 1 - 1440" << endl; |
| 235 | return true; |
| 236 | } |
| 237 | |
| 238 | } else if (!strcmp(argv[i], "-m")) { |
| 239 | // We expect the next arg to be mode |
| 240 | if (i + 1 >= argc) { |
| 241 | cout << "INVALID ARG: -m expects mode value" << endl; |
| 242 | return true; |
| 243 | } |
| 244 |