| 51 | }; |
| 52 | |
| 53 | static int |
| 54 | parse_args(int argc, char **argv) |
| 55 | { |
| 56 | char *app_name = argv[0]; |
| 57 | struct option lgopts[] = { |
| 58 | { NULL, 0, 0, 0 } |
| 59 | }; |
| 60 | int opt, option_index; |
| 61 | int h_present, p_present, s_present, n_args, i; |
| 62 | |
| 63 | /* Skip EAL input args */ |
| 64 | n_args = argc; |
| 65 | for (i = 0; i < n_args; i++) |
| 66 | if (strcmp(argv[i], "--") == 0) { |
| 67 | argc -= i; |
| 68 | argv += i; |
| 69 | break; |
| 70 | } |
| 71 | |
| 72 | if (i == n_args) |
| 73 | return 0; |
| 74 | |
| 75 | /* Parse args */ |
| 76 | h_present = 0; |
| 77 | p_present = 0; |
| 78 | s_present = 0; |
| 79 | |
| 80 | while ((opt = getopt_long(argc, argv, "h:p:s:", lgopts, &option_index)) |
| 81 | != EOF) |
| 82 | switch (opt) { |
| 83 | case 'h': |
| 84 | if (h_present) { |
| 85 | printf("Error: Multiple -h arguments\n"); |
| 86 | return -1; |
| 87 | } |
| 88 | h_present = 1; |
| 89 | |
| 90 | if (!strlen(optarg)) { |
| 91 | printf("Error: Argument for -h not provided\n"); |
| 92 | return -1; |
| 93 | } |
| 94 | |
| 95 | app.conn.addr = strdup(optarg); |
| 96 | if (app.conn.addr == NULL) { |
| 97 | printf("Error: Not enough memory\n"); |
| 98 | return -1; |
| 99 | } |
| 100 | break; |
| 101 | |
| 102 | case 'p': |
| 103 | if (p_present) { |
| 104 | printf("Error: Multiple -p arguments\n"); |
| 105 | return -1; |
| 106 | } |
| 107 | p_present = 1; |
| 108 | |
| 109 | if (!strlen(optarg)) { |
| 110 | printf("Error: Argument for -p not provided\n"); |
no test coverage detected