double SR865::getOUTP(const QString &i) const { if (isValidString(this->outputNumberListLongName, i)) return getOUTP(numberFromString(this->outputNumberListLongName, i)); if (isValidString(this->outputNumberListShortName, i)) return getOUTP(numberFromString(this->outputNumberListShortName, i)); return 0; }
int SR865::outpNumberFromString(const QString &outp_string) const { if (isValidString(this->outputNumberListLongName, outp_string)) return numberFromString(this->outputNumberListLongName, outp_string); if (isValidString(this->outputNumberListShortName, outp_string)) return numberFromString(this->outputNumberListShortName, outp_string); return -1; }
int main(int argc, char** argv) { if(checkArgc(argc, 5, "You must supply a VPN IP, VPN Port, Server IP, and Server Port!")) { return 1; } int vpnPort = parseAndCheckPort(argv[2]); #ifdef Debug printf("VPN Port: %d\r\n", vpnPort); #endif int msglen = strlen(argv[3]) + strlen(argv[4]) + 4; int x; char *buffer = mallocAndCheck(sizeof(char)*msglen); for(x = 0; x < msglen; x++) buffer[x] = 0; socklen_t addrlen = (socklen_t)sizeof(struct sockaddr_storage); int udpSocket = bindUDPSocket(); struct sockaddr_in vpnaddr; vpnaddr.sin_family = AF_INET; vpnaddr.sin_port = htons(vpnPort); // Parse the arg given to us for the IP if(inet_pton(AF_INET, argv[1], &(vpnaddr.sin_addr)) <= 0) { write(2, "Failed to parse IP Address!\r\n", 29); return -1; } #ifdef Debug printf("Server Address: %s\r\n", inet_ntoa(vpnaddr.sin_addr)); #endif strcpy(buffer, argv[3]); strcat(buffer, "\r\n"); strcat(buffer, argv[4]); strcat(buffer, "\r\n"); if(sendto(udpSocket, buffer, msglen, 0, (struct sockaddr *)&vpnaddr, addrlen) <= 0) { perror("Sendto"); return 1; } printf("Sent:\r\n%s\r\n", buffer); memset(buffer, 0, 1024); while(recvfrom(udpSocket, buffer, 1024, 0, (struct sockaddr *)&vpnaddr, &addrlen) <= 0) { } printf("VPN Port: %d\r\n", numberFromString(buffer)); }
int SR865::timeConstantNumberFromString(const QString &timeConstant_string) const { return numberFromString(this->timeConstantList, timeConstant_string); }
int SR865::sensivityNumberFromString(const QString &sensivity_string) const { return numberFromString(this->sensivityList, sensivity_string); }
int SR865::currentInputGainNumberFromString(const QString ¤tInputGain_string) const { return numberFromString(this->currrentInputGainList, currentInputGain_string); }
int SR865::voltageInputRangeNumberFromString(const QString &voltageInputRange_string) const { return numberFromString(this->voltageInputRangeList, voltageInputRange_string); }
int SR865::voltageInputShieldsNumberFromString(const QString &voltageInputShields_string) const { return numberFromString(this->voltageInputShieldsList, voltageInputShields_string); }
int SR865::voltageInputCouplingNumberFromString(const QString &voltageInputCoupling_string) const { return numberFromString(this->voltageInputCouplingList, voltageInputCoupling_string); }
int SR865::refOutputZNumberFromString(const QString &outpZ_string) const { return numberFromString(this->referenceTriggerOutputZList, outpZ_string); }
int SR865::refModeNumberFromString(const QString &mode_string) const { return numberFromString(this->referenceTriggerModeList, mode_string); }
int SR865::refSourceNumberFromString(const QString &ref_string) const { return numberFromString(this->referenceSourceList, ref_string); }
int DS345::modulationTypeNumberFromString(const QString &type_string) const { return numberFromString(this->modulationTypeList, type_string); }
int DS345::modulationFunctionNumberFromString(const QString &function_string) const { return numberFromString(this->modulationFunctionList, function_string); }
int SR865::filterNumberFromString(const QString &filter_string) const { return numberFromString(this->filterList, filter_string); }
int SR865::signalInputNumberFromString(const QString &signalInput_string) const { return numberFromString(this->signalInputList, signalInput_string); }
int main(int argc, char**argv) { if (argc < 4) { write(2, "You must supply an IP address, a port, and a secret key!\r\n", 25); return -1; } #ifdef Debug printf("Argv[1]: %s\r\nArgv[2]: %s\r\nArgv[3]: %s\r\n", argv[1], argv[2], argv[3]); #endif int port = numberFromString(argv[2]); if (port < 49152 || port > 65535) { write(2, "The port must be between 49152 and 65535!\r\n", 43); return -1; } #ifdef Debug printf("Port: %d\r\n", port); #endif // Malloc space for our secret key secret = mallocAndCheck(sizeof(char)*strlen(argv[3])); strcpy(secret, argv[3]); #ifdef Debug printf("Secret: %s\r\n", secret); #endif char *buffer = mallocAndCheck(sizeof(char)*1024); int x; for(x = 0; x < 1024; x++) { buffer[x] = '\0'; } int msglen = 1024; addrlen = (socklen_t)sizeof(struct sockaddr_storage); udpSocket = socket(AF_INET, SOCK_DGRAM, 0); if(udpSocket <= 0) { write(2, "Unable to bind socket!\r\n", 24); return -1; } registeredaddr = mallocAndCheck(addrlen); ((struct sockaddr_in *)registeredaddr)->sin_family = AF_INET; ((struct sockaddr_in *)registeredaddr)->sin_port = htons(port); // Parse the arg given to us for the IP if(inet_pton(AF_INET, argv[1], &((struct sockaddr_in *)registeredaddr)->sin_addr) <= 0) { write(2, "Failed to parse IP Address!\r\n", 29); return -1; } int reminders = 1; int registered = 0; int lastReminder = 0; setClientAlarmHandler(); // While we have reminders to receive while(reminders) { for(x = 0; x < 1024; x++) { buffer[x] = '\0'; } // If we've not registered, send a registration packet if(!registered) { registration(0); } // Busy wait for a packet while(recvfrom(udpSocket, buffer, msglen, 0, registeredaddr, &addrlen) <= 0) { // If we've not received a registration ACK // and we don't have an alarm set to send it // again, we'll set a timer if(!alarmSet) setClientAlarm(); } #ifdef Debug printf("\r\nReceived: %s\r\n", buffer); #endif // Exit packet will tell us when we're done if(strcmp(buffer, "Exit\r\n\r\n") == 0) { write(2, "All Reminders Received!\r\n", 25); reminders = 0; } // Our registration was dropped! else if (strcmp(buffer, "DropRegistration\r\n\r\n") == 0) { write(2, "Registration Dropped!\r\n", 23); registered = 0; } // Our registration was accepted! else if (strcmp(buffer, "Registered\r\n\r\n") == 0) { write(2, "Registered!\r\n", 13); registered = 1; alarm(0); } // Default case else { int number = numberFromString(buffer); #ifdef Debug printf("Received: %d, Last: %d\r\n", number, lastReminder); #endif // If we've received a reminder that is more than just the increment // of the last one, send the resend packet if(number - lastReminder > 1) { // WE LOST A PACKET! char* resend = mallocAndCheck(sizeof(char)*8 + sizeof(int)); memset(resend, 0, sizeof(char)*8 + sizeof(int)); strcpy(resend, "Resend\t"); strcat(resend, timeToString(lastReminder+1)); mySendTo(udpSocket, resend, strlen(resend), 0, registeredaddr, addrlen); } // Otherwise, cancel our registration alarm if we've had one // and update our last received reminder. // Display the reminder packet; else { alarm(0); alarmSet = 0; lastReminder = number; write(2, buffer, strlen(buffer)); write(2, "\r\n", 2); } } } return 0; }
int main(int argc, char** argv) { // Argument check if (argc < 2) { write(2, "You must supply a port!\r\n", 25); return -1; } // Port parse and check int port = numberFromString(argv[1]); if (port < 49152 || port > 65535) { write(2, "The port must be between 49152 and 65535!\r\n", 43); return -1; } #ifdef Debug printInt(port); write(2, "\r\n", 2); #endif // Struct for the incoming connection struct sockaddr clientaddr; socklen_t addrlen = (socklen_t)sizeof(struct sockaddr_storage); int msglen = 1024; char buffer[msglen]; // Socket alloc int tcpSocket = socket(AF_INET, SOCK_STREAM, 0); if(tcpSocket <= 0) { write(2, "Unable to bind socket!\r\n", 24); return -1; } // My own address struct, choosing any possible IN ADDRESS struct sockaddr_in myaddr; myaddr.sin_family = AF_INET; myaddr.sin_port = htons(port); myaddr.sin_addr.s_addr = INADDR_ANY; // Bind up the socket to myself if(bind(tcpSocket, (struct sockaddr*)&myaddr, sizeof(struct sockaddr))) { perror("Bind"); return -1; } if(listen(tcpSocket, 1) != 0) { perror("Listen"); return -1; } int new_socket; // Infinite response int resp; while(1) { if((new_socket = accept(tcpSocket, &clientaddr, &addrlen)) < 0) { perror("Accept"); return -1; } // receive the message while(read(new_socket, buffer, msglen) <= 0) {} // Indicate our success write(2, "Got a message!\r\n", 16); // FORK! int pid = fork(); #ifdef Debug printf("PID: %d\r\n", pid); #endif // Child process if(pid == 0) { // Send it right back to them, round trip baby! resp = write(new_socket, buffer, msglen); if(resp <= 0) { write(2, "The message could not be sent!\r\n", 32); break; } } // Failed to fork else if (pid == -1) { perror("Fork failed"); break; } // We're the parent, so we do nothing. else { } } return 0; }