This commit is contained in:
/jdi/ 2015-09-23 22:29:29 +02:00
commit 009294ba4d
13 changed files with 696 additions and 0 deletions

100
src/smrtlink.cpp Normal file
View file

@ -0,0 +1,100 @@
//============================================================================
// Name : smrtlink.cpp
// Author : jdi
// Version :
// Copyright : GPL v2
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <cstring>
#include <getopt.h>
#include <unistd.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include "Program.h"
#define USAGE "Usage: smrtlink [-p n|--port n] [-h|--help] [-v|--version] name\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;
option_flags = 0;
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 }, };
Program p = Program();
while ((opt = getopt_long(argc, argv, "vhp:s:", longopts, &index)) != -1) {
switch (opt) {
case 'h':
std::cout << "You hit help" << std::endl;
option_flags |= flag_version;
break;
case 'v':
std::cout << "You hit version" << std::endl;
option_flags |= flag_help;
break;
case 'p':
p.dst_port = atoi(optarg);
option_flags |= 4;
break;
case 's':
p.src_port = atoi(optarg);
option_flags |= 4;
break;
default: /* '?' */
fprintf(stderr, "Unknown option\n");
fprintf(stderr, USAGE);
exit(EXIT_FAILURE);
}
}
if (optind >= argc && !option_flags) {
//fprintf(stderr, "Expected argument\n");
fprintf(stderr, USAGE);
exit(EXIT_FAILURE);
}
while (optind < argc) {
if (strcmp(argv[optind], "list") == 0) {
printf("List:\n\tA B C\n");
}else {
printf("->%s\n", argv[optind]);
}
optind++;
}
if (p.src_port != 0) {
printf("src_port = %d\n", p.src_port);
}
if (p.dst_port != 0) {
printf("dst_port = %d\n", p.dst_port);
}
if (p.run())
exit(EXIT_SUCCESS);
else
exit(EXIT_FAILURE);
}