예제 #1
0
TEST_F(FileTransferTest, Test1) {
  const int kFileSize = CheckBook::GetSliceSize() + 1;
  string content;
  CreateFile(kFileSize, &content);
  const string local_filename = "1112";
  FileTransfer::RegisterRequest request;
  FileTransfer::RegisterResponse response;
  request.set_src_filename(kTestFile);
  request.set_local_filename(local_filename);
  request.set_local_mac_address(GetMacAddress());
  RpcController controller;
  scoped_ptr<FileTransferServiceImpl> local_file_transfer_service(
      new FileTransferServiceImpl(FLAGS_local_root));
  scoped_ptr<FileDownloadNotifyImpl> local_file_notify(
      new FileDownloadNotifyImpl);
  client_connection_->RegisterService(local_file_transfer_service.get());
  client_connection_->RegisterService(local_file_notify.get());
  boost::shared_ptr<FileDownloadNotifier> notifier(
      new FileDownloadNotifier("Test1Notifier"));
  local_file_notify->RegisterNotifier(kTestFile, local_filename, notifier);
  CHECK(!client_connection_->IsConnected());
  CHECK(client_connection_->Connect());
  client_stub_->RegisterDownload(
      &controller,
      &request, &response, NULL);
  controller.Wait();
  ASSERT_TRUE(response.succeed());
  notifier->Wait();
  client_connection_->Disconnect();
  boost::filesystem::path dest_path(FLAGS_local_root);
  dest_path /= local_filename;
  ASSERT_TRUE(FileEqual(kTestFile, dest_path.file_string()));
  boost::filesystem::remove(kTestFile);
  boost::filesystem::remove(dest_path);
}
예제 #2
0
bool CheckValidation(DataBaseAccess *dBA, char * serverIP){
	char macAddress[SIZEOFCHARARRAY];
	int DID = 0;

	if ( GetMacAddress(macAddress) ){
		cout<<"\nMacAddress--->"<<macAddress<<endl;
		CreateUniqueDID(macAddress,DID);
		if ( !dBA->isMacAddressExist(macAddress, serverIP ) ){
			while(1){
				cout<<"\nPlease Enter DeviceIp---->";
				gets(serverIP);
				if ( !IsIPAddress(serverIP) ){
					cout<<"\nInvalid IPAddress Please try again\n";
				}
				else
					break;
			}
			if ( !dBA->InsertOwnerDeviceIp( macAddress,DID,serverIP ) ){
				cout<<"\n Unable to Insert \n"<<endl;
				return false;
			}
			else{
				cout<<"\nnot Exists inserted\n";
				return true;
			}
		}else{
			cout<<"\nServerIP--->"<<serverIP;
			return true;
		}
	}
	else
		return false;
}
예제 #3
0
void ARCGUID::Init()
{
	byte macaddress[6];
	if(GetMacAddress(macaddress)){
	}
	slocalID.Format(_T("%02x%02x%02x%02x%02x%02x"),macaddress[0],macaddress[1],macaddress[2],macaddress[3],macaddress[4],macaddress[5]);	
}
예제 #4
0
BSTR CHardInfoActiveXCtrl::getMacAddress()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	CString strResult;

	// TODO:  在此添加调度处理程序代码
	char value[512];
	int len = sizeof(value);
	memset(value, '\0', len);
	bool bRet = false;

	bRet = GetMacAddress(value, len);

	if (bRet)
	{

		strResult = value;

	}
	else
	{

		strResult = "";

	}

	return strResult.AllocSysString();
}
예제 #5
0
BOOL CPortScannerDlg::OnInitDialog()
{
	
	
	CDialog::OnInitDialog();

	list=(CListCtrl *)this->GetDlgItem(IDC_LIST1);
	port1=(CEdit *)this->GetDlgItem(IDC_EDIT1);
	port2=(CEdit *)this->GetDlgItem(IDC_EDIT2);

	devlist=(CComboBox*)GetDlgItem(IDC_COMBO1);
	devlist->SetWindowPos(&wndTop,0,0,250,120,SWP_SHOWWINDOW | SWP_NOMOVE);


	butstart=(CButton *)GetDlgItem(IDC_BUTTON1);
	butstop=(CButton *)GetDlgItem(IDC_BUTTON2);

	butstart->EnableWindow(TRUE);
	butstop->EnableWindow(FALSE);


	list->SetExtendedStyle(LVS_EX_FULLROWSELECT); 
	list->InsertColumn(0,"Port",LVCFMT_LEFT,150);
	list->InsertColumn(1,"Status",LVCFMT_LEFT,212);


	packet=new Packet();
	if(packet->GetDeviceList()==0)
	{
	MessageBox("No network adapters are present...");
	OnCancel();
	}
	
	// Get the device names and add to the combo box...
	for(int i=0;i<packet->devcount;i++)
	devlist->AddString(packet->description[i]);

	devlist->SetCurSel(0);

	// Now create the thread....
	packet->CreateThread();

	
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	

	//Get MAC address of LocalHost
	if(GetMacAddress()==FALSE)
	{
		MessageBox("Unable to get Source MAC address");
		OnCancel();
	}

	


	return TRUE;  // return TRUE  unless you set the focus to a control
}
예제 #6
0
void send_information_values_html(TDR_WebServer *w) {
	ESP8266WebServer* s=w->getServer();
	String values ="";

	values += "x_ssid|" + (String)w->getSSID() +  "|div\n";
	values += "x_ip|" +  (String) WiFi.softAPIP()[0] + "." +  (String) WiFi.softAPIP()[1] + "." +  (String) WiFi.softAPIP()[2] + "." + (String) WiFi.softAPIP()[3] +  "|div\n";
	values += "x_mac|" + GetMacAddress() +  "|div\n";
	s->send ( 200, "text/plain", values);
	Serial.println(__FUNCTION__);
}
예제 #7
0
VOID hwGetMacAddressThread(VOID *data)
{
	PMINIPORT_ADAPTER Adapter = (MINIPORT_ADAPTER *)data;
	ENTER;

	DumpDebug(TX, "Wait for SDIO ready...");
	msleep(2000);	//cky 20100525 important; wait for cmc730 can handle mac req packet
	
	GetMacAddress(Adapter);
	LEAVE;
}
예제 #8
0
STATIC
EFI_STATUS
DelPhyhandleUpdateMacAddress(IN VOID* Fdt)
{
    UINT8               port;
    INTN                ethernetnode;
    INTN			    node;
    INTN                Error;
    struct              fdt_property *m_prop;
    int                 m_oldlen;
    EFI_STATUS          Status = EFI_SUCCESS;
    
    node = fdt_subnode_offset(Fdt, 0, "soc");
    if (node < 0) 
    {
        DEBUG ((EFI_D_ERROR, "can not find soc root node\n"));
        return EFI_INVALID_PARAMETER;
    }
    else
    {
        for( port=0; port<8; port++ )
        {
            (VOID) GetMacAddress(port);
            ethernetnode=fdt_subnode_offset(Fdt, node,EthName[port]);
            if (ethernetnode < 0) 
            {
                DEBUG ((EFI_D_ERROR, "can not find ethernet@ %d node\n",port));
            }
            m_prop = fdt_get_property_w(Fdt, ethernetnode, "local-mac-address", &m_oldlen);
            if(m_prop)
            {
                Error = fdt_delprop(Fdt, ethernetnode, "local-mac-address");
                if (Error) 
                {
                    DEBUG ((EFI_D_ERROR, "ERROR:fdt_delprop() Local-mac-address: %a\n", fdt_strerror (Error)));
                    Status = EFI_INVALID_PARAMETER;
                } 
                Error = fdt_setprop(Fdt, ethernetnode, "local-mac-address",gMacAddress,sizeof(MAC_ADDRESS));
                if (Error) 
                {
                    DEBUG ((EFI_D_ERROR, "ERROR:fdt_setprop():local-mac-address %a\n", fdt_strerror (Error)));
                    Status = EFI_INVALID_PARAMETER;
                } 
            }
        }
    }
    return Status;
}
예제 #9
0
INT  Net_Init(INT dhcp)
{
	_NetTerm.tx_head = _NetTerm.tx_tail = 0;
	_NetTerm.rx_head = _NetTerm.rx_tail = 0;
	_NetTerm.state = TCP_DISCONNECT;
	_NetTerm.my_port = NET_TERM_PORT;
	_NetTerm.seqNum = 0x12345678;


#if USE_SIB
	memcpy((CHAR *)_HostMAC, (CHAR *)_bmSIB.HostMAC, 6);
	memcpy((CHAR *)_HostIP, (CHAR *)_bmSIB.HostIP, 4);
#else
	GetMacAddress(_HostMAC);	
#endif

	if (!_netbuf_ready)
	{
		if (NetBuf_Init() < 0)
			return -1;
		_netbuf_ready = 1;
	}

	if (_mac_inited == 0)
	{
		NIC_InitDriver();
		_mac_inited = 1;
	}
	else
       	Mac_EnableInt();

	NIC_EnableBroadcast();

	if (dhcp)
	{
		if (GetIpByDhcp() < 0)
		{
	
			NIC_ShutDown();
			return -1;
		}
	}

	return 0;
}
예제 #10
0
파일: File.cpp 프로젝트: nightstyles/focp
ulong CFile::GetHostId()
{
#ifdef UNIX
	return gethostid();
#else
	static uint32 nHostId;
	static bool bInit = false;
	if(bInit)
		return nHostId;
	SystemLock();
	if(!bInit)
	{
		char* out = (char*)&nHostId;
		char sMac[20];
		if(!GetMacAddress(sMac))
		{
			nHostId = 0xFFFFFFFF;
			bInit = true;
			SystemUnLock();
			return nHostId;
		}
		static uint8 sSecret[10] = {0x7E,0xA6,0xD7,0xB1,0xC3,0xF2,0xE3,0x04,0xBE,0xCA};
		char md5Output[16];
		CBinary::MemoryCopy(sMac+6, sSecret, 10);
		GetMd5((uint8*)md5Output, (uint8*)sMac, 16);
		if(CBinary::U32Code(1) != 1)
		{
			out[0] = md5Output[1] + md5Output[6] + md5Output[11];
			out[1] = md5Output[3] + md5Output[8] + md5Output[13];
			out[2] = md5Output[5] + md5Output[10] + md5Output[15];
			out[3] = md5Output[0] & 0x7F;
		}
		else
		{
			out[3] = md5Output[1] + md5Output[6] + md5Output[11];
			out[2] = md5Output[3] + md5Output[8] + md5Output[13];
			out[1] = md5Output[5] + md5Output[10] + md5Output[15];
			out[0] = md5Output[0] & 0x7F;
		}
		bInit = true;
	}
	SystemUnLock();
	return nHostId;
#endif
}
예제 #11
0
파일: unix.c 프로젝트: FancsalMelinda/core
void GetInterfacesInfo(AgentType ag)
{
    int fd, len, i, j, first_address = false, ipdefault = false;
    struct ifreq ifbuf[CF_IFREQ], ifr, *ifp;
    struct ifconf list;
    struct sockaddr_in *sin;
    struct hostent *hp;
    char *sp, workbuf[CF_BUFSIZE];
    char ip[CF_MAXVARSIZE];
    char name[CF_MAXVARSIZE];
    char last_name[CF_BUFSIZE];
    Rlist *interfaces = NULL, *hardware = NULL, *ips = NULL;

    CfDebug("GetInterfacesInfo()\n");

    // Long-running processes may call this many times
    DeleteItemList(IPADDRESSES);
    IPADDRESSES = NULL;

    memset(ifbuf, 0, sizeof(ifbuf));

    InitIgnoreInterfaces();
    
    last_name[0] = '\0';

    if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
    {
        CfOut(OUTPUT_LEVEL_ERROR, "socket", "Couldn't open socket");
        exit(1);
    }

    list.ifc_len = sizeof(ifbuf);
    list.ifc_req = ifbuf;

# ifdef SIOCGIFCONF
    if (ioctl(fd, SIOCGIFCONF, &list) == -1 || (list.ifc_len < (sizeof(struct ifreq))))
# else
    if ((ioctl(fd, OSIOCGIFCONF, &list) == -1) || (list.ifc_len < (sizeof(struct ifreq))))
# endif
    {
        CfOut(OUTPUT_LEVEL_ERROR, "ioctl", "Couldn't get interfaces - old kernel? Try setting CF_IFREQ to 1024");
        exit(1);
    }

    last_name[0] = '\0';

    for (j = 0, len = 0, ifp = list.ifc_req; len < list.ifc_len;
         len += SIZEOF_IFREQ(*ifp), j++, ifp = (struct ifreq *) ((char *) ifp + SIZEOF_IFREQ(*ifp)))
    {

        if (ifp->ifr_addr.sa_family == 0)
        {
            continue;
        }

        if ((ifp->ifr_name == NULL) || (strlen(ifp->ifr_name) == 0))
        {
            continue;
        }

        /* Skip virtual network interfaces for Linux, which seems to be a problem */

        if (IgnoreInterface(ifp->ifr_name))
        {
            continue;
        }
        
        if (strstr(ifp->ifr_name, ":"))
        {
#ifdef __linux__
            CfOut(OUTPUT_LEVEL_VERBOSE, "", "Skipping apparent virtual interface %d: %s\n", j + 1, ifp->ifr_name);
            continue;
#endif
        }
        else
        {
            CfOut(OUTPUT_LEVEL_VERBOSE, "", "Interface %d: %s\n", j + 1, ifp->ifr_name);
        }

        // Ignore the loopback

        if (strcmp(ifp->ifr_name, "lo") == 0)
        {
            continue;
        }

        if (strncmp(last_name, ifp->ifr_name, sizeof(ifp->ifr_name)) == 0)
        {
            first_address = false;
        }
        else
        {
            strncpy(last_name, ifp->ifr_name, sizeof(ifp->ifr_name));

            if (!first_address)
            {
                NewScalar("sys", "interface", last_name, DATA_TYPE_STRING);
                first_address = true;
            }
        }

        snprintf(workbuf, CF_BUFSIZE, "net_iface_%s", CanonifyName(ifp->ifr_name));

        HardClass(workbuf);

        if (ifp->ifr_addr.sa_family == AF_INET)
        {
            strncpy(ifr.ifr_name, ifp->ifr_name, sizeof(ifp->ifr_name));

            if (ioctl(fd, SIOCGIFFLAGS, &ifr) == -1)
            {
                CfOut(OUTPUT_LEVEL_ERROR, "ioctl", "No such network device");
                continue;
            }

            if ((ifr.ifr_flags & IFF_UP) && (!(ifr.ifr_flags & IFF_LOOPBACK)))
            {
                sin = (struct sockaddr_in *) &ifp->ifr_addr;

                if (IgnoreJailInterface(j + 1, sin))
                {
                    CfOut(OUTPUT_LEVEL_VERBOSE, "", "Ignoring interface %d", j + 1);
                    continue;
                }

                CfDebug("Adding hostip %s..\n", inet_ntoa(sin->sin_addr));
                HardClass(inet_ntoa(sin->sin_addr));

                if ((hp =
                     gethostbyaddr((char *) &(sin->sin_addr.s_addr), sizeof(sin->sin_addr.s_addr), AF_INET)) == NULL)
                {
                    CfDebug("No hostinformation for %s found\n", inet_ntoa(sin->sin_addr));
                }
                else
                {
                    if (hp->h_name != NULL)
                    {
                        CfDebug("Adding hostname %s..\n", hp->h_name);
                        HardClass(hp->h_name);

                        if (hp->h_aliases != NULL)
                        {
                            for (i = 0; hp->h_aliases[i] != NULL; i++)
                            {
                                CfOut(OUTPUT_LEVEL_VERBOSE, "", "Adding alias %s..\n", hp->h_aliases[i]);
                                HardClass(hp->h_aliases[i]);
                            }
                        }
                    }
                }

                if (strcmp(inet_ntoa(sin->sin_addr), "0.0.0.0") == 0)
                {
                    // Maybe we need to do something windows specific here?
                    CfOut(OUTPUT_LEVEL_VERBOSE, "", " !! Cannot discover hardware IP, using DNS value");
                    strcpy(ip, "ipv4_");
                    strcat(ip, VIPADDRESS);
                    AppendItem(&IPADDRESSES, VIPADDRESS, "");
                    RlistAppend(&ips, VIPADDRESS, RVAL_TYPE_SCALAR);

                    for (sp = ip + strlen(ip) - 1; (sp > ip); sp--)
                    {
                        if (*sp == '.')
                        {
                            *sp = '\0';
                            HardClass(ip);
                        }
                    }

                    strcpy(ip, VIPADDRESS);
                    i = 3;

                    for (sp = ip + strlen(ip) - 1; (sp > ip); sp--)
                    {
                        if (*sp == '.')
                        {
                            *sp = '\0';
                            snprintf(name, CF_MAXVARSIZE - 1, "ipv4_%d[%s]", i--, CanonifyName(VIPADDRESS));
                            NewScalar("sys", name, ip, DATA_TYPE_STRING);
                        }
                    }
                    continue;
                }

                strncpy(ip, "ipv4_", CF_MAXVARSIZE);
                strncat(ip, inet_ntoa(sin->sin_addr), CF_MAXVARSIZE - 6);
                HardClass(ip);

                if (!ipdefault)
                {
                    ipdefault = true;
                    NewScalar("sys", "ipv4", inet_ntoa(sin->sin_addr), DATA_TYPE_STRING);

                    strcpy(VIPADDRESS, inet_ntoa(sin->sin_addr));
                }

                AppendItem(&IPADDRESSES, inet_ntoa(sin->sin_addr), "");
                RlistAppend(&ips, inet_ntoa(sin->sin_addr), RVAL_TYPE_SCALAR);

                for (sp = ip + strlen(ip) - 1; (sp > ip); sp--)
                {
                    if (*sp == '.')
                    {
                        *sp = '\0';
                        HardClass(ip);
                    }
                }

                // Set the IPv4 on interface array

                strcpy(ip, inet_ntoa(sin->sin_addr));

                if ((ag != AGENT_TYPE_KNOW) && (ag != AGENT_TYPE_GENDOC))
                {
                    snprintf(name, CF_MAXVARSIZE - 1, "ipv4[%s]", CanonifyName(ifp->ifr_name));
                }
                else
                {
                    snprintf(name, CF_MAXVARSIZE - 1, "ipv4[interface_name]");
                }

                NewScalar("sys", name, ip, DATA_TYPE_STRING);

                i = 3;

                for (sp = ip + strlen(ip) - 1; (sp > ip); sp--)
                {
                    if (*sp == '.')
                    {
                        *sp = '\0';

                        if ((ag != AGENT_TYPE_KNOW) && (ag != AGENT_TYPE_GENDOC))
                        {
                            snprintf(name, CF_MAXVARSIZE - 1, "ipv4_%d[%s]", i--, CanonifyName(ifp->ifr_name));
                        }
                        else
                        {
                            snprintf(name, CF_MAXVARSIZE - 1, "ipv4_%d[interface_name]", i--);
                        }

                        NewScalar("sys", name, ip, DATA_TYPE_STRING);
                    }
                }
            }

            // Set the hardware/mac address array
            GetMacAddress(ag, fd, &ifr, ifp, &interfaces, &hardware);
        }
    }

    close(fd);

    NewList("sys", "interfaces", interfaces, DATA_TYPE_STRING_LIST);
    NewList("sys", "hardware_addresses", hardware, DATA_TYPE_STRING_LIST);
    NewList("sys", "ip_addresses", ips, DATA_TYPE_STRING_LIST);

    RlistDestroy(interfaces);
    RlistDestroy(hardware);
    RlistDestroy(ips);

    FindV6InterfacesInfo();
}
예제 #12
0
void CNetworkLinux::queryInterfaceList()
{
  char macAddrRaw[6];
  m_interfaces.clear();

#if defined(TARGET_DARWIN) || defined(TARGET_FREEBSD)

   // Query the list of interfaces.
   struct ifaddrs *list;
   if (getifaddrs(&list) < 0)
     return;

   struct ifaddrs *cur;
   for(cur = list; cur != NULL; cur = cur->ifa_next)
   {
     if(cur->ifa_addr->sa_family != AF_INET)
       continue;

     GetMacAddress(cur->ifa_name, macAddrRaw);
     // Add the interface.
     m_interfaces.push_back(new CNetworkInterfaceLinux(this, cur->ifa_name, macAddrRaw));
   }

   freeifaddrs(list);

#else
   FILE* fp = fopen("/proc/net/dev", "r");
   if (!fp)
   {
     // TBD: Error
     return;
   }

   char* line = NULL;
   size_t linel = 0;
   int n;
   char* p;
   int linenum = 0;
   while (getdelim(&line, &linel, '\n', fp) > 0)
   {
      // skip first two lines
      if (linenum++ < 2)
         continue;

    // search where the word begins
      p = line;
      while (isspace(*p))
      ++p;

      // read word until :
      n = strcspn(p, ": \t");
      p[n] = 0;

      // save the result
      std::string interfaceName = p;
      GetMacAddress(interfaceName, macAddrRaw);
      m_interfaces.push_back(new CNetworkInterfaceLinux(this, interfaceName, macAddrRaw));
   }
   free(line);
   fclose(fp);
#endif
}
예제 #13
0
BOOL DHCP_MONITOR(int timeout, char *re_addr, char *custpath, char *szReturn)
{
	int		i;
	SOCKET	s;
	struct	sockaddr_in lsa, rsa;
	DWORD	dwbTime, dweTime;

	int		reqlen = 0;
	u_char	reqmessage[1000] = {0};
	u_char	resmessage[1000] = {0};

	dwbTime = ::GetTickCount();

	DHCPMessage reqdm, resdm;

	srand((unsigned)time(NULL));

	memset(&reqdm, 0, sizeof(struct DHCP_MESSAGE));
	reqdm.op = 0x01;
	reqdm.htype = 0x01;
	reqdm.hlen = 0x06;

	// Physical Address
	GetMacAddress(reqdm.ch_addr);

	for(i = 0;i < 4;i ++)
		reqdm.xid[i] = rand() % 0xff;

	reqdm.opts.oplen = 0;

	// magic cookie
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x63;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x82;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x53;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x63;

	// DHCP Message Type
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x35;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x01;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x01;

	reqdm.opts.opstr[reqdm.opts.oplen++] = 0xFB;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x01;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x01;

	// Client-identifier
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x3D;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x07;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x01;
	GetMacAddress(reqdm.opts.opstr + reqdm.opts.oplen);
	reqdm.opts.oplen += 6;

	// Requested IP Address
	if(*re_addr)
	{
		int		f_1 = 0, f_2 = 0, f_3 = 0, f_4 = 0;

		if(sscanf(re_addr, "%d.%d.%d.%d", &f_1, &f_2, &f_3, &f_4) != 4)
		{
			sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_DHCP_1%>"));//<%IDS_DHCP_1%>
			return FALSE;
		}

		reqdm.opts.opstr[reqdm.opts.oplen++] = 0x32;
		reqdm.opts.opstr[reqdm.opts.oplen++] = 0x04;
		reqdm.opts.opstr[reqdm.opts.oplen++] = f_1;
		reqdm.opts.opstr[reqdm.opts.oplen++] = f_2;
		reqdm.opts.opstr[reqdm.opts.oplen++] = f_3;
		reqdm.opts.opstr[reqdm.opts.oplen++] = f_4;
	}

	// Host Name Option
	TCHAR lhost[80];
	gethostname(lhost, sizeof(lhost));
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x0C;
	reqdm.opts.opstr[reqdm.opts.oplen++] = strlen(lhost);
	for(i = 0;i < (int)strlen(lhost);i ++)
		reqdm.opts.opstr[reqdm.opts.oplen++] = lhost[i];

	// Class-identifier
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x3C;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x08;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x44;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x46;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x2E;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x46;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x72;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x61;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x6E;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x6B;

	// Parameter Request List
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x37;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x0A;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x01;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x0F;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x03;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x06;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x2C;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x2E;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x2F;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x1F;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x21;
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0x2B;

	// end
	reqdm.opts.opstr[reqdm.opts.oplen++] = 0xFF;

	// padding
	if(reqdm.opts.oplen < 64)
	{
		int left = 64 - reqdm.opts.oplen;
		for(i = 0;i < left;i ++)
			reqdm.opts.opstr[reqdm.opts.oplen++] = 0x00;
	}

	reqlen = topacket(&reqdm, reqmessage);

	if((s = socket(PF_INET, SOCK_DGRAM, 0)) == INVALID_SOCKET)
	{
		sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_DHCP_2%>"));//<%IDS_DHCP_2%>
		return FALSE;
	}

	// set socket broadcast flag
	{
	const int on = 1;
	setsockopt(s, SOL_SOCKET, SO_BROADCAST, (const char *)&on, sizeof(on));
	}

	memset(&lsa, 0, sizeof(lsa));
	lsa.sin_family = AF_INET;
	lsa.sin_addr.s_addr = htonl(inet_addr(DHCP_LOCAL_ADDRESS));
	lsa.sin_port=htons(DHCP_CLIENT_PORT);
	if(bind(s, (struct sockaddr *)&lsa, sizeof(lsa)) == SOCKET_ERROR)
	{
		sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_DHCP_3%>"));//<%IDS_DHCP_3%>
		return FALSE;
	}

    rsa.sin_family = AF_INET;
	rsa.sin_addr.s_addr = htonl(inet_addr(DHCP_MULTICAST_ADDRESS));
    rsa.sin_port = htons(DHCP_SERVER_PORT);

	int dw, n;
	if((n = sendto(s, (char *)reqmessage, reqlen, 0, (struct sockaddr *)&rsa, sizeof(rsa))) == SOCKET_ERROR)
	{
		sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_DHCP_4%>"));//<%IDS_DHCP_4%>
		return FALSE;
	}
	
	if(RESPONSE_WAIT(s, timeout) > 0)
	{
		dw = sizeof(rsa);
		if((n = recvfrom(s, (char *)resmessage, 1000, 0, (struct sockaddr *)&rsa, &dw)) == SOCKET_ERROR)
		{
			sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_DHCP_5%>"));//<%IDS_DHCP_5%>
			return FALSE;
		}

		if(n == 0)
		{
			sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_DHCP_6%>"));//<%IDS_DHCP_6%>
			return FALSE;
		}

		if(tostruct(&resdm, resmessage, n))
		{
			sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_DHCP_7%>"));//<%IDS_DHCP_7%>
			return FALSE;
		}

		if(resdm.op != 2 || resdm.htype != 1 || resdm.hlen != 6)
		{
			sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_DHCP_8%>"));//<%IDS_DHCP_8%>
			return FALSE;
		}

		if(!resdm.siaddr)
		{
			sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_DHCP_9%>"));//<%IDS_DHCP_9%>
			return FALSE;
		}

		dweTime = ::GetTickCount();
		sprintf(szReturn, "roundTripTime=%ld", dweTime - dwbTime);
		return TRUE;

	}

	sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_DHCP_10%>"));//<%IDS_DHCP_10%>
	return FALSE;
}
예제 #14
0
std::string Crypto_t::genHardwareIdentKey()
{
	return GetMacAddress();
}
예제 #15
0
IPCCommandResult NetNCDManage::IOCtlV(const IOCtlVRequest& request)
{
  s32 return_value = IPC_SUCCESS;
  u32 common_result = 0;
  u32 common_vector = 0;

  switch (request.request)
  {
  case IOCTLV_NCD_LOCKWIRELESSDRIVER:
    break;

  case IOCTLV_NCD_UNLOCKWIRELESSDRIVER:
    // Memory::Read_U32(request.in_vectors.at(0).address);
    break;

  case IOCTLV_NCD_GETCONFIG:
    INFO_LOG(IOS_NET, "NET_NCD_MANAGE: IOCTLV_NCD_GETCONFIG");
    config.WriteToMem(request.io_vectors.at(0).address);
    common_vector = 1;
    break;

  case IOCTLV_NCD_SETCONFIG:
    INFO_LOG(IOS_NET, "NET_NCD_MANAGE: IOCTLV_NCD_SETCONFIG");
    config.ReadFromMem(request.in_vectors.at(0).address);
    break;

  case IOCTLV_NCD_READCONFIG:
    INFO_LOG(IOS_NET, "NET_NCD_MANAGE: IOCTLV_NCD_READCONFIG");
    config.ReadConfig();
    config.WriteToMem(request.io_vectors.at(0).address);
    common_vector = 1;
    break;

  case IOCTLV_NCD_WRITECONFIG:
    INFO_LOG(IOS_NET, "NET_NCD_MANAGE: IOCTLV_NCD_WRITECONFIG");
    config.ReadFromMem(request.in_vectors.at(0).address);
    config.WriteConfig();
    break;

  case IOCTLV_NCD_GETLINKSTATUS:
    INFO_LOG(IOS_NET, "NET_NCD_MANAGE: IOCTLV_NCD_GETLINKSTATUS");
    // Always connected
    Memory::Write_U32(Net::ConnectionSettings::LINK_WIRED, request.io_vectors.at(0).address + 4);
    break;

  case IOCTLV_NCD_GETWIRELESSMACADDRESS:
    INFO_LOG(IOS_NET, "NET_NCD_MANAGE: IOCTLV_NCD_GETWIRELESSMACADDRESS");

    u8 address[Common::MAC_ADDRESS_SIZE];
    GetMacAddress(address);
    Memory::CopyToEmu(request.io_vectors.at(1).address, address, sizeof(address));
    break;

  default:
    INFO_LOG(IOS_NET, "NET_NCD_MANAGE IOCtlV: %#x", request.request);
    break;
  }

  Memory::Write_U32(common_result, request.io_vectors.at(common_vector).address);
  if (common_vector == 1)
  {
    Memory::Write_U32(common_result, request.io_vectors.at(common_vector).address + 4);
  }
  return GetDefaultReply(return_value);
}
예제 #16
0
// This is just for debugging / playing around.
// There really is no reason to implement wd unless we can bend it such that
// we can talk to the DS.
IPCCommandResult NetWDCommand::IOCtlV(const IOCtlVRequest& request)
{
  s32 return_value = IPC_SUCCESS;

  switch (request.request)
  {
  case IOCTLV_WD_SCAN:
  {
    // Gives parameters detailing type of scan and what to match
    // XXX - unused
    // ScanInfo *scan = (ScanInfo *)Memory::GetPointer(request.in_vectors.at(0).m_Address);

    u16* results = (u16*)Memory::GetPointer(request.io_vectors.at(0).address);
    // first u16 indicates number of BSSInfo following
    results[0] = Common::swap16(1);

    BSSInfo* bss = (BSSInfo*)&results[1];
    memset(bss, 0, sizeof(BSSInfo));

    bss->length = Common::swap16(sizeof(BSSInfo));
    bss->rssi = Common::swap16(0xffff);

    for (int i = 0; i < BSSID_SIZE; ++i)
      bss->bssid[i] = i;

    const char* ssid = "dolphin-emu";
    strcpy((char*)bss->ssid, ssid);
    bss->ssid_length = Common::swap16((u16)strlen(ssid));

    bss->channel = Common::swap16(2);
  }
  break;

  case IOCTLV_WD_GET_INFO:
  {
    Info* info = (Info*)Memory::GetPointer(request.io_vectors.at(0).address);
    memset(info, 0, sizeof(Info));
    // Probably used to disallow certain channels?
    memcpy(info->country, "US", 2);
    info->ntr_allowed_channels = Common::swap16(0xfffe);

    u8 address[Common::MAC_ADDRESS_SIZE];
    GetMacAddress(address);
    memcpy(info->mac, address, sizeof(info->mac));
  }
  break;

  case IOCTLV_WD_GET_MODE:
  case IOCTLV_WD_SET_LINKSTATE:
  case IOCTLV_WD_GET_LINKSTATE:
  case IOCTLV_WD_SET_CONFIG:
  case IOCTLV_WD_GET_CONFIG:
  case IOCTLV_WD_CHANGE_BEACON:
  case IOCTLV_WD_DISASSOC:
  case IOCTLV_WD_MP_SEND_FRAME:
  case IOCTLV_WD_SEND_FRAME:
  case IOCTLV_WD_CALL_WL:
  case IOCTLV_WD_MEASURE_CHANNEL:
  case IOCTLV_WD_GET_LASTERROR:
  case IOCTLV_WD_CHANGE_GAMEINFO:
  case IOCTLV_WD_CHANGE_VTSF:
  case IOCTLV_WD_RECV_FRAME:
  case IOCTLV_WD_RECV_NOTIFICATION:
  default:
    request.Dump(GetDeviceName(), LogTypes::IOS_NET, LogTypes::LINFO);
  }

  return GetDefaultReply(return_value);
}
예제 #17
0
TEST_F(FileTransferTest, Test2) {
  const int kConnectionNumber = FLAGS_num_connections;
  const int kSliceNumber = 10;
  const int kFileSize = CheckBook::GetSliceSize()  * kSliceNumber + 1;
  string content;
  CreateFile(kFileSize, &content);
  const string local_filename = "111";
  FileTransfer::RegisterRequest request;
  FileTransfer::RegisterResponse response;
  request.set_src_filename(kTestFile);
  request.set_local_filename(local_filename);
  request.set_local_mac_address(GetMacAddress());
  RpcController controller;
  boost::shared_ptr<FileTransferServiceImpl> local_file_transfer_service(
      new FileTransferServiceImpl(FLAGS_local_root));
  boost::shared_ptr<FileDownloadNotifyImpl> local_file_notify(
      new FileDownloadNotifyImpl);
  client_connection_->RegisterService(local_file_transfer_service.get());
  client_connection_->RegisterService(local_file_notify.get());
  boost::shared_ptr<FileDownloadNotifier> notifier(
      new FileDownloadNotifier("FinishedNotify"));
  local_file_notify->RegisterNotifier(
      kTestFile, local_filename, notifier);
  vector<boost::shared_ptr<ClientConnection> > connections;
  for (int i = 0; i < kConnectionNumber; ++i) {
    controller.Reset();
    const string name("FileDownloadTest2Client." + boost::lexical_cast<string>(i));
    boost::shared_ptr<ClientConnection> r(new ClientConnection(name, FLAGS_server, FLAGS_port));
    CHECK(!r->IsConnected());
    CHECK(r->Connect());
    r->RegisterService(local_file_transfer_service.get());
    r->RegisterService(local_file_notify.get());
    connections.push_back(r);
    FileTransfer::FileDownloadService::Stub stub(r.get());
    request.set_peer_name(r->name());
    VLOG(2) << "Call RegisterDownload to register: " << i;
    stub.RegisterDownload(
        NULL,
        &request, &response, NULL);
    VLOG(2) << "Register " << i;
  }
  for (int i = 0; i < connections.size(); ++i) {
    if (i % 2 == 1) {
      VLOG(2) << "Disconnect: " << i << connections[i]->name();
      connections[i]->Disconnect();
      connections.erase(connections.begin() + i);
    }
  }
  ASSERT_LT(connections.size(), kConnectionNumber);
  ASSERT_GT(connections.size(), 0);
  VLOG(2) << "connections size: " << connections.size();
  notifier->Wait();
  for (int i = 0; i < connections.size(); ++i) {
    VLOG(2) << "Disconnect: " << i << connections[i]->name();
    connections[i]->Disconnect();
  }
  boost::filesystem::path dest_path(FLAGS_local_root);
  dest_path /= local_filename;
  ASSERT_TRUE(FileEqual(kTestFile, dest_path.file_string()));
//  boost::filesystem::remove(kTestFile);
//  boost::filesystem::remove(dest_path);
}
예제 #18
0
/**
 * Encrypts a buffer using the crypto API
 *
 * @param SrcBuffer the source data being encrypted
 * @param SrcLen the size of the buffer in bytes
 * @param DestBuffer (out) chunk of memory that is written to
 * @param DestLen (in) the size of the dest buffer, (out) the size of the encrypted data
 *
 * @return true if the encryption worked, false otherwise
 */
static bool EncryptBuffer(const uint8* SrcBuffer,const uint32 SrcLen,uint8* DestBuffer,uint32& DestLen)
{
	bool bEncryptedOk = false;

#if PLATFORM_MAC
	unsigned long long MacAddress = 0;
	uint32 AddressSize = sizeof(unsigned long long);
	GetMacAddress((uint8*)&MacAddress,AddressSize);
	unsigned long long Entropy = 5148284414757334885ull;
	Entropy ^= MacAddress;

	uint8 Key[kCCKeySizeAES128];
	check(kCCKeySizeAES128 == 2*sizeof(unsigned long long));
	FMemory::Memcpy(Key,&Entropy,sizeof(Entropy));
	FMemory::Memcpy(Key+sizeof(Entropy),&Entropy,sizeof(Entropy));

	size_t OutBufferSize = SrcLen + kCCBlockSizeAES128;
	uint8* OutBuffer = (uint8*)FMemory::Malloc(OutBufferSize);
	FMemory::Memset(OutBuffer,0,OutBufferSize);

	size_t BytesEncrypted = 0;
	CCCryptorStatus Status = CCCrypt( kCCEncrypt, kCCAlgorithmAES128,
		kCCOptionPKCS7Padding, Key, kCCKeySizeAES128, NULL, SrcBuffer,
		SrcLen, OutBuffer, OutBufferSize, &BytesEncrypted);
	if (Status == kCCSuccess)
	{
		DestLen = BytesEncrypted;
		FMemory::Memcpy(DestBuffer,OutBuffer,DestLen);
		bEncryptedOk = true;
	}
	else
	{
		UE_LOG(LogTaskBrowser, Log, TEXT("CCCrypt failed w/ 0x%08x"), Status);
	}
	FMemory::Free(OutBuffer);
#elif PLATFORM_LINUX
	printf("STaskBrowser.cpp: LINUX EncryptBuffer()\n");
#elif PLATFORM_WINDOWS
	DATA_BLOB SourceBlob, EntropyBlob, FinalBlob;
	// Set up the datablob to encrypt
	SourceBlob.cbData = SrcLen;
	SourceBlob.pbData = (uint8*)SrcBuffer;
	// Get the mac address for mixing into the entropy (ties the encryption to a location)
	ULONGLONG MacAddress = 0;
	uint32 AddressSize = sizeof(ULONGLONG);
	GetMacAddress((uint8*)&MacAddress,AddressSize);
	// Set up the entropy blob (changing this breaks all previous encrypted buffers!)
	ULONGLONG Entropy = 5148284414757334885ui64;
	Entropy ^= MacAddress;
	EntropyBlob.cbData = sizeof(ULONGLONG);
	EntropyBlob.pbData = (uint8*)&Entropy;
	// Zero the output data
	FMemory::Memzero(&FinalBlob,sizeof(DATA_BLOB));
	// Now encrypt the data
	if (CryptProtectData(&SourceBlob,
		NULL,
		&EntropyBlob,
		NULL,
		NULL,
		CRYPTPROTECT_UI_FORBIDDEN,
		&FinalBlob))
	{
		if (FinalBlob.cbData <= DestLen)
		{
			// Copy the final results
			DestLen = FinalBlob.cbData;
			FMemory::Memcpy(DestBuffer,FinalBlob.pbData,DestLen);
			bEncryptedOk = true;
		}
		// Free the encryption buffer
		LocalFree(FinalBlob.pbData);
	}
	else
	{
		uint32 Error = GetLastError();
		UE_LOG(LogTaskBrowser, Log, TEXT("CryptProtectData failed w/ 0x%08x"), Error);
	}
#else
	unimplemented();
#endif
	return bEncryptedOk;
}