int main(int argc, const char * argv[]) {
    Gateway gateway = Gateway();
    GatewayFilter filter = GatewayFilter();
    struct gwFilterData gwFD;
    gwFD.st = &gateway.st;
    gwFD.gw = &gateway;
    Logger::initLog("gout.txt");

    filter.startFilterThread(&gwFD);

    gateway.initBlacklist();

    pthread_t taskThread;
    pthread_t blockThread;

    sem_init(&Gateway::sem, 0 , 0);
    sem_init(&Gateway::qsem, 0 , 1);
    sem_init(&Gateway::lsem, 0, 1);

    pthread_create(&taskThread, NULL, &gatewayTaskThread, (void *) &gateway);
    pthread_create(&blockThread, NULL, &gatewayBlockCleanupThread, (void *) &gateway);

    int s = -1;
    while(s < 0){
        s = socket(AF_INET, SOCK_STREAM, 0);
    }

    addrinfo hints, *res;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = AF_INET;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = AI_PASSIVE;

    getaddrinfo(NULL, "41025", &hints, &res);

    bind(Gateway::s, res->ai_addr, res->ai_addrlen);

    listen(Gateway::s,10);

    int len;
    char buf[1024];
    sockaddr_storage their_addr;
    for(;;){
        unsigned int addr_size = sizeof(their_addr);
        int sock = accept(Gateway::s, (sockaddr *) &their_addr, &addr_size);
        addr_size = sizeof(their_addr);
        getpeername(sock, (sockaddr *) &their_addr, &addr_size);
        struct sockaddr_in *saddr = (struct sockaddr_in *)&their_addr;
        char addr[1000];
        inet_ntop(AF_INET, &saddr->sin_addr, addr, 1000);
        Logger::writeToLog("accept()ed a connection from " + std::string(addr));
        pthread_t t;
        pthread_create(&t, NULL, &recvBlockReq, (void *)sock);
    }
}
Beispiel #2
0
int Interpreteur( char *Buffer, struct Global *g)
{
  char arg0[80],arg1[80],arg2[80],arg3[80],arg4[80] ;
  int rc ;
  bzero(arg0,sizeof(arg1));
  bzero(arg1,sizeof(arg1));
  bzero(arg2,sizeof(arg2));
  bzero(arg3,sizeof(arg3));
  bzero(arg4,sizeof(arg4));
  fprintf(stderr,"Interpreteur ;") ;
  sscanf(Buffer,"%s %s %s %s %s\n",arg0,arg1,arg2,arg3,arg4) ;
  fprintf(stderr,"arg0 %s \n",arg0 ) ;

  /* ATTENTIO? NE PAS OUBLIER ELSE SINON ERREUR DE SYTAXE */
  if (strcmp(arg0,"connexion")==0)  rc=Connexion(Buffer,arg1,arg2,arg3, arg4,g) ;
  else 
  if (strcmp(arg0,"ip")==0 &&( strcmp(arg1,"address")==0) ) rc=IpAddress(Buffer,arg1,arg2,arg3, arg4,g) ;
  else
  if (strcmp(arg0,"netmask")==0 ) rc = Netmask(Buffer,arg1,arg2,arg3, arg4,g) ;
  else 
 if (strcmp(arg0,"gateway")==0 ) rc = Gateway(Buffer,arg1,arg2,arg3, arg4,g) ;
  else
 if (strcmp(arg0,"dns")==0 ) rc = Dns(Buffer,arg1,arg2,arg3, arg4,g) ;
 else
 if (strcmp(arg0,"ports")==0 ) rc = Ports(Buffer,arg1,arg2,arg3, arg4,g) ;
 else
 if (strcmp(arg0,"ping")==0 ) rc = Ping(Buffer,arg1,arg2,arg3, arg4,g) ;
 else
 if (strcmp(arg0,"send")==0 ) rc = Send(Buffer,arg1,arg2,arg3, arg4,g) ;
 else
 if (strcmp(arg0,"bind")==0)  rc = Bind(Buffer,arg1,arg2,arg3, arg4,g) ;
 else
 if (strcmp(arg0,"nslookup")==0 )  rc= NsLookup(Buffer,arg1,arg2,arg3, arg4,g) ;
 else
 if (strcmp(arg0,"waitreceive")==0 ) rc=WaitReceive(g) ;
 else
 if (strcmp(arg0,"read")==0) rc = LireMessage( g ) ;
 else
 if (strcmp(arg0,"exit")==0) exit(0);
 else
 if (strcmp(arg0,"ipconfig")==0) rc = AfficherParametres( g ) ;
 else
 if (strcmp(arg0,"help")==0) rc = Help() ;
 else
 if (Blanc1013(Buffer))
    {
     fprintf(stderr,"Ligne vide \n" ) ;
     rc =  1 ;
    }
 else
    rc = 0 ;
 fprintf(stderr,"fin Interpeteur\n") ;
 return(rc) ;
}