tunneldiggercpp

git clone git://archive.git.mtrnord.blog/MTRNord/tunneldiggercpp.git
Log | Files | Refs | README

broker.cpp (1470B)


      1 //
      2 // Created by marce on 22.09.2017.
      3 //
      4 
      5 #ifdef linux
      6     #include "broker.h"
      7     #include <iostream>
      8     #include <sys/types.h>
      9     #include <sys/wait.h>
     10     #include <unistd.h>
     11     #include <errno.h>
     12     #include <stdlib.h>
     13 
     14     using namespace std;
     15 
     16     broker::TunnelManager::TunnelManager(const char * nspaceL) {
     17         nspace = nspaceL;
     18     }
     19 
     20     int broker::TunnelManager::initialize() {
     21         std::cout << "Prepare Routing" << endl;
     22 
     23 
     24         string prerouting_chain = (string) "L2TP_PREROUTING_" + nspace;
     25         string postrouting_chain  = (string) "L2TP_POSTROUTING_" + nspace;
     26 
     27         pid_t pid;
     28         int status;
     29         pid_t ret;
     30         char *const args[3] = {"iptables", "--version", NULL};
     31         char **env;
     32         extern char **environ;
     33 
     34         /* ... Sanitize arguments ... */
     35 
     36         pid = fork();
     37         if (pid == -1) {
     38             /* Handle error */
     39         } else if (pid != 0) {
     40             while ((ret = waitpid(pid, &status, 0)) == -1) {
     41                 if (errno != EINTR) {
     42                     /* Handle error */
     43                     break;
     44                 }
     45             }
     46             if ((ret != -1) &&
     47                 (!WIFEXITED(status) || !WEXITSTATUS(status)) ) {
     48                 /* Report unexpected child status */
     49             }
     50         } else {
     51             if (execve("iptables", args, env) == -1) {
     52                 /* Handle error */
     53                 _Exit(127);
     54             }
     55         }
     56 
     57         return 0;
     58     }
     59 #endif