/* * (c) Jul.2000 AngelFire / [LmT] * * Greetz: all members of [LmT] * and all my friendz that makes me happy of this shitty world. * * PLEASE DISTRIBUTE (sick of PRIVATE shitz!) * * Some code is of course stolen from its rightful owners. * */ #include #include #include #include #include #include #include #include #include #include #include #include //#define DEBUG char usage[] = "usage: x25scan -h -p -f -c nuafile\n" "-h : some x25 pad\n" "-p : port to connect to\n" "-f : file to log\n" "-c : log to console only... (disable log file)\n" "nuafile : file with nua's to scan (each on newline)\n"; char recvbuf[BUFSIZ], sendbuf[BUFSIZ], xpad[BUFSIZ], logf[BUFSIZ]; FILE *cin, *cout, *logfile, *nuafile; int timeout, response = 1, seconds = 0, minute = 0, port, fd; int logit( const char *fmt, ...) { va_list args; va_start(args, fmt); #ifdef DEBUG vfprintf(stderr, fmt, args); #endif va_end(args); return 0; } char *get_time( void ) { char *tim; time_t t; time(&t); tim=ctime(&t); tim[strlen(tim)-9]=0; strtok(tim," "); return strtok('\0', "\0"); } long getip( char *name ) { struct hostent *hp; long ip; extern int h_errno; if ((ip = inet_addr(name)) < 0) { if (!(hp = gethostbyname(name))) { fprintf(stderr, "gethostbyname(): %s\n", strerror(h_errno)); exit(1); } memcpy(&ip, (hp->h_addr), 4); } return ip; } int connecthost( char *host, int port) { int sockfd; struct sockaddr_in cli; bzero(&cli, sizeof(cli)); cli.sin_family = AF_INET; cli.sin_addr.s_addr=getip(host); cli.sin_port = htons(port); logit("Connecting to %s... ", xpad); if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { perror("socket"); return -1; } if(connect(sockfd, (struct sockaddr *)&cli, sizeof(cli)) < 0) { perror("connect"); close(sockfd); return -1; } cin = fdopen(sockfd, "r"); cout = fdopen(sockfd, "w"); if (!cin || !cout) { close(sockfd); return -1; } logit("Connected.\nSending 2xCR. just in case...\n"); sleep(3); (void)fputs("\r\n\r\n",cout); (void)fflush(cout); return sockfd; } int disconnecthost( int sock ) { logit("Disconnecting from %s...", xpad); close(sock); logit("Disconnected.\n"); return 0; } int command( const char *cmd ) { if (!cout) return -1; fprintf(cout, cmd); logit(">S> %s\n",cmd); fputs("\r\n", cout); (void)fflush(cout); return 0; } int alarmhandler( int signum ) { if ( response == 0 ) { seconds += 2; minute += 2; logit("seconds:%d minute:%d ",seconds,minute); if ( seconds > timeout ) { logit("... sending CR\n"); fprintf(cout, "\r\n"); fflush(cout); seconds = 0; alarm(2); return 0; } else { if ( minute > 20 ) { logit("... reconnecting\n"); disconnecthost(fd); sleep(2); if ((fd = connecthost(xpad, port)) < 0) { logit("Connection to %s failed.\n", xpad); exit(1); } seconds = minute = 0; response = 1; alarm(0); // doscan; logit("scaning...\n"); return 0; } logit("... setting new alarm\n"); alarm(2); return 0; } } else { return 0; } } int getreply( void ) { response = 0; seconds = 0; alarm(2); if (!(fgets(recvbuf, BUFSIZ, cin))) return -1; response = 1; logit("