mirror of https://github.com/agdsn/xerxes.git
first working ,,proof of concept'' of xerxes with
boost::programm_options
This commit is contained in:
parent
2dacef4bc0
commit
12fbe224af
43
xerxes.cxx
43
xerxes.cxx
|
|
@ -31,7 +31,7 @@ class SocketOption {
|
||||||
: type(UNIX), file(new_file)
|
: type(UNIX), file(new_file)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
SocketOption(std::string new_hostname, int new_port)
|
SocketOption(std::string new_hostname, std::string new_port)
|
||||||
: type(TCP), hostname(new_hostname), port(new_port)
|
: type(TCP), hostname(new_hostname), port(new_port)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -39,7 +39,7 @@ class SocketOption {
|
||||||
int type;
|
int type;
|
||||||
std::string file;
|
std::string file;
|
||||||
std::string hostname;
|
std::string hostname;
|
||||||
int port;
|
std::string port;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -62,16 +62,26 @@ void validate(boost::any& v,
|
||||||
// Do regex match and convert the interesting part to
|
// Do regex match and convert the interesting part to
|
||||||
// int.
|
// int.
|
||||||
boost::smatch match;
|
boost::smatch match;
|
||||||
if (regex_match(s, match, r)) {
|
if(regex_match(s, match, r))
|
||||||
cout << "1: " << match[1] << endl; // Type
|
{
|
||||||
|
cout << "1: " << match[1] << endl; // Type
|
||||||
cout << "2: " << match[2] << endl; // File-/Hostname
|
cout << "2: " << match[2] << endl; // File-/Hostname
|
||||||
cout << "5: " << match[5] << endl; // Port
|
cout << "5: " << match[5] << endl; // Port
|
||||||
|
if(match[1] == "tcp")
|
||||||
v = any(SocketOption())
|
{
|
||||||
//v = any(magic_number(boost::lexical_cast<int>(match[1])));
|
cout << "TCP" << endl;
|
||||||
} else {
|
v = boost::any(SocketOption(match[2], match[5]));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cout << "UNIX" << endl;
|
||||||
|
v = boost::any(SocketOption(match[2]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
throw validation_error("invalid value");
|
throw validation_error("invalid value");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -106,10 +116,15 @@ if (vm.count("help")) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vm.count("src")) {
|
if (vm.count("src")) {
|
||||||
// SocketOption sock = vm["src"].as<SocketOption>;
|
SocketOption sock = vm["src"].as<SocketOption>();
|
||||||
// if(sock.type == TCP){
|
if(sock.type == TCP)
|
||||||
// cout << "TCP Source is " << sock.hostname << "," << sock.port << ".\n";
|
{
|
||||||
// }
|
cout << "TCP Source is " << sock.hostname << "," << sock.port << ".\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cout << "UNIX Source is " << sock.file << ".\n";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
cout << "Source was not set.\n";
|
cout << "Source was not set.\n";
|
||||||
}
|
}
|
||||||
|
|
@ -117,7 +132,7 @@ if (vm.count("src")) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
|
||||||
|
|
||||||
Socket lstn(PF_INET, SOCK_STREAM, 0);
|
Socket lstn(PF_INET, SOCK_STREAM, 0);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue