[Previo por Fecha] [Siguiente por Fecha] [Previo por Hilo] [Siguiente por Hilo]

[Hilos de Discusión] [Fecha] [Tema] [Autor]

Re: [Sop.Tec.LinuxPPP] pedido



Checalo, es el que yo utilizo para capturar la ROP de los swithces
Lucent y PBX's Nortel

Hasta pronto.


El jue, 18-03-2004 a las 23:45, Héctor R. González escribió:
>  
> Sergio
>  
> Buenos dias,.. encontre un trozo de programa en C en un foro 
> especificamente en
> http://mail.linuxppp.com/pipermail/linux/2003-January/000185.html
> claro es del año pasado,..solo que el codigo C no esta del todo 
> legible y con algunos caracteres raros en medio.
> Si lo tienes a mano tendrias la gentileza de enviarmelo por e-mail.
>  
> Cordiales Saludos desde esta zona del planeta.
>  
> Hector G.
> Asuncion, Paraguay
>  
>  
-- 
Sergio Vergara Ganado
Telereunion, S.A de C.V
Cell: 044-55-1176-5190

Este artculo puede ser copiado parcial o totalmente, transmitido por cualquier medio conocido o por conocer, siempre y cuando se mencione la fuente y el autor del mismo. Copyleft 2003
#include <stdio.h>   /* Standard input/output definitions */
#include <string.h>  /* String function definitions */
#include <unistd.h>  /* UNIX standard function definitions */
#include <fcntl.h>   /* File control definitions */
#include <errno.h>   /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */


#define BAUDRATE    B9600
#define MODEMDEVICE "/dev/ttyS"
#define MAXLENNAME  1024   /* max number of bytes we can get at once */
#define MAXLENCAMPO 10     /* max number of bytes we can get at once */

int  open_port(char NoPto[]);
void NuevoNom (char acNomFileAct[], int imes, int idia, int ianio, char acExt[], char pathfile[]);
void MesDia   (int *imes, int *idia, int *ianio);
int  IntMes   (char acmes[]);
void CreaFile (FILE **pFile, char acNomFileAct[]);




int main(int argc, char *argv[])
   {
   int mainfd=0;                               /* File descriptor */
   char chout;
   struct termios options;

   FILE     *ArchOut;
   char     acNomFileAct[MAXLENNAME];
   int      idia, imes, idiaant, imesant, ianio;

   if (argc !=4 )
      {
      fprintf(stderr,"\n\nusage: ReadCOM Extension Path Serial\n\n");
      fprintf(stderr,"Donde: Extension = extension que tendra el archivo Generado.\n");
      fprintf(stderr,"       Path      = Lugar donde se grabara el archivo de salida.\n");
      fprintf(stderr,"       Serial    = Puerto serial a leer.\n\n");
      fprintf(stderr,"Ejemplo: ReadCOM  .pbx /home/Reportes/ 1\n\n");
      fprintf(stderr,"Leera el Serial COM1, es decir, /dev/ttyS1 y \nGenerara archivos en el directorio: /home/Reportes/ , con el nombre PBX_ANNIMESDIA.pbx\n\n");
      fprintf(stderr,"Donde: ANNIO = 4 digitos para el Anio\n");
      fprintf(stderr,"       MES   = 2 digitos para el Mes\n");
      fprintf(stderr,"       ANNIO = 2 digitos para el Dia\n\n");

      exit(1);
      }

   
   mainfd = open_port(argv[3]);

   fcntl(mainfd, F_SETFL, FNDELAY);            /* Configure port reading */

   tcgetattr(mainfd, &options);                /* Get the current options for the port */
   cfsetispeed(&options, BAUDRATE);            /* Set the input speed baud rates to 9600 */
   cfsetospeed(&options, BAUDRATE);            /* Set the out   speed baud rates to 9600 */
    
   options.c_cflag |= (CLOCAL | CREAD);        /* Enable the receiver and set local mode */

  /* Puerto configurado como 7E1
  /* Size Word = 7, paridad = par, 1 bit de paro
  /*
   options.c_cflag |= PARENB;
   options.c_cflag &= ~PARODD;
   options.c_cflag &= ~CSTOPB;
   options.c_cflag &= ~CSIZE;
   options.c_cflag |= CS7;

   options.c_cflag &= ~CRTSCTS;                /* Disable hardware flow control */  
   options.c_lflag &= ~(ICANON | ECHO | ISIG); /* Enable data to be processed as raw input */

   tcsetattr(mainfd, TCSANOW, &options);       /* Set the new options for the port */


  /*
   * Obtencion del Mes y Dia actual
   */
   MesDia(&imes, &idia, &ianio);

  /*
   * Generacion del nombre del archivo actual
   */
   NuevoNom(acNomFileAct, imes, idia, ianio, argv[1], argv[2]);

  /*
   * Creacion del archivo actual
   */
   CreaFile(&ArchOut, acNomFileAct);

   idiaant = idia;
   imesant = imes;

                         
   while (1)
      {
      read(mainfd, &chout, sizeof(chout));      /* Read character from ABU */
   
      if (chout != 0)
         {
         /*printf("Got %c.\n", chout);*/
         /*printf("%c", chout);*/

         fprintf(ArchOut, "%c", chout);
         fflush(ArchOut);
         }

      if( (imes!=imesant) || (idia!=idiaant) )
          {
          MesDia(&imes, &idia, &ianio);
          NuevoNom(acNomFileAct, imes, idia, ianio, argv[1], argv[2]);
          fclose(ArchOut);

          CreaFile(&ArchOut, acNomFileAct);

          idiaant = idia;
          imesant = imes;
          }


      MesDia(&imes, &idia, &ianio);

      chout=0;
      usleep(20000);
      }
                                                    /* Close the serial port */
   close(mainfd);
   }





 /*
  * 'open_port()' - Open serial port 1.
  *
  * Returns the file descriptor on success or -1 on error.
  */

int open_port(char NoPto[])
   {
   int  fd;                                           /* File descriptor for the port */
   char acSerial[15];


   acSerial[0]='\0';
   strcpy(acSerial,MODEMDEVICE);
   strcat(acSerial,NoPto);
   acSerial[10]='\0';
 
   printf("\nPuerto a Monitor: %s\n", acSerial);

   fd = open(acSerial, O_RDWR | O_NOCTTY | O_NDELAY);

   if (fd == -1)
      {                                              /* Could not open the port */
      fprintf(stderr, "open_port: Unable to open /dev/ttyS1 - %s\n", strerror(errno));
      exit(1);
      }

   return (fd);
 }


void MesDia (int *imes, int *idia, int  *ianio)
   {
   time_t t;
   char   buffer[1020];
   char   acmes[10];
   char   acdia[10];
   char   acanio[10];
   int auxmes = 0;

   memset(buffer, 0x00,1020);
   memset(acmes,  0x00, 10);
   memset(acdia,  0x00, 10);
   memset(acanio,  0x00, 10);

   time(&t);
   sprintf(buffer,"%s", ctime(&t));
   memcpy(acmes, &buffer[4], 3);
   memcpy(acdia, &buffer[8], 2);
   memcpy(acanio, &buffer[20], 4);

   acmes[3] = '\0';
   acdia[2] = '\0';
   acanio[4] = '\0';

   *idia = atoi(acdia);
   *imes = IntMes(acmes);
   *ianio = atoi(acanio);
   }





int IntMes(char acmes[])
   {
   int   icont, icomp;
   char  acMesCal[12][4]={"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"  };

   for(icont=0; icont<12; ++icont)
      {
      icomp = strcmp(acmes, acMesCal[icont]);

      if(icomp == 0)
         break;
      }
   return (++icont);
   }




void NuevoNom(char acNomFileAct[], int imes, int idia, int ianio, char acExt[], char pathfile[])
   {
   char   acMesbuf[MAXLENCAMPO];
   char   acDiabuf[MAXLENCAMPO];
   char   acAniobuf[MAXLENCAMPO];

   memset(acNomFileAct, 0x00, MAXLENNAME);
   memset(acMesbuf,     0x00, MAXLENCAMPO);
   memset(acDiabuf,     0x00, MAXLENCAMPO);
   memset(acAniobuf,    0x00, MAXLENCAMPO);

   sprintf(acAniobuf, "%d", ianio);
   acAniobuf[4] = '\0';
   sprintf(acMesbuf, "%02d", imes);
   acMesbuf[3] = '\0';
   sprintf(acDiabuf, "%02d", idia);
   acDiabuf[2] = '\0';

   /*printf ("\n Anio=%s, Mes=%s, Dia=%s", acAniobuf,acMesbuf,acDiabuf); */

   strcat(acNomFileAct, pathfile);
   strcat(acNomFileAct, "PBX_");
   strcat(acNomFileAct, acAniobuf);
   strcat(acNomFileAct, acMesbuf);
   strcat(acNomFileAct, acDiabuf);
   strcat(acNomFileAct, acExt);
  /* printf("\n acNomFileAct = %s\n", acNomFileAct);*/

   }



void CreaFile(FILE **pFile, char acNomFileAct[])
   {
   if ((*pFile = fopen(acNomFileAct, "a+t")) == NULL)
      {
      fprintf(stderr, "Cannot open output file.\n");
      exit(1);
      }

   }




[Hilos de Discusión] [Fecha] [Tema] [Autor]