// Fill a tpStats structure with the contents from a STATS line int GetStatsFromLine(char *line, TPStats *s) { char valBuf[30]; if (strncmp(line, "STATS ", 6) != 0) return -1; memset(valBuf, 0, 30); if (CopyTagField(valBuf, 29, line+6, "majorv")) s->MajorVersion = atoi(valBuf); if (CopyTagField(valBuf, 29, line+6, "minorv")) s->MinorVersion = atoi(valBuf); if (CopyTagField(valBuf, 29, line+6, "pktssent")) s->PktsSent = atoi(valBuf); if (CopyTagField(valBuf, 29, line+6, "pktsunsent")) s->PktsUnSent = atoi(valBuf); if (CopyTagField(valBuf, 29, line+6, "pktsrcvd")) s->PktsRecvd = atoi(valBuf); if (CopyTagField(valBuf, 29, line+6, "bytessent")) sscanf(valBuf, "%" LONG_LONG_PREFIX "d", &(s->BytesSent)); if (CopyTagField(valBuf, 29, line+6, "bytesrcvd")) sscanf(valBuf, "%" LONG_LONG_PREFIX "d", &(s->BytesRecvd)); if (CopyTagField(valBuf, 29, line+6, "maxrtt")) s->MaxRoundtrip = atoi(valBuf); if (CopyTagField(valBuf, 29, line+6, "minrtt")) s->MinRoundtrip = atoi(valBuf); if (CopyTagField(valBuf, 29, line+6, "oocount")) s->ooCount = atoi(valBuf); if (CopyTagField(valBuf, 29, line+6, "txstart_s")) s->StartSend.tv_sec = atoi(valBuf); if (CopyTagField(valBuf, 29, line+6, "txstart_us")) s->StartSend.tv_usec = atoi(valBuf); if (CopyTagField(valBuf, 29, line+6, "txstop_s")) s->StopSend.tv_sec = atoi(valBuf); if (CopyTagField(valBuf, 29, line+6, "txstop_us")) s->StopSend.tv_usec = atoi(valBuf); if (CopyTagField(valBuf, 29, line+6, "rxstart_s")) s->StartRecv.tv_sec = atoi(valBuf); if (CopyTagField(valBuf, 29, line+6, "rxstart_us")) s->StartRecv.tv_usec = atoi(valBuf); if (CopyTagField(valBuf, 29, line+6, "rxstop_s")) s->StopRecv.tv_sec = atoi(valBuf); if (CopyTagField(valBuf, 29, line+6, "rxstop_us")) s->StopRecv.tv_usec = atoi(valBuf); if (CopyTagField(valBuf, 29, line+6, "totrtt")) s->TotalRoundtrip = atoi(valBuf); if (CopyTagField(valBuf, 29, line+6, "nortt")) s->nRoundtrips = atoi(valBuf); if (CopyTagField(valBuf, 101, line + 6, "email")) strcpy(s->email, valBuf); if (CopyTagField(valBuf, 101, line + 6, "pwd")) strcpy(s->pwd, valBuf); return 0; }
/* * Perform a test session. */ static void DoSession( int CtrlSock ) { struct sockaddr_in LocSa; struct stat statbuf; int SaLen, Vmajor, Vminor; char str[256], *line, *p; /* * Get the source address from the control socket. */ SaLen = sizeof LocSa; if( getpeername( CtrlSock, (struct sockaddr *)(&LocSa), &SaLen ) != 0 ) { syslog( LOG_ERR, "Can't get source address from control socket (%m)" ); close( CtrlSock ); exit( 1 ); } syslog( LOG_INFO, "Connection from %s:%d", inet_ntoa( LocSa.sin_addr ), ntohs( LocSa.sin_port ) ); SourceAddress = LocSa.sin_addr; /* * Check if DENYFILE exists and if so, refuse connection */ if (stat(DENYFILE, &statbuf) == 0) { syslog( LOG_INFO, "Connection from %s:%d refused: DENYFILE (%s) exists", inet_ntoa( LocSa.sin_addr ), ntohs( LocSa.sin_port ), DENYFILE); Reply(CtrlSock, 410, "Service temporarily disabled. Please try later"); usleep( 200000 ); close( CtrlSock ); exit( 1 ); } /* * Get the HELO/INFO request from a client */ if ((line = ReadLineTimeout(CtrlSock, 10)) == NULL) { close( CtrlSock ); exit( 1 ); } p = line; if (strncmp(p, "HELO ", 5) != 0) { if (strncmp(p, "INFO", 4) != 0) { Reply(CtrlSock, 510, "Syntax error"); close( CtrlSock ); exit( 1 ); } else { /* Send INFO */ char str[100]; int i = 0; while (strlen(Info[i])) { sprintf(str, "250-%s\r\n", Info[i]); if (write(CtrlSock, str, strlen(str)) != strlen(str)) { syslog( LOG_ERR, "Error writing to socket (%m)"); close( CtrlSock ); exit( 1 ); } i++; } Reply(CtrlSock, 250, ""); } } else { char tBuf[50]; memset(tBuf, 0, 50); p += 5; if (CopyTagField(tBuf, 49, p, "vmajor")) Vmajor = atoi(tBuf); else Vmajor = 0; if (CopyTagField(tBuf, 49, p, "vminor")) Vminor = atoi(tBuf); else Vminor = 0; if (Vmajor < MajorVersion) { sprintf(str, "You need to upgrade, Go to %s", UPGRADE_URL); Reply(CtrlSock, 501, str); usleep( 200000 ); close( CtrlSock ); exit( 1 ); } SendServerList( CtrlSock ); } usleep( 200000 ); close( CtrlSock ); exit( 0 ); }