int main(int argc, char *argv[]) { FILE *procfd; int delay = 50; char tty[20] = "/dev/"; struct utsname uname_dummy; char arg_dummy; int i; long j=0; iDebug = 5; if(argc < 3) { printf(help,banner,argv[0]); exit(0); } for(arg_dummy=3; arg_dummy < argc; arg_dummy++) { if(argv[arg_dummy][0] != '-') { printf("Error: option: %s\n", argv[arg_dummy]); exit(1); } switch(argv[arg_dummy][1]) { case 'c': if(argv[arg_dummy+1] == NULL || strlen(argv[arg_dummy+1]) != 3) freakout("-c option needs 3 chars"); led_config[0] = select_mode(argv[arg_dummy+1][0]); led_config[1] = select_mode(argv[arg_dummy+1][1]); led_config[2] = select_mode(argv[arg_dummy+1][2]); arg_dummy++; break; case 'd': if(argv[arg_dummy+1] == NULL) freakout("-d option needs an integer"); delay = atol(argv[arg_dummy+1]); arg_dummy++; break; case 'f': options |= OPT_FORK; break; case 'i': options |= OPT_INVERT; break; case 'a': options |= OPT_ALTKBCODE; break; case 'v': if (options & OPT_VERBOSE) options |= OPT_VVERBOSE; else options |= OPT_VERBOSE; break; case 'D': options |= OPT_DEBUG; break; default: printf("Error: option: %s\n",argv[arg_dummy]); exit(1); break; } } //if (options & OPT_VERBOSE) // iDebug = 2; //if (options & OPT_VVERBOSE) // iDebug = 3; if (options & OPT_DEBUG) { if ((fOut = fopen(szOutFile, "w")) == NULL) { status_msg("failed to open output file",1); } else { status_msg("starting aifled....",2); status_msg("successfully created output file",3); } } // check if forking and verbose // if ((options & OPT_VERBOSE) && (options & OPT_FORK)) // options -= OPT_VERBOSE; // if ((options & OPT_VVERBOSE) && (options & OPT_FORK)) // options -= OPT_VVERBOSE; uname(&uname_dummy); sprintf(szMsg,"kernel version: %s", uname_dummy.release); status_msg(szMsg,3); if(strncmp(uname_dummy.release,"2.0",3) == 0) options |= OPT_KERNEL_2_0; // Simmiyy - Extend Kernel family selection else if(strncmp(uname_dummy.release,"2.2",3) == 0 || strncmp(uname_dummy.release,"2.4",3) == 0) options |= OPT_KERNEL_2_2; // else if(strncmp(uname_dummy.release,"2.6",3) == 0) // options |= OPT_KERNEL_2_6; strcat(tty,argv[1]); sprintf(szMsg,"opening tty %s...",tty); status_msg(szMsg,2); if((ttyfd = open(tty,O_RDWR)) < 0) { sprintf(szMsg,"unable to open tty %s",tty); status_msg(szMsg,1); freakout("Unable to open tty."); } else { sprintf(szMsg,"successfully opened tty %s",tty); status_msg(szMsg,2); } if(options & OPT_FORK) fork_program(); else printf(banner); // if (options & OPT_VVERBOSE) // printf("running in very verbose mode...\n"); // else if (options & OPT_VERBOSE) // printf("running in verbose mode...\n"); if (options & OPT_VERBOSE) { sprintf(szMsg,"monitoring interface %s on tty %s", argv[2], argv[1]); status_msg(szMsg,1); for (i=0; i<3; i++) { sprintf(szMsg,"led%d: ", i); switch (led_config[i]) { case IF_RX: strcat(szMsg,"receive"); break; case IF_TX: strcat(szMsg,"transmit"); break; case IF_COLL: strcat(szMsg,"collision"); break; case IF_DROP_RX: strcat(szMsg,"drop (receive)"); break; case IF_DROP_TX: strcat(szMsg,"drop (transmit)"); break; case IF_ERR_TX: strcat(szMsg,"error (transmit)"); break; case IF_ERR_RX: strcat(szMsg,"error (receive)"); break; case IF_RXTX: strcat(szMsg,"activity"); break; case IF_DROP: strcat(szMsg,"drop"); break; case IF_ERR: strcat(szMsg,"error"); break; case IF_NONE: strcat(szMsg,"none"); break; case IF_ALIVE: strcat(szMsg,"red interface alive"); break; } status_msg(szMsg,1); } } status_msg("SIGINT signal_handler....",3); signal(SIGINT,signal_handler); status_msg("SIGTERM signal_handler....",3); signal(SIGTERM,signal_handler); status_msg("update_netproc....",3); update_netproc(argv[2]); status_msg("memcpy....",3); memcpy(&l_if_info,&if_info,sizeof(if_info)); while(1) { // if (options & OPT_VVERBOSE) // { //printf("%5d: ",j); //sprintf(szMsg,"%5d: ",j); //status_msg(szMsg,2); //j++; // printf("tx:%d rx:%d coll:%d tx_drop:%d rx_drop:%d err_tx:%d err_rx:%d alive:%d\n", // if_info[IF_TX],if_info[IF_RX],if_info[IF_COLL],if_info[IF_DROP_TX], // if_info[IF_DROP_RX],if_info[IF_ERR_TX],if_info[IF_ERR_RX],if_info[IF_ALIVE]); sprintf(szMsg,"tx:%d rx:%d coll:%d tx_drop:%d rx_drop:%d err_tx:%d err_rx:%d alive:%d", if_info[IF_TX],if_info[IF_RX],if_info[IF_COLL],if_info[IF_DROP_TX], if_info[IF_DROP_RX],if_info[IF_ERR_TX],if_info[IF_ERR_RX],if_info[IF_ALIVE]); status_msg(szMsg,2); // } status_msg("update_netproc....",3); update_netproc(argv[2]); status_msg("update_leds....",3); update_leds(tty); status_msg("usleep....",3); usleep(delay*1000); status_msg("done",3); } close(ttyfd); return 0; }
static bool _FrExecProgram(const char *hostname, int portnum, int &pipe_in, int &pipe_out, istream *&stream_in, ostream *&stream_out, ostream &err, const char *progname, char **arglist) { set_child_pid(-1) ; if (progname && *progname) { bool result ; if (portnum > 0) { #ifdef FrUSING_POPEN result = popen_program(arglist,err) ; if (result) #else int sp ; sp = spawnvp(P_NOWAIT,arglist[0],(char const * const *)arglist) == 0 ; if (sp == 0) #endif /* FrUSING_POPEN */ { result = true ; // wait for the child program to contact us FrSocket sock = FrAwaitConnection(portnum, FrPOPEN_LOAD_TIMEOUT, err,false) ; if (sock != (FrSocket)INVALID_SOCKET) { pipe_in = pipe_out = sock ; stream_in = new FrISockStream(sock) ; stream_out = new FrOSockStream(sock) ; if (!stream_in || !stream_in->good()) result = false ; // the child program is supposed to send us a line identifying // itself if (FramepaC_verbose) { char line[MAX_CMDLINE] ; stream_in->getline(line,sizeof(line)) ; err << "; Connected: " << line << endl ; } else stream_in->ignore(MAX_CMDLINE,'\n') ; } else result = false ; // close the listening socket to avoid having it hang around (void)FrAwaitConnection(-1,0,err,false) ; } } else { result = fork_program(arglist,pipe_in,pipe_out) ; if (result) { stream_in = Fr_ifstream(pipe_in) ; stream_out = Fr_ofstream(pipe_out) ; } } return result ; } else return connect_to_port(hostname,portnum,pipe_in, pipe_out, stream_in,stream_out) ; }