void decode_pkt(struct pkt *current_pkt) { uint8_t pkt_type = current_pkt->data[0]; int ret; DEBUG_PRINT_PACKET(current_pkt->data, current_pkt->len); if ((pkt_type & ASYNC_FRAME_MASK) == ASYNC_FRAME_MASK) { // send to measures packets handler ret = handle_measure_pkt(current_pkt->data, current_pkt->len); } else { // answer commands ret = write_answer(current_pkt->data, current_pkt->len); } if (ret) { PRINT_ERROR("Error in decode packet: ret %d: " \ "len %d - 0x%02X 0x%02X\n", ret, current_pkt->len, current_pkt->data[0], current_pkt->data[1]); } }
int main (int argc, char **argv) { char * password = 0; char * username = 0; char expect = ':'; int opt, pty, pid, rc; int times = 1; while((opt = getopt(argc,argv,"+hrp:u:")) != -1) switch(opt) { case 'h': printf("%s",myexpect_usage); exit(0); break; case 'p': password = strdup(optarg); break; case 'u': username = strdup(optarg); break; case 'r': times = 2; break; default: fprintf(stderr,"Wrong option. Check usage\n"); fprintf(stderr,"%s",myexpect_usage); exit(-1); break; } if (password == 0 || username == 0 || optind >= argc ) { fprintf(stderr,"Wrong number of arguments. Check usage\n"); fprintf(stderr,"%s",myexpect_usage); exit(-1); } pid = forkpty(&pty,0,0,0); if(pid == 0) { struct termios tios; tcgetattr(pty, &tios); tios.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); tios.c_oflag &= ~(ONLCR); tcsetattr(pty, TCSANOW, &tios); execvp(argv[optind],&(argv[optind])); exit(-1); } else if (pid == -1) { perror("fork\n"); } while ( times > 0 ) { if (expect_char(pty,&expect,1) == -1) { return -1; } sleep(1); write_answer(pty,username); if (expect_char(pty,&expect,1) == -1) { return -1; } sleep(1); write_answer(pty,password); times = times - 1; } expect_char(pty,0,0); wait(&rc); return WEXITSTATUS(rc); }