Example #1
0
static void signal_handler(int sig) {
	int i;
        if (sig == SIGINT) {
            printf("Caught signal for Ctrl+C\n");
            exit(1);
        }
        if (sig == SIGTSTP) { // CTRL-z
        printf("\n...................SSL Info........................\n");
		printf("\n Current State: %d, ", cfg.sslC->state);
        printf("Version Req = %d, %d\n", cfg.sslC->versionResp[0],
                                        cfg.sslC->versionResp[1]);
        printf("  cfg.sslC->sessionID: Len: %d, Value: ", cfg.sslC->sessionIDLen);
        for (i=0;i<cfg.sslC->sessionIDLen;i++)
                printf("%hhx ", cfg.sslC->sessionID[i]);
        printf("\n  Handshake Responses: ");
        for (i=0;i<32;i++) {
                if (cfg.sslC->handshakeResp & (1<<i)) {
                        printf("%s ", msgToString(i));
                        fflush(stdout);

                }
        }
        }
        printf("\n...................................................\n");

}
Example #2
0
void CAsciiBufferLogger::logSent(const CByteBuffer& data)
{
   std::cout << "Yadoms >>> " << msgToString(data) << std::endl;
}
Example #3
0
/**
 * Daemon entry point.
 */
int main(int argc, char** argv) {
	int sock; // Listening UDP socket

	// Options
	char bDaemon=0,bOutputToNull=1;
	
	bVerbose=0; // Set global verbosity option to false

	// Program name (i.e. argv[0])
	char* progName;

	// Port to listen to (set to default)
	unsigned short port = SSD_DEFAULT_PORT;
	
	progName = argv[0]; // Note our program name
	argc--; argv++; // ...and get rid of it

	// Get all cmdline args
	while (argc >= 1 && argv[0][0]=='-') {
		switch (argv[0][1]) {
			case 'v': bVerbose=1; break;
			case 'O': bOutputToNull=0; break;
			case 'd': bDaemon=1; break;
			default: usage(progName); // Invalid argument, give the help message and exit
		}
		
		argc--; argv++; // Shift cmdline arguments to get rid of this option we just processed
	}

	// Check for port number on command line
	if (argc == 1) {
		port = atoi(argv[0]);
		if (port == 0) {
			fprintf(stderr,"Invalid port number '%s'!\n",argv[0]);
			return EXIT_FAILURE;
		}
	} else if (argc > 1) {
		usage(progName);
	}

	// Emit banner with options listing
	printf(
			TITLE "\n"
			"\n"
			"Options:\n"
			"  Verbose?      : %s\n"
			"  Daemon?       : %s\n"
			"  OutputToNull? : %s  (daemon mode only)\n"
			"\n",
	tf(bVerbose),
	tf(bDaemon),
	tf(bOutputToNull));

	// Read the gears file
	if (readGears() != 0) {
		fprintf(stderr,"Unable to read frequencies list from '%s'.\n",FILE_FREQ_LIST);
		return EXIT_FAILURE;
	}

	// Emit the detected gears
	printf("Gears:\n");
	int i;
	for (i=0; i<numGears; i++) {
		printf("  [%d] %d MHz\n",i,gearSpeeds[i]/1000);
	}
	printf("\n");

	// Become a daemon if we should
	if (bDaemon) {
		printf("Forking daemon...\n");
		daemonize(bOutputToNull);
	}

	// Create UDP socket for listening
	sock = makeUDPSocket(port);

	printf("Up and running!\n");
	while (1) { // Server loop
		struct sockaddr_in addrOther;
		SSDMessage msgIn,msgOut;
		int result;

		// Get next request
		result = recvMessage(sock, &msgIn, &addrOther);
		if (result != 0) {
			printf("Error receiving message...\n");
			continue;
		}

		if (bVerbose) printf("Got message %s.\n",msgToString(&msgIn));

		// Handle it
		char bValid;
		switch (msgIn.type) {
			case SSD_SET_SPEED:
				// Determine if this is a valid gear
				bValid = (msgIn.gear >= 0 && msgIn.gear < numGears);

				// Prepare response
				if (bValid) {
					msgOut.type = SSD_ACK;
					msgOut.gear = msgIn.gear;
					msgOut.freqKHz = gearSpeeds[msgIn.gear];
				} else {
					msgOut.type = SSD_NAK;
					msgOut.gear = -1;
					msgOut.freqKHz = -1;
				}

				// Send response
				if (bVerbose) printf("Sending response %s.\n",msgToString(&msgOut));
				sendMessage(sock, &msgOut, &addrOther);

				// Actually set gear
				if (bValid) setSpeed(msgIn.gear);
				break;

			case SSD_GET_SPEED:
				// Prepare response & check for validity
				msgOut.gear = getSpeed();
				
				bValid = (msgOut.gear >= 0 && msgOut.gear < numGears);
				
				if (bValid) {
					msgOut.type = SSD_ACK;
					msgOut.freqKHz = gearSpeeds[msgOut.gear];
				} else { // Error, send NAK
					msgOut.type = SSD_NAK;
					msgOut.gear = -1;
					msgOut.freqKHz = -1;
				}

				// Send response
				if (bVerbose) printf("Sending response %s.\n",msgToString(&msgOut));
				sendMessage(sock, &msgOut, &addrOther);
				break;

			case SSD_ACK:
			case SSD_NAK:
				printf("Daemon got an ACK/NAK?!?\n");

				break;
			default:
				printf("Daemon got message with invalid type %s.\n",msgToString(&msgIn));

		}
		
	}

	// We never get here, but who cares
	return EXIT_SUCCESS;
}
Example #4
0
void CAsciiBufferLogger::logReceived(const CByteBuffer& data) 
{
   std::cout << "Yadoms <<< " << msgToString(data) << std::endl;
}