Exemple #1
0
int main(void) {
    char c, b;
    int res;
    int ip;
    int Heure, HeureS, HeureP;
    int PlacesLibres;
    char Tampon[50];
    int NumTicket;

    while(1) {
        printf ("menu :\n");
        printf("1) Creation du fichier  \n");
        printf("2) Affichage du fichier \n");
        printf("3) Reservation Ticket \n");
        printf("4) Recherche et paiement \n");
        printf("5) Recherche et sortie \n");
        printf("6) exit\n");
        printf("---------------------\n");
        c = LocalReadChar();   /* Readchar se trouve dans la librairie Physlib */
        printf("\n%c\n", c);
        switch(c) {
            case '1' :
                res = CreationFichierTransaction("essai", 50);
                printf("Resultat %d \n", res);
                break;
            case '2' :
                res = AffichageFichier("essai");
                printf("Resultat %d \n", res);
                break;
            case '3':
                Ipv4ToInt("192.168.1.1", &ip);
                res = ReservationTicketBDEF("essai", ip, 80, 3, 16, &PlacesLibres);
                printf("Resultat %d \n", res);
                break;
            case '4':
                printf("Num Ticket : ");
                b = LocalReadChar();
                Ipv4ToInt("192.168.1.2", &ip);
                res = PaiementTicketBDEF("essai", ip, 80, 3, 1812, ctoi(b));
                printf("Resultat %d \n", res);
                break;
            case '5':
                printf("Num Ticket : ");
                b = LocalReadChar();
                Ipv4ToInt("192.168.2.2", &ip);
                res = SortieParkingBDEF("essai", ip, 80, 3, 1812, ctoi(b));
                printf("Resultat %d \n", res);
                break;
            case '6' :
                exit(0);
        }
    }
    return 0;
}
Exemple #2
0
int Dns( char *Buffer,char *arg1,char *arg2,char* arg3, char *arg4,  struct Global *g)
{
     if (Ipv4ToInt(arg1,&(g->IPDNS))==-1)  /* On r�up�e le masque r�eau */
     {
      fprintf(stderr,"Adresse Serveur dns Invalide:%s \n",arg1) ;
      return(0) ;
     }
     else
        return(1) ;
}
Exemple #3
0
int Gateway( char *Buffer,char *arg1,char *arg2,char* arg3, char *arg4,  struct Global *g)
 {
      if (Ipv4ToInt(arg1,&(g->Gateway))==-1)  /* On r�up�e le masque r�eau */
      {
       fprintf(stderr,"Gateway Invalide !!!\n") ;
       return(0) ;
      }
      else
       {
        fprintf(stderr,"Gateway:%s\n",arg1) ;
        return(1) ;
       }
} 
Exemple #4
0
int Netmask( char *Buffer,char *arg1,char *arg2,char* arg3, char *arg4,  struct Global *g)
{
       if (Ipv4ToInt(arg1,&(g->NetworkMask))==-1)  /* On r�up�e le masque r�eau */
       {
        printf("Masque Invalide !!!\n") ;
        return(0) ;
       }
       else
          {
           fprintf(stderr,"Masque:%s\n",arg1) ;
	   return(1);
          }
}
Exemple #5
0
int IpAddress( char *Buffer,char *arg1,char *arg2,char* arg3, char *arg4,  struct Global *g)
{
    if (Ipv4ToInt(arg2,&(g->IPInterface))==-1)  /* On r�up�e l'adresse IP */
    {
     printf("Adresse Invalide !!!\n") ;
     return(0) ;
    }
    else
       {
        fprintf(stderr,"ip:%s\n",arg2) ;
        return(1) ;
       }
}
Exemple #6
0
int ip_address(char *Buffer,struct Global *g)
{
 int rc ;
 char arg0[80],arg0B[80],LIP[80],arg2[80],arg3[80],arg4[80] ;
 struct Interface *pI ;
 int UneIP ;
 fprintf(stderr,"Entree IP adress\n") ;
 AfficheInterfaces(g->pI) ;
 bzero(arg0,sizeof(arg0));
 bzero(LIP,sizeof(LIP));
 sscanf(Buffer,"%s %s %s\n",arg0,arg0B,LIP) ;
/*----------- arg1 est l'adresse IP ------------------------*/
 pI = RechercheInterfaceNom(g->CurrentInterface,g->pI) ;
 if ( pI == NULL )
    {
     fprintf(stderr,"Le nom de l'interface n'existe pas %s \n",g->CurrentInterface) ;
     return (0) ;
    } 
 if (Ipv4ToInt(LIP,&UneIP)!=-1) /* IP ligne valide ? */
   {
    int ETR ;
    int Ligne ;
    char Buf[30] ;
    Ipv4ToS(UneIP,Buf) ;
    Ligne = ObtenirLigne(pI) ;
    fprintf(stderr,"L'adresse Pour la ligne %d est la suivante %s.\n",Ligne, Buf  ) ;
    ETR = ObtenirEntreeTableRoutage(pI) ;
    if (ETR ==-1)
       {
        /* première fois qu on assigne une ip £*/
        AjoutEntreeTableRoutage( g->TableRoutage,UneIP & 0xFFFFFF00 , Ligne, UneIP ,0xFFFFFF00, &g->NbrEntrees) ;
        ModifieEntreeTableRoutage(g->NbrEntrees-1,pI) ;
       }
    else 
       {
        fprintf(stderr,"Modiication de l entrée de la table de routage \n") ;
        RemplaceEntreeTableRoutage( g->TableRoutage,UneIP & 0xFFFFFF00 , Ligne, UneIP ,0xFFFFFF00, ETR) ;
       }
    ModifieIP(UneIP,pI) ;
    AfficheInterfaces(g->pI) ;
   }
 else
    {
     fprintf(stderr,"L'adresse %s est mauvaise.",LIP) ;
     return 0 ;
    }
 AfficheInterfaces(g->pI) ;
 fprintf(stderr,"Sortie Ip_adress\n") ;
 return 1 ;
}
Exemple #7
0
enum Evenements ReponseDNS(char *Buffer,struct Global *g)
{
 char NomDNS[50] ;
 char ADRESSEIP[50] ; 
 int UneIp ;
 /*char Buffer[100] ; Acooriger */

