This commit is contained in:
/jdi/ 2015-09-27 12:23:12 +02:00
parent 364bb25ab7
commit b76fb38bc2
16 changed files with 363 additions and 196 deletions

View file

@ -15,75 +15,105 @@
#include <stdlib.h>
#include <stdio.h>
#include "Options.h"
#include "Program.h"
#define USAGE "Usage: smrtlink [-p n|--port n] [-h|--help] [-v|--version] <command>\n"
#define flag_version 1
#define flag_help 2
#define no_argument 0
#define required_argument 1
#define optional_argument 2
int main(int argc, char *argv[]) {
int opt, index, option_flags;
Options options;
option_flags = 0;
int main(int argc, char *argv[]) {
int opt, index;
const struct option longopts[] = { { "version", no_argument, 0, 'v' }, {
"help", no_argument, 0, 'h' },
{ "port", required_argument, 0, 'p' }, { "srcport",
required_argument, 0, 's' },
{ "dstport", required_argument, 0, 'p' }, { 0, 0, 0, 0 }, };
"help", no_argument, 0, 'h' }, { "reverse", no_argument, 0, 'r' }, {
"password", required_argument, 0, 'p' }, { "user",
required_argument, 0, 'u' }, { "interface", required_argument, 0, 'i' }, {
"header", required_argument, 0, 'b' }, { "hex", required_argument,
0, 'x' }, { 0, 0, 0, 0 }, };
Program p = Program();
while ((opt = getopt_long(argc, argv, "vhp:s:", longopts, &index)) != -1) {
while ((opt = getopt_long(argc, argv, "bhrvxp:u:i:", longopts, &index))
!= -1) {
switch (opt) {
case 'h':
std::cout << "You hit help" << std::endl;
option_flags |= flag_version;
fprintf(stderr, VERSION);
fprintf(stderr, USAGE, argv[0]);
fprintf(stderr, HELP);
exit(EXIT_SUCCESS);
break;
case 'v':
std::cout << "You hit version" << std::endl;
option_flags |= flag_help;
fprintf(stderr, VERSION);
exit(EXIT_SUCCESS);
break;
case 'r':
options.flags |= FLAG_REVERSE;
break;
case 'b':
options.flags |= FLAG_HEADER;
break;
case 'x':
options.flags |= FLAG_HEX;
break;
case 'p':
p.dst_port = atoi(optarg);
option_flags |= 4;
//TODO add password
break;
case 's':
p.src_port = atoi(optarg);
option_flags |= 4;
case 'u':
//TODO add username
break;
case 'i':
//TODO add interface
break;
default: /* '?' */
fprintf(stderr, "Unknown option\n");
fprintf(stderr, USAGE);
fprintf(stderr, USAGE, argv[0]);
exit(EXIT_FAILURE);
}
}
if (optind >= argc && !option_flags) {
//fprintf(stderr, "Expected argument\n");
fprintf(stderr, USAGE);
if (optind >= argc) {
fprintf(stderr, "Command expected\n");
fprintf(stderr, USAGE, argv[0]);
exit(EXIT_FAILURE);
}
if (optind < argc) {
if (strcmp(argv[optind], "list") == 0) {
if (strcmp(argv[optind], "help") == 0) {
fprintf(stderr, VERSION);
fprintf(stderr, USAGE, argv[0]);
fprintf(stderr, HELP);
exit(EXIT_SUCCESS);
} else if (strcmp(argv[optind], "list") == 0) {
optind++;
if (p.list())
exit(EXIT_SUCCESS);
}else if (strcmp(argv[optind], "sniff") == 0) {
} else if (strcmp(argv[optind], "sniff") == 0) {
optind++;
if (p.sniff())
exit(EXIT_SUCCESS);
} else if (strcmp(argv[optind], "encode") == 0) {
optind++;
if (optind < argc) {
std::string s(argv[optind]);
optind++;
if (p.encode(s))
exit(EXIT_SUCCESS);
} else {
fprintf(stderr, "Argument expected after encode\n");
exit(EXIT_FAILURE);
}
} else {
printf("Unknown command: %s\n", argv[optind]);
optind++;