Пример #1
0
void Reporter::initReporter()
{
    timer = new QTimer(this);
    udpSocket = new QUdpSocket(this);
    
    Setting& setting = Setting::instance();
    
    hostDesc = setting.getHostDesc();
    timeInterval = setting.getBroadcastTimeValue();
    broadcastPort = setting.getBroadcastPort();
    listenPort = setting.getListenPort();
    
    getHostIp();

    timer->setInterval(timeInterval*1000);

    connect(&setting, SIGNAL(hostDescriptionChanged(const QString&)),
        this, SLOT(onHostDescChanged(const QString&)));
    connect(&setting, SIGNAL(broadcastTimaeValueChanged(int)),
        this, SLOT(onTimerChanged(int)));
    connect(&setting, SIGNAL(broadcastPortChanged(int)),
        this, SLOT(onBroadcastPortChanged(int)));

    connect(timer, SIGNAL(timeout()), this, SLOT(onTimeout()));

    stopThread = false;

    timer->start();

}
Пример #2
0
void createGraph(char *file){
	numberOfNodes = 1;
	fstream ifile;
	string line, nodeName;
	int position;
	ifile.open(file,ios::in);
	if (!ifile)
	{
		cout << "No config file found!! \n Program Terminating";
		exit(0);
	}
	else
	{
		ifile.unsetf(ios_base::skipws);
		while (getline(ifile,line))
		{
			//			cout << line<<"\n";
			if(line.empty()){continue;}
			numberOfNodes++;
			position = line.find(" ");
			nodeName = line.substr(0,position);
			nodesList.push_back(nodeName);
			labels[nodeName] = *(getHostIp(nodeName));
			if(strcasecmp(line.substr(position+1).c_str(),"yes")==0){
				neighbors.push_back(nodeName);
			}
		}
	}
	initializeSingleSourceGraph();
}
Пример #3
0
void whoAmI(){

	char *hostname = (char*)calloc(sizeof(char),1024);
	gethostname(hostname,1024);
	//cout << hostname;
	//rootnode.name="bandicoot.soic.indiana.edu";
	hostName =  hostname;
	labels[hostName] = *(getHostIp(hostName));
	nodesList.push_back(hostName);
}
Пример #4
0
UtlBoolean OsSocket::isLocalHost(const char* hostAddress)
{
        UtlBoolean local;
        UtlString thisHost;
        UtlString thisHostAddr;
        getHostName(&thisHost);
        getHostIp(&thisHostAddr);

        if(strcmp(hostAddress, "127.0.0.1") == 0 ||
                strcmp(hostAddress, "localhost") == 0 ||
                strcmp(hostAddress, thisHost.data()) == 0 ||
                strcmp(hostAddress, thisHostAddr.data()) == 0)
        {
                local = TRUE;
        }
        else
        {
                local = FALSE;
        }
        thisHost.remove(0);
        thisHostAddr.remove(0);
        return(local);
}
Пример #5
0
// sets the passive mode - data part
void d_pasv(char **params, short *abor, int fd,
	struct state *cstate, struct config *configuration) {
	int csockfd, newsock, port, retcode, optval = 1;
	struct sockaddr_in in;
	bzero(&in, sizeof (in));
	char ip[INET_ADDRSTRLEN], msg[STR_LENGTH];
	// default new port
	port = 30000;
	in.sin_family = AF_INET;
	// gets the IP adress the OS provides
	read(fd, &csockfd, sizeof (int));
	if (getHostIp(ip, csockfd) == -1)
		return;
	if (inet_pton(AF_INET, ip, &(in.sin_addr)) == -1) {
		retcode = 5;
		write(fd, &retcode, sizeof (int));
		return;
	}
	in.sin_port = htons(port);
	// server already listens - abort
	if (cstate->data_sock) {
		close(cstate->data_sock);
		// shutdown(cstate->data_sock, SHUT_RDWR);
		cstate->data_sock = 0;
	}
	// create new socket
	if ((newsock = socket(AF_INET, SOCK_STREAM, 6)) == -1) {
		perror("Error creating data socket.");
		retcode = 5;
		write(fd, &retcode, sizeof (int));
		return;
	}
	if (setsockopt(newsock, SOL_SOCKET, SO_REUSEADDR,
		&optval, sizeof (optval)) == -1) {
		perror("Problem occured while creating the socket.");
		retcode = 5;
		write(fd, &retcode, sizeof (int));
		close(newsock);
		return;
	}
	errno = 0;
	// tries to bind to different ports
	while ((bind(newsock, (struct sockaddr *) &in,
		sizeof (in)) == -1) && (errno == EADDRINUSE)) {
		if (++port > 32768)
			break;
		in.sin_port = htons(port);
		errno = 0;
	}
	if (errno) {
		perror("Error binding data socket.");
		retcode = 5;
		write(fd, &retcode, sizeof (int));
		close(newsock);
		return;
	}
	if (listen(newsock, SOMAXCONN) == -1) {
		perror("Error listening on control socket.");
		retcode = 5;
		write(fd, &retcode, sizeof (int));
		close(newsock);
		return;
	}
	// writes info about new IP address and socket to the control thread
	snprintf(msg, STR_LENGTH, "%s,%d,%d", ip, (port / 256), (port % 256));
	retcode = 2;
	write(fd, &retcode, sizeof (int));
	write(fd, msg, strlen(msg) + 1);
	cstate->data_sock = newsock;
	cstate->addr_family = 1;
}