 sscanf(Buffer,"%s %s",NomDNS,ADRESSEIP ) ;  
 printf("Pour %s L'adresse IP est %s\n",NomDNS,ADRESSEIP) ;
 Ipv4ToInt(ADRESSEIP,&UneIp) ; 
 AjoutCacheDNS(g->CacheDNS,NomDNS,UneIp);
 AfficheCacheDNS(g->CacheDNS) ;
 return(NEAN) ;
}
Exemple #8
0
enum Evenements ResolutionNom(char *NomOuIp,int *IPDestination,struct Global *g)
{
 int PortDestination ;
 fprintf(stderr,">ResolutionNom %s\n",NomOuIp) ;
 if (Ipv4ToInt(NomOuIp, IPDestination)==-1)
    {
      printf(" Ce n'est pas une ip et") ;
     *IPDestination = RechercheNomCacheDNS(g->CacheDNS,NomOuIp) ;
     if (!(*IPDestination))
	{
	 printf("ce nom n'est pas dans le cache dns %d\n",*IPDestination) ;
         return(0) ; 
	}
     else
	 printf("ce nom est dans le cache dns\n") ;	 
    }
 
 return(1) ;
}
Exemple #9
0
void LectureTableFiltrage(char *NomFichier,struct Regle TableFiltrage[],int *NbrRegles,int NbrLignes)
{
 FILE *FichierRegles ;
 char LigneFichier[200] ;
 int Ligne,MS, MD, PortSource, PortDestination ;
 char IPSource[80],IPDestination[80],Politique[80],Protocole[80] ;
 
 FichierRegles = fopen(NomFichier,"r") ;
 if ( FichierRegles == NULL )
    {
     printf("Fichier de filtrage non ouvert \n") ;
     exit(0) ;
    }
 else
    printf("Ouverture de regles \n") ;
 *NbrRegles = 0 ;
 fgets(LigneFichier,sizeof LigneFichier,FichierRegles) ;
 while(!feof(FichierRegles))
 {
  printf(" >-> %c \n",LigneFichier[0] ) ;
  if (LigneFichier[0]=='#')
      ; 
  else
  	{
sscanf(LigneFichier,"%d %s \\ %d %s \\ %d %d %d %s %s\n",&Ligne,IPSource,&MS,IPDestination,&MD,&PortSource,&PortDestination,Protocole,Politique) ;
	 printf("%d %s \\ %d %s \\ %d %d %d %s %s\n",Ligne,IPSource,MS,IPDestination,MD,PortSource,PortDestination,Protocole,Politique ) ;
  	 if ( Ipv4ToInt(IPSource,&TableFiltrage[*NbrRegles].IPSource)== -1 )
      	   {
            printf(" Le param�re 2 n'est pas une ip\n") ;
            exit(0) ;
           }
  	 if ( Ipv4ToInt(IPDestination,&TableFiltrage[*NbrRegles].IPDestination)== -1 )
           {
            printf(" Le param�re 3 n'est pas une ip\n") ;
            exit(0) ;
      	   }
         if ( ( MS > 32 ) || ( MS < 0 ) )
	    {
             printf("Le masque source n'est pas bon %d \n", MS ) ;
	     exit(0) ;
            }
         else
	    TableFiltrage[*NbrRegles].MasqueS = MS ;
         if ( ( MD > 32 ) || ( MD < 0 ) )
	    {
             printf("Le masque destination n'est pas bon %d \n", MD ) ;
	     exit(0) ;
            }
	 else
            TableFiltrage[*NbrRegles].MasqueD = MD ;
  	 if (strcmp(Protocole,"IP")==0 )
     	   if (( PortSource == 0) && ( PortDestination == 0))
              TableFiltrage[*NbrRegles].Protocole = IP ;
           else
              {
               printf("placer des ports avec une r�le ip non sens \n") ;
	       exit(0) ;
              }
         else
    	   if (strcmp(Protocole,"UDP")==0 )
              TableFiltrage[*NbrRegles].Protocole = UDP ;
           else
              if (strcmp(Protocole,"TCP")==0 )
                 TableFiltrage[*NbrRegles].Protocole = TCP ;
              else
                 {
                  printf(" Le param�re 6 n'est pas un protocole valide \n") ;
                  exit(0) ;
                 }

         if (strcmp(Politique,"DROP")==0 )
            TableFiltrage[*NbrRegles].Politique = DROP ;
         else
            if (strcmp(Politique,"ACCEPT")==0 )
               TableFiltrage[*NbrRegles].Politique = ACCEPT ;
            else
               {
                printf(" Le param�re 7 n'est pas une politique valide \n") ;
                exit(0) ;
               }
  	if (Ligne <= NbrLignes )
      	   TableFiltrage[*NbrRegles].LigneEntree = Ligne ;
  	else
     	   {

            printf(" La ligne %d n'existe pas \n",Ligne) ;
            exit(0) ;
     	   }
        TableFiltrage[*NbrRegles].PortSource = PortSource ;
        TableFiltrage[*NbrRegles].PortDestination = PortDestination ;
        (*NbrRegles)++ ;
       }
  fgets(LigneFichier,sizeof LigneFichier,FichierRegles) ;
 }
 fclose(FichierRegles) ;
}
Exemple #10
0
int ip_route(char *Buffer,struct Global *g)
{
     int Adresse ;
     int Ligne ;
     int Gateway ;
     int Masque ;
     int rc ;
     struct Interface *pI ;
     char arg0[80],arg0B[80],arg1[80],arg2[80],arg3[80],arg4[80] ;

     fprintf(stderr,"Entree ip_route\n") ;

     bzero(arg0,sizeof(arg0));
     bzero(arg1,sizeof(arg1));
     bzero(arg2,sizeof(arg0));
     bzero(arg3,sizeof(arg1));
     bzero(arg4,sizeof(arg1));
     /* Syntaxe 10.1.2.0 255.255.255.0 etho  */
     sscanf(Buffer,"%s %s %s %s %s %s\n",arg0,arg0B,arg1,arg2,arg3,arg4) ;
     if (Ipv4ToInt(arg1,&Adresse)!=-1) /* IP ligne valide ? */
     {
      char Buf[30] ;
      Ipv4ToS(Adresse,Buf) ;
      fprintf(stderr,"L'adresse est la suivante %s.\n", Buf  ) ;
     }
     else
         {
          fprintf(stderr,"Adresse IP 1  non valide \n") ;
          return(0) ;
         }
     if (Ipv4ToInt(arg2,&Masque)!=-1) /* IP ligne valide ? */
         {
          char Buf[30] ;
          Ipv4ToS(Masque,Buf) ;
          fprintf(stderr,"L'adresse est la suivante %s.\n", Buf  ) ;
          }
     else
         {
          fprintf(stderr,"Masque IP  non valide \n") ;
          return(0) ;
         }
     /*  RechercheInterface(arg3,g->NomInterface ,g->NbrLignes ,&Ligne ) */
     pI = RechercheInterfaceNom(arg3,g->pI) ;
     
     if ( pI!=NULL )
        {
         Ligne = ObtenirLigne(pI) ;
         printf("Interface valide %d\n",Ligne) ;
         
        }
     else
         {
          printf("Interface non valide \n") ;
          return(0) ;
         }
    if (Ipv4ToInt(arg4,&Gateway)!=-1) /* IP ligne valide ? */
         {
          char Buf[30] ;
          Ipv4ToS(Gateway,Buf) ;
          fprintf(stderr,"L'adresse est la suivante %s.\n", Buf  ) ;
          }
      else
         {
          fprintf(stderr,"Gateway non valide \n") ;
          return(0) ;
         }
     AjoutEntreeTableRoutage(g->TableRoutage,Adresse, Ligne,Gateway,Masque,& (g->NbrEntrees)) ;
     return(1) ;
}