Estoy programando una aplicacion para el curro.
Utiliza la libreria pthread para crear hilos, y hacer una tarea de toma de datos de forma concurrente.
Utilliza la libreria Chilkatssh para conectarse a equipo por ssh y tomar datos.
despues formateo los datos y los imprimo en pantalla.
para ello declaro un array de punteros de tipo struck que he creado para almacenar todos los datos. este puntero es el que le paso a la funcion que crea los hilos y ejecuta mi funcion que se conecta a los equipos, toma los datos, y los guarda, para que en el main, los imprima por pantalla.
La cosa, es que funcionar funciona. paro al cabo de un rato, me sale el tipico erro de win diciendome que la aplicacion ha sufrido un error y ha de cerrarse.
alguna idea¿?
Código
// LinkSample.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> using namespace std; #include <windows.h> // This example does nothing more than include a number of Chilkat headers // and instantiating objects for the purpose of demonstrating a clean build // and link (i.e. there are no unresolved externals). // If you didn't ready the README.html that is included with the download, // you should probably spend a few minutes reviewing it. It tells what // Chilkat lib should be linked, depending on the "Runtime Library" setting // in your Project Properties --> C++ --> Code Generation settings. // It also tells what additional Microsoft libs need to be added to your // list of link libraries, such as ws2_32.lib, crypt32.lib, etc. #include "../include/CkZip.h" #include "../include/CkFtp2.h" #include "../include/CkMailMan.h" #include "../include/CkXml.h" #include "../include/CkPrivateKey.h" #include "../include/CkRsa.h" #include "../include/CkHttp.h" #include "../include/CkMime.h" #include "../include/CkMht.h" #include "../include/CkRar.h" #include "../include/CkSsh.h" #include "../include/CkSshkey.h" #include "../include/CkSFtp.h" #include "../include/CkDkim.h" #include "../include/CkDirTree.h" #include "../include/CkRarEntry.h" #include <pthread.h> #define Tamaño_arg 10000 #define NUM_THREADS 30 #define x_equipo_cero 0 #define y_equipo_cero 4 #define x_valor_cero 22 #define y_ancho_equipo 6 #define x_canal 29 #define y_canal 2 #define x_canal_actual 12 #define y_error 80 #define x_num_iteracion 15 #define rojo 12 #define verde 10 #define neutro 7 #define gris 112 /* * estructura que sirve para que la función * 'ConectaSsh' obtenga los * datos del equipo */ typedef struct outThread { char * hostname; int port; int numEquipo; int icanalAP; long iteracion; int phy; int thp; int per; int snr; char *mac; char *macap; int actualizado; int error; char *errormsg; } ot; void gotoxy(int x, int y) { COORD coord; coord.X = x; coord.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); } void ColorearValores(char*tipo,int valor) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hConsole, 7); if ((strcmp(tipo,"PHY")== 0)) { if (valor <=24000) { SetConsoleTextAttribute(hConsole, rojo); }else if ((valor > 24000) && (valor <=36000)) { SetConsoleTextAttribute(hConsole, neutro); }else if (valor >36000) { SetConsoleTextAttribute(hConsole, verde); } }else if (strcmp(tipo,"THP")== 0) { if (valor <=10000) { SetConsoleTextAttribute(hConsole, rojo); }else if ((valor > 10000) && (valor <=18000)) { SetConsoleTextAttribute(hConsole, neutro); }else if (valor >18000) { SetConsoleTextAttribute(hConsole, verde); } }else if (strcmp(tipo,"PER")== 0) { if (valor <=29) { SetConsoleTextAttribute(hConsole, verde); }else if ((valor > 29) && (valor <=50)) { SetConsoleTextAttribute(hConsole, neutro); }else if (valor >50) { SetConsoleTextAttribute(hConsole, rojo); } }else if (strcmp(tipo,"SNR")== 0) { if (valor <=17) { SetConsoleTextAttribute(hConsole, rojo); }else if ((valor > 17) && (valor <=27)) { SetConsoleTextAttribute(hConsole, neutro); }else if (valor >27) { SetConsoleTextAttribute(hConsole, verde); } } return; } void ImprimirValores(char *tipo, int valor,int numEquipo,int canalAP) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); if ((strcmp(tipo,"PHY")== 0)) { gotoxy(x_valor_cero,y_equipo_cero + y_ancho_equipo*numEquipo); printf_s("PHY:"); gotoxy(x_canal+(canalAP-1)*4 ,y_equipo_cero + y_ancho_equipo*numEquipo); printf_s( " " ); gotoxy(x_canal+(canalAP-1)*4 ,y_equipo_cero + y_ancho_equipo*numEquipo); ColorearValores("PHY",valor); printf_s( "%d\n", valor/1000 ); }else if (strcmp(tipo,"THP")== 0) { gotoxy(x_valor_cero,y_equipo_cero +1 + y_ancho_equipo*numEquipo); printf_s("THP:"); gotoxy(x_canal+(canalAP-1)*4 ,y_equipo_cero +1 + y_ancho_equipo*numEquipo); printf_s( " " ); gotoxy(x_canal+(canalAP-1)*4 ,y_equipo_cero +1 + y_ancho_equipo*numEquipo); ColorearValores("THP",valor); printf_s( "%d\n", valor/1000 ); }else if (strcmp(tipo,"PER")== 0) { gotoxy(x_valor_cero,y_equipo_cero +2 + y_ancho_equipo*numEquipo); printf_s("PER:"); gotoxy(x_canal+(canalAP-1)*4 ,y_equipo_cero +2 + y_ancho_equipo*numEquipo); printf_s( " " ); gotoxy(x_canal+(canalAP-1)*4 ,y_equipo_cero +2 + y_ancho_equipo*numEquipo); ColorearValores("PER",valor); printf_s( "%d\n", valor ); }else if (strcmp(tipo,"SNR")== 0) { gotoxy(x_valor_cero,y_equipo_cero +3 + y_ancho_equipo*numEquipo); printf_s("SNR:"); gotoxy(x_canal+(canalAP-1)*4 ,y_equipo_cero +3 + y_ancho_equipo*numEquipo); printf_s( " " ); gotoxy(x_canal+(canalAP-1)*4 ,y_equipo_cero +3 + y_ancho_equipo*numEquipo); ColorearValores("SNR",valor); printf_s( "%d\n", valor ); } SetConsoleTextAttribute(hConsole, neutro); return; } int ComprobarMac(char *NroHexa) { //char NroHexa[100]; int i, Error; /** if((strlen(NroHexa)>19) || (strlen(NroHexa)<10)) { Error = 1; return Error; } **/ for( Error = 0, i = strlen(NroHexa) - 2; i>=0; i--) { if( !( ( NroHexa[i] >= 'A' && NroHexa[i] <= 'F' ) || ( NroHexa[i] >= 'a' && NroHexa[i] <= 'f' ) || ( NroHexa[i] >= '0' && NroHexa[i] <= '9' ) || ( NroHexa[i] >= ':' && NroHexa[i] <= ':' ) )) { Error = 1; break; } } return Error; } int ComprobarCH(char *NroHexa) { //char NroHexa[100]; int i, Error; if((atoi(NroHexa)>13) || (atoi(NroHexa)<1)) { Error = 1; return Error; } for( Error = 0, i = strlen(NroHexa) - 2; i>=0; i--) { if( !( NroHexa[i] >= '0' && NroHexa[i] <= '9' )) { Error = 1; break; } } return Error; } void* ConectaSsh(void *param) { // Important: It is helpful to send the contents of the // ssh.LastErrorText property when requesting support. //obtener valores del argumento de entrada tipo ot ot *parametros; parametros = (ot *)param; char * hostname = parametros->hostname; long port = parametros->port; int numEquipo = parametros->numEquipo; int icanalAP = parametros->icanalAP; parametros->error=1; //printf_s("valor de parametros.hosname %s\n de parametros.port %d\n de parametros.numEquipo %d\n de parametros.icanalAP %d\n",parametros.hostname,parametros.port,parametros.numEquipo,parametros.icanalAP); CkSsh ssh; HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); /** SetConsoleTextAttribute(hConsole, 14); gotoxy(17, 2); printf_s("%d", numEquipo +1); SetConsoleTextAttribute(hConsole, 7); **/ // Any string automatically begins a fully-functional 30-day trial. bool success; success = ssh.UnlockComponent("SSH12345678_738EFF5D8O0Z"); if (success != true) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } // Connect to an SSH server: success = ssh.Connect(hostname,port); if (success != true) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } // Wait a max of 5 seconds when reading responses.. ssh.put_IdleTimeoutMs(10000); // Wait a max of 5 seconds when responses.. ssh.put_ConnectTimeoutMs(10000); // Authenticate using login/password: success = ssh.AuthenticatePw("chilkat", "myPassword"); if (success != true) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } // Open a session channel. (It is possible to have multiple // session channels open simultaneously.) long channelNum; channelNum = ssh.OpenSessionChannel(); if (channelNum < 0) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } // Some SSH servers require a pseudo-terminal // If so, include the call to SendReqPty. If not, then // comment out the call to SendReqPty. // Note: The 2nd argument of SendReqPty is the terminal type, // which should be something like "xterm", "vt100", "dumb", etc. // A "dumb" terminal is one that cannot process escape sequences. // Smart terminals, such as "xterm", "vt100", etc. process // escape sequences. If you select a type of smart terminal, // your application will receive these escape sequences // included in the command's output. Use "dumb" if you do not // want to receive escape sequences. (Assuming your SSH // server recognizes "dumb" as a standard dumb terminal.) const char * termType; termType = "dumb"; long widthInChars; widthInChars = 120; long heightInChars; heightInChars = 40; // Use 0 for pixWidth and pixHeight when the dimensions // are set in number-of-chars. long pixWidth; pixWidth = 0; long pixHeight; pixHeight = 0; success = ssh.SendReqPty(channelNum,termType,widthInChars,heightInChars,pixWidth,pixHeight); if (success != true) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } // Start a shell on the channel: success = ssh.SendReqShell(channelNum); if (success != true) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } // Start a command in the remote shell. Login. success = ssh.ChannelSendString(channelNum,"*****\n","ansi"); if (success != true) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } //Read untel we get thr prompt fo the password: success = ssh.ChannelReceiveUntilMatch(channelNum,"password :","ansi",true); if (success != true) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } // Display what we've received so far: const char * cmdOutputDebug; cmdOutputDebug = ssh.getReceivedText(channelNum,"ansi"); if (cmdOutputDebug == 0 ) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } //printf_s("n%s\n",cmdOutputDebug); // Start a command in the remote shell. Password success = ssh.ChannelSendString(channelNum,"********\n","ansi"); if (success != true) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } // Display what we've received so far: cmdOutputDebug = ssh.getReceivedText(channelNum,"ansi"); if (cmdOutputDebug == 0 ) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } //printf_s("%s\n",cmdOutputDebug); //Read untel we get thr prompt fo the rkcli: success = ssh.ChannelReceiveUntilMatch(channelNum,"rkscli:","ansi",true); if (success != true) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } // Display what we've received so far: cmdOutputDebug = ssh.getReceivedText(channelNum,"ansi"); if (cmdOutputDebug == 0 ) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } //printf_s("%s\n",cmdOutputDebug); //obtener macs // Start a command in the remote shell. chanel success = ssh.ChannelSendString(channelNum,"get wlanlist\n","ansi"); if (success != true) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } // Read whatever output may already be available on the // SSH connection. ChannelReadAndPoll returns the number of bytes // that are available in the channel's internal buffer that // are ready to be "picked up" by calling GetReceivedText // or GetReceivedData. // A return value of -1 indicates failure. // A return value of -2 indicates a failure via timeout. // The ChannelReadAndPoll method waits // for data to arrive on the connection usingi the IdleTimeoutMs // property setting. Once the first data arrives, it continues // reading but instead uses the pollTimeoutMs passed in the 2nd argument: // A return value of -2 indicates a timeout where no data is received. long n; long pollTimeoutMs; pollTimeoutMs = 2000; n = ssh.ChannelReadAndPoll(channelNum,pollTimeoutMs); if (n < 0) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } // Mostramos en que canal esta el ap: const char * macs = ssh.getReceivedText(channelNum,"ansi"); if (macs == 0 ) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } char *string1 =const_cast<char*> (macs); char seps[] = " \t\n"; char *token1 = NULL; char *next_token1 = NULL; // Establish string and get the first token: token1 = strtok_s( string1, seps, &next_token1); // While there are tokens in "string1" or "string2" int bmac =1; while ((token1 != NULL) && (bmac <=100)) { // Get next token: if (token1 != NULL) { token1 = strtok_s( NULL, seps, &next_token1); bmac++; if ((bmac == 14)&&(!ComprobarMac(token1))) parametros->mac = token1; if ((bmac == 19)&&(!ComprobarMac(token1))) parametros->macap = token1; } } //obtener chanel // Start a command in the remote shell. chanel success = ssh.ChannelSendString(channelNum,"get channel svcp\n","ansi"); if (success != true) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } // Read whatever output may already be available on the // SSH connection. ChannelReadAndPoll returns the number of bytes // that are available in the channel's internal buffer that // are ready to be "picked up" by calling GetReceivedText // or GetReceivedData. // A return value of -1 indicates failure. // A return value of -2 indicates a failure via timeout. // The ChannelReadAndPoll method waits // for data to arrive on the connection usingi the IdleTimeoutMs // property setting. Once the first data arrives, it continues // reading but instead uses the pollTimeoutMs passed in the 2nd argument: // A return value of -2 indicates a timeout where no data is received. pollTimeoutMs = 2000; n = ssh.ChannelReadAndPoll(channelNum,pollTimeoutMs); if (n < 0) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } // Mostramos en que canal esta el ap: const char * canalAP = ssh.getReceivedText(channelNum,"ansi"); if (canalAP == 0 ) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } char *string2 =const_cast<char*> (canalAP); // Establish string and get the first token: token1 = strtok_s( string2, seps, &next_token1); // While there are tokens in "string1" or "string2" int bChanel =1; while ((token1 != NULL) && (bChanel <=5)) { // Get next token: if (token1 != NULL) { token1 = strtok_s( NULL, seps, &next_token1); bChanel++; } } if (!ComprobarCH(token1))canalAP = token1; //debug de canalAP /** gotoxy(x_equipo_cero ,y_equipo_cero +2 + y_ancho_equipo*numEquipo); printf_s( " CH actual: " ); SetConsoleTextAttribute(hConsole, 14); gotoxy(x_canal_actual ,y_equipo_cero +2 + y_ancho_equipo*numEquipo); printf_s( "%s", canalAP ); SetConsoleTextAttribute(hConsole, 7); **/ // Start a command in the remote shell. valores success = ssh.ChannelSendString(channelNum,"get station svcp stats all\n","ansi"); if (success != true) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } // Display what we've received so far: cmdOutputDebug = ssh.getReceivedText(channelNum,"ansi"); if (cmdOutputDebug == 0 ) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } //printf_s("%s\n",cmdOutputDebug); // Read whatever output may already be available on the // SSH connection. ChannelReadAndPoll returns the number of bytes // that are available in the channel's internal buffer that // are ready to be "picked up" by calling GetReceivedText // or GetReceivedData. // A return value of -1 indicates failure. // A return value of -2 indicates a failure via timeout. // The ChannelReadAndPoll method waits // for data to arrive on the connection usingi the IdleTimeoutMs // property setting. Once the first data arrives, it continues // reading but instead uses the pollTimeoutMs passed in the 2nd argument: // A return value of -2 indicates a timeout where no data is received. //long n; //long pollTimeoutMs; pollTimeoutMs = 2000; n = ssh.ChannelReadAndPoll(channelNum,pollTimeoutMs); if (n < 0) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } // Send an EOF. This tells the server that no more data will // be sent on this channel. The channel remains open, and // the SSH client may still receive output on this channel. success = ssh.ChannelSendEof(channelNum); if (success != true) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } // Close the channel: success = ssh.ChannelSendClose(channelNum); if (success != true) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } // Perhaps we did not receive all of the commands output. // To make sure, call ChannelReceiveToClose to accumulate any remaining // output until the server's corresponding "channel close" is received. success = ssh.ChannelReceiveToClose(channelNum); if (success != true) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } // Let's pickup the accumulated output of the command: const char * cmdOutput; cmdOutput = ssh.getReceivedText(channelNum,"ansi"); if (cmdOutput == 0 ) { parametros->error=1; parametros->errormsg = const_cast<char*> (ssh.lastErrorText()); pthread_exit(NULL); return NULL; } // Display the remote shell's command output: //printf_s("esto es los que me da despues de cerrar el chanel:\n%s\n",cmdOutput); //Vamos a dividir la salida e imprimir solo lo que nos interesa: string1 =const_cast<char*> (cmdOutput); token1 = NULL; next_token1 = NULL; // Establish string and get the first token: token1 = strtok_s( string1, seps, &next_token1); // While there are tokens in "string1" or "string2" while (token1 != NULL) { // Get next token: if (token1 != NULL) { //printf_s( "%s\n", token1 ); token1 = strtok_s( NULL, seps, &next_token1); if (strcmp(token1,"tx_rate")== 0) { token1 = strtok_s( NULL, seps, &next_token1); parametros->phy = atoi(const_cast<char*> (token1)); }else if (strcmp(token1,"tx_kbps")== 0) { token1 = strtok_s( NULL, seps, &next_token1); parametros->thp = atoi(const_cast<char*> (token1)); }else if (strcmp(token1,"tx_per")== 0) { token1 = strtok_s( NULL, seps, &next_token1); parametros->per = atoi(const_cast<char*> (token1)); }else if (strcmp(token1,"tx_rssi")== 0) { token1 = strtok_s( NULL, seps, &next_token1); parametros->snr = atoi(const_cast<char*> (token1)); break; } } } //Calcular la iteracion if (parametros->icanalAP!=atoi(canalAP) ) { parametros->iteracion=0; }else parametros->iteracion=parametros->iteracion+1; //actualizar icanalAP parametros->icanalAP = atoi(canalAP) ; // Disconnect ssh.Disconnect(); parametros->error=0; return NULL; } int main(int argc,char *argv[]) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); pthread_t threads[NUM_THREADS]; int port; // Hostname may be an IP address or hostname: //char *hostname; //hostname = "212.63.98.64"; port = 22; //Lo usare para el tema de los colores /** // you can loop x higher to see more color choices for(int x = 1; x < 255; x++) { // pick the colorattribute x you want SetConsoleTextAttribute(hConsole, x); printf_s("%d\tColorful text!",x); } printf_s("compilado por mi\n"); system("pause"); return 0; **/ //Posible configuracion de salida printf_s("Vamos a estudiar los valores de los siguientes equipos:\n"); /** int i; printf_s("Se han pasado %3d argumentos:\n", argc); for(i=0; i<argc; i++) printf_s("%5d- %s\n", i, argv[i]); system("pause"); return 0; **/ char ips[Tamaño_arg]; if (argc==1){ printf_s( "Introduce las IPs de los equipos separadas por ';' :" ); scanf_s("%s",ips); }else strcpy_s(ips,sizeof(ips),argv[1]); gotoxy(0,1); printf_s("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"); gotoxy(0,y_canal); printf_s("Numero de equipos: "); gotoxy(x_canal,y_canal); SetConsoleTextAttribute(hConsole, 55); printf_s("01 02 03 04 05 06 07 08 09 10 11 12 13\n"); SetConsoleTextAttribute(hConsole, 7); //por si hace falta getch(); no hace eco en la pantalla del caracter leido. /** //llamar al colasoft char colasoft[1024]; strcpy_s(colasoft,"\"%propramfiles%\\COLASO~1.1\\CPing.exe\" "); printf_s("%s",ips);c:\\ strcat_s(colasoft,ips); printf_s("%s\n",colasoft); system(colasoft); printf_s("compilado por mi\n"); system("pause"); return 0; **/ //char *equipos[20]; //obtener valores del argumento de entrada tipo ot //ot *ptr[NUM_THREADS] ; ot *ptr; ot parametros[NUM_THREADS]; int rc; //Inicio los del los equipos for (int i=0;i<NUM_THREADS; i++){ parametros[i].icanalAP = 0; parametros[i].iteracion = 0; parametros[i].error = 0; parametros[i].mac =""; parametros[i].macap =""; } while(true) { //ConectaSsh(hostname,port); char string1[Tamaño_arg]; strcpy_s(string1,sizeof(string1),ips); char seps[] = ",;:\t "; char *token1 = NULL; char *next_token1 = NULL; int maxNumEquipo=0; int numEquipo=0; // Establish string and get the first token: token1 = strtok_s( string1, seps, &next_token1); // While there are tokens in "string1" or "string2" while (token1 != NULL) { // Get next token: if (token1 != NULL) { //Imprimir hostname y numequipo gotoxy(x_equipo_cero ,y_equipo_cero + y_ancho_equipo*numEquipo); SetConsoleTextAttribute(hConsole, 14); printf_s( "%d\n", numEquipo +1 ); SetConsoleTextAttribute(hConsole, 7); gotoxy(x_equipo_cero +3,y_equipo_cero + y_ancho_equipo*numEquipo); printf_s( "%s\n", token1); gotoxy(x_equipo_cero, y_canal); ptr = ¶metros[numEquipo]; if(parametros[numEquipo].error == 0) { parametros[numEquipo].hostname = token1; parametros[numEquipo].numEquipo = numEquipo; parametros[numEquipo].port = port; rc = pthread_create(&threads[numEquipo], NULL, ConectaSsh, (void *)ptr); if (rc){ gotoxy(0,y_equipo_cero + y_ancho_equipo*(maxNumEquipo+1)); printf_s("ERROR; return code from pthread_create() is %d\n",numEquipo+1); exit(-1); } } numEquipo++; token1 = strtok_s( NULL, seps, &next_token1); } if(maxNumEquipo<=numEquipo) maxNumEquipo=numEquipo; } //Imprimir nº de equipos a estudiar SetConsoleTextAttribute(hConsole, 14); gotoxy(20, y_canal); printf_s("%d", maxNumEquipo ); SetConsoleTextAttribute(hConsole, 7); Sleep(10000); //Imprimimos los valores for(int i =0; i<maxNumEquipo; i++) { //Imprimir valroes if((parametros[i].error == 0 ) && parametros[i].icanalAP){ ImprimirValores("PHY",parametros[i].phy,i,parametros[i].icanalAP); ImprimirValores("THP",parametros[i].thp,i,parametros[i].icanalAP); ImprimirValores("PER",parametros[i].per,i,parametros[i].icanalAP); ImprimirValores("SNR",parametros[i].snr,i,parametros[i].icanalAP); //Imprimir ultimo canal y macs gotoxy(x_equipo_cero ,y_equipo_cero +2 + y_ancho_equipo*i); printf_s( " Ultimo CH: " ); SetConsoleTextAttribute(hConsole, 14); gotoxy(x_canal_actual ,y_equipo_cero +2 + y_ancho_equipo*i); printf_s( "%d", parametros[i].icanalAP ); SetConsoleTextAttribute(hConsole, 7); gotoxy(x_equipo_cero ,y_equipo_cero +1 + y_ancho_equipo*i); if (!ComprobarMac(parametros[i].mac)) printf_s( " %s\n", parametros[i].mac ); gotoxy(x_equipo_cero ,y_equipo_cero +3 + y_ancho_equipo*i); if (!ComprobarMac(parametros[i].macap)) printf_s( "AP %s\n", parametros[i].macap ); //Imprimir nº Iteracion gotoxy(x_num_iteracion ,y_equipo_cero +2 + y_ancho_equipo*i); printf_s( "%d", parametros[i].iteracion ); gotoxy(20, y_canal); } //Imprimir erores /** if(parametros[i].error){ gotoxy(0,y_equipo_cero + y_ancho_equipo*(maxNumEquipo+1)); printf_s("Error en el equipo %d:\n%s",i+1, parametros[i].errormsg); gotoxy(0,y_canal); } **/ } /** gotoxy(0,y_ancho_equipo*(maxNumEquipo+1)); printf_s("numEquipo %d\nlos valores de %s\ncanal %d\nIteracion %d\nerror: %d\nMacap %s\n%d\n%d\n%d\n%d",parametros[0].numEquipo,parametros[0].hostname, parametros[0].icanalAP,parametros[0].iteracion,parametros[0].error,parametros[0].macap,parametros[0].phy,parametros[0].thp,parametros[0].per,parametros[0].snr); gotoxy(0,y_ancho_equipo*(maxNumEquipo+1)+10); printf_s("numEquipo %d\nlos valores de %s\ncanal %d\nIteracion %d\nerror: %d\nMacap %s\n%d\n%d\n%d\n%d",parametros[1].numEquipo,parametros[1].hostname, parametros[1].icanalAP,parametros[1].iteracion,parametros[1].error,parametros[1].macap,parametros[1].phy,parametros[1].thp,parametros[1].per,parametros[1].snr); gotoxy(0,y_canal); **/ } pthread_exit(NULL); printf_s("compilado por mi\n"); system("pause"); return 0; }
He cambiado las credenciales por seguridad... pero si alguien viera donde pierdo los punteros o arrays... se que hay mucha cosa comentada en plan prueba
Gracias y un saludo.