Beispiel #1
0
void MainWindow::on_mainAir_clicked()
{
    menu = 4;
    int j=0;
    DeleteItem();
    get_devlist(devfd,dev_list);
    ui->mainList->setColumnCount(2);

    for(i=0; i<254; i++)
    {
        if(dev_list[i].addr==255)
            break;
        printf("dev_list[%d].addr=%d\n",i,dev_list[i].addr);
        printf("dev_list[%d].devicetype=%d\n",i,dev_list[i].devicetype);


        if(dev_list[i].devicetype == 4)
        {
            QString str = "TV";

            str.toStdString().c_str();

            ui->mainList->insertRow(j);
            QTableWidgetItem *item = new QTableWidgetItem( QString("Air Controller"), 0);
            ui->mainList->setItem(j, 0, item);
            QTableWidgetItem *item2 = new QTableWidgetItem( str.setNum(dev_list[i].addr), 0);
            ui->mainList->setItem(j, 1, item2);
            j++;
        }

    }
}
Beispiel #2
0
void MainWindow::MainListSet()
{
    get_devlist(devfd,dev_list);
    ui->mainList->setColumnCount(2);

    for(i=0; i<254; i++)
    {
        if(dev_list[i].addr==255)
            break;
        printf("dev_list[%d].addr=%d\n",i,dev_list[i].addr);
        printf("dev_list[%d].devicetype=%d\n",i,dev_list[i].devicetype);

        QString str = "";

        str.toStdString().c_str();


        if(dev_list[i].devicetype == 1)
        {
            ui->mainList->insertRow(i);
            QTableWidgetItem *item = new QTableWidgetItem( QString("TV"), 0);
            ui->mainList->setItem(i, 0, item);
            QTableWidgetItem *item2 = new QTableWidgetItem( str.setNum(dev_list[i].addr), 0);
            ui->mainList->setItem(i, 1, item2);
        }
        if(dev_list[i].devicetype == 2)
        {
            ui->mainList->insertRow(i);
            QTableWidgetItem *item = new QTableWidgetItem( QString("Refrigerator"), 0);
            ui->mainList->setItem(i, 0, item);
            QTableWidgetItem *item2 = new QTableWidgetItem( str.setNum(dev_list[i].addr), 0);
            ui->mainList->setItem(i, 1, item2);
        }
        if(dev_list[i].devicetype == 3)
        {
            ui->mainList->insertRow(i);
            QTableWidgetItem *item = new QTableWidgetItem( QString("Light"), 0);
            ui->mainList->setItem(i, 0, item);
            QTableWidgetItem *item2 = new QTableWidgetItem( str.setNum(dev_list[i].addr), 0);
            ui->mainList->setItem(i, 1, item2);
        }
        if(dev_list[i].devicetype == 4)
        {
            ui->mainList->insertRow(i);
            QTableWidgetItem *item = new QTableWidgetItem( QString("Air Controller"), 0);
            ui->mainList->setItem(i, 0, item);
            QTableWidgetItem *item2 = new QTableWidgetItem( str.setNum(dev_list[i].addr), 0);
            ui->mainList->setItem(i, 1, item2);
        }
    }
}
Beispiel #3
0
int
main(int argc, char **argv)
{
    capdev_t interfaces[32];
    int numdev, i;

    /* Try loading the DLL. */
#ifdef _WIN32
    pcap_handle = dynld_module("wpcap.dll", pcap_imports);
#else
    pcap_handle = dynld_module("libpcap.so", pcap_imports);
#endif
    if (pcap_handle == NULL) {
#ifdef _WIN32
	fprintf(stderr, "Unable to load WinPcap DLL !\n");
#else
	fprintf(stderr, "Unable to load libpcap.so !\n");
#endif
	return(1);
    }

    /* Get the list. */
    numdev = get_devlist(interfaces);

    if (argc == 1) {
	/* No arguments, just show the list. */
	show_devs(interfaces, numdev);

	dynld_close(pcap_handle);

	return(numdev);
    }

    /* Assume argument to be the interface number to listen on. */
    i = atoi(argv[1]);
    if (i < 0 || i > numdev) {
	fprintf(stderr, "Invalid interface number %d !\n", i);

	dynld_close(pcap_handle);

	return(1);
    }

    /* Looks good, go and listen.. */
    i = start_cap(interfaces[i-1].device);

    dynld_close(pcap_handle);

    return(i);
}
Beispiel #4
0
void MainWindow::on_mainList_cellClicked(int row, int column)
{
    //main list click  row = 0~254
    get_devlist(devfd,dev_list);
    ui->mainList->setColumnCount(2);

    for(i=0; i<254; i++)
    {
        if(dev_list[i].addr==255)
            break;
        printf("dev_list[%d].addr=%d\n",i,dev_list[i].addr);
        printf("dev_list[%d].devicetype=%d\n",i,dev_list[i].devicetype);

        QString str = "";

        str.toStdString().c_str();


        if( (dev_list[i].devicetype == 1) && (menu ==1))
        {
            if(i==row)
            {
                number = dev_list[i].addr;
            }
        }
        if((dev_list[i].devicetype == 2) && (menu ==2))
        {
            if(i==row)
            {
                number = dev_list[i].addr;
            }

        }
        if((dev_list[i].devicetype == 3) && (menu ==3))
        {
            if(i==row)
            {
                number = dev_list[i].addr;
            }
        }
        if((dev_list[i].devicetype == 4) && (menu ==4))
        {
            if(i==row)
            {
                number = dev_list[i].addr;
            }
        }
    }

}
Beispiel #5
0
int main(void)
{
	int devfd;
	int cmd;
	int ret;
	struct packet user_packet;
	struct packet recv_packet;

	int i=0;
	int dst;
	int type;
	int operation;
	int operand1,operand2;

	devfd=device_open();
	if(devfd==0)
	{
		printf("open error\n");
		return 0;
	}
	printf("devfd=%d\n",devfd);

	while(1)
	{
		printf("0. broadcast 1. send 2. recv 3. listget 4. exit: ");
		scanf("%d",&cmd);

		if(cmd==0)
		{
			packet_set(&user_packet,0,255,2,0,0,0);
			ret=packet_send(devfd,user_packet);
			printf("send ret=%d\n",ret);
/*			ret=packet_recv(devfd,&recv_packet);
			printf("recv ret=%d\n");
		
			printf("recv_packet.src=%d\n",recv_packet.src);
			printf("recv_packet.dst=%d\n",recv_packet.dst);
			printf("recv_packet.optype=%d\n",recv_packet.optype);
			printf("recv_packet.operation=%d\n",recv_packet.operation);
			printf("recv_packet.operand[0]=%d\n",recv_packet.operand[0]);
			printf("recv_packet.operand[1]=%d\n",recv_packet.operand[1]);*/
		}
		else if(cmd==1)
		{
			printf("input dev number: ");
			scanf("%d",&dst);
			printf("input type: ");
			scanf("%d",&type);
			printf("input dev operation: ");
			scanf("%d",&operation);
			printf("input operand[0]: ");
			scanf("%d",&operand1);
			printf("input operand[1]: ");
			scanf("%d",&operand2);
			
			packet_set(&user_packet,0,dst,type,operation,operand1,operand2);
			ret=packet_send(devfd,user_packet);
			printf("send ret=%d\n",ret);
		}
		else if(cmd==2)
		{
			ret=packet_recv(devfd,&recv_packet);
			printf("recv ret=%d\n");
		
			printf("recv_packet.src=%d\n",recv_packet.src);
			printf("recv_packet.dst=%d\n",recv_packet.dst);
			printf("recv_packet.optype=%d\n",recv_packet.optype);
			printf("recv_packet.operation=%d\n",recv_packet.operation);
			printf("recv_packet.operand[0]=%d\n",recv_packet.operand[0]);
			printf("recv_packet.operand[1]=%d\n",recv_packet.operand[1]);
		}
		else if(cmd==3)
		{
			get_devlist(devfd,dev_list);
			for(i=0; i<254; i++)
			{
				if(dev_list[i].addr==255)
					break;
				printf("dev_list[%d].addr=%d\n",i,dev_list[i].addr);
				printf("dev_list[%d].devicetype=%d\n",i,dev_list[i].devicetype);
			}
		}
		else if(cmd==4)
			break;
	}

	return 0;
}