main.cpp (1631B)
1 #ifdef linux 2 #include <unistd.h> 3 #include "libs/INIReader.h" 4 #include "broker.h" 5 #endif 6 #include <iostream> 7 8 using namespace std; 9 10 int main(int argc, char* argv[]) { 11 #ifdef linux 12 string configFile= "../l2tp_broker.cfg.example"; 13 if (argc > 1) { 14 if (string(argv[1]) != "") { 15 configFile = argv[1]; 16 }else{ 17 std::cout << "Using example config" << endl; 18 } 19 }else{ 20 std::cout << "Using example config" << endl; 21 } 22 INIReader reader(configFile); 23 24 if (reader.ParseError() < 0) { 25 std::cout << "Can't load '"<< configFile << "'" << reader.ParseError() << endl; 26 return 1; 27 } 28 std::cout << "Config loaded from '"<< configFile << "': address=" 29 << reader.Get("broker", "address", "UNKNOWN") << ", port=" 30 << reader.Get("broker", "port", "UNKNOWN") << endl; 31 int uid=getuid(); 32 if (uid == 0) { 33 /* We might have elevated privileges beyond that of the user who invoked 34 * the program, due to suid bit. Be very careful about trusting any data! */ 35 36 string nspaceL = reader.Get("broker", "namespace", "l2tp"); 37 38 broker::TunnelManager tunnelManager(nspaceL.c_str()); 39 tunnelManager.initialize(); 40 } else { 41 std::cout << "Please run this as root" << endl; 42 } 43 return 0; 44 #else 45 printf("You currently have to use Linux to run this. Other System support might eventually come in the future. :)\n"); 46 47 return 1; 48 #endif 49 }