コード例 #1
0
CEXIETHERNET::CEXIETHERNET()
{
	tx_fifo = new u8[1518];
	mBbaMem = new u8[BBA_MEM_SIZE];

	mRecvBuffer = new u8[BBA_RECV_SIZE];
	mRecvBufferLength = 0;

	MXHardReset();

	// Parse MAC address from config, and generate a new one if it doesn't
	// exist or can't be parsed.
	std::string &mac_addr_setting = SConfig::GetInstance().m_bba_mac;
	u8 mac_addr[MAC_ADDRESS_SIZE] = { 0 };

	if (!StringToMacAddress(mac_addr_setting, mac_addr))
	{
		GenerateMacAddress(BBA, mac_addr);
		mac_addr_setting = MacAddressToString(mac_addr);
		SConfig::GetInstance().SaveSettings();
	}

	memcpy(&mBbaMem[BBA_NAFR_PAR0], mac_addr, MAC_ADDRESS_SIZE);

	// HACK: .. fully established 100BASE-T link
	mBbaMem[BBA_NWAYS] = NWAYS_LS100 | NWAYS_LPNWAY | NWAYS_100TXF | NWAYS_ANCLPT;

#if defined(_WIN32)
	mHAdapter = INVALID_HANDLE_VALUE;
	mHRecvEvent = INVALID_HANDLE_VALUE;
	mHReadWait = INVALID_HANDLE_VALUE;
#elif defined(__linux__) || defined(__APPLE__)
	fd = -1;
#endif
}
コード例 #2
0
ファイル: MAC_Finder.cpp プロジェクト: craiglotter/MAC-Finder
int main(int argc, char *argv[]) // command line args
{
    //declare variables necessary for adaptersinfo call
	HMODULE hLib;
	GetAdaptersInfoFunc GetAdaptersInfo = NULL;

	PIP_ADAPTER_INFO pai = NULL;
	DWORD dwSize = 0;
	DWORD dwRet;
	CHAR szMac[64];
	
	//declare variables necessary for the later string manipulation
	CHAR resultstring[64] = "";
    CHAR macfolder[] = "00000000.000";
    char sourcefolder[100];
    char destinationfolder[100];
    char filename[100];
	char* token;
	char seps[]   = "-";

	//control variables
	int firstflagsuccess = 0;

    cout << "\n" << endl;

	//checks that correct number of parameters are present
    if (argc != 4)
	{
		error("Incorrect number of parameters.\nUsage: MAC_Finder <source folder> <destination folder> <file to copy>\nNote: Folders must not have a '\\' character following them. (e.g. C:\\Windows)","");
	}

	//sets the inputted parameters to variables.
	strcpy(sourcefolder,argv[1]);
	strcpy(destinationfolder,argv[2]);
	strcpy(filename,argv[3]);

	//loads the IP helper api library
	hLib = LoadLibrary("Iphlpapi.dll");
	if (!hLib)
	{
		error("Failed to load Iphlpapi.dll","");
		//system ("pause");		
	}

	//Checks that the function exists within the library
	GetAdaptersInfo = (GetAdaptersInfoFunc)GetProcAddress(hLib, "GetAdaptersInfo");
	if (GetAdaptersInfo == NULL)
	{
		error("Failed to load GetAdaptersInfo in Iphlpapi.dll","");
	}

	// Get size of buffer needed:
	GetAdaptersInfo(NULL, &dwSize);

	pai = (PIP_ADAPTER_INFO)GlobalAlloc(GPTR, dwSize);

	//calls the adaptersinfo function
	dwRet = GetAdaptersInfo(pai, &dwSize);

	//checks that no error occurred
	if(dwRet != ERROR_BUFFER_OVERFLOW)
	{
	    if (GetLastError() != 0)
   	    {
   	            printf("GetAdapterInfo error:%d\n", GetLastError());
                exit(1);
        }
    }

    //retrieves the PC's MAC address
	PIP_ADAPTER_INFO p = pai;
	while (p)
	{
		MacAddressToString(p->Address, szMac, p->AddressLength);
		printf("Description: %s\nMAC Address: %s\n", p->Description, szMac);
		printf("\n");
		p = p->Next;
	}

	//Splits up the MAC address so that the string can be manipulated
	//e.g. 002244001145 -> 02244001.145
	token = strtok( szMac, seps );
	if (token != NULL)
	{
	    strncpy(resultstring, token + 1, 1 );
        firstflagsuccess = 0;
    }
    while( token != NULL )
    {
      if (firstflagsuccess == 1)
      	strcat(resultstring, token);      
  	  else
  	    firstflagsuccess = 1;
      token = strtok( NULL, seps );
    }

    strncpy(macfolder,resultstring,8);
    strncpy(macfolder+8,".",1);
    strncpy(macfolder + 9,resultstring + 8,3);

    //create the sourcefile and destinationfile strings
    strcat(sourcefolder,"\\");
    strcat(sourcefolder,macfolder);
    strcat(sourcefolder,"\\");
    strcat(sourcefolder,filename);
    strcat(destinationfolder,"\\");
    strcat(destinationfolder,filename);
    cout << "Copying \"" << sourcefolder << "\" to \"" << destinationfolder << "\""<< endl;

    //copy file
    ifstream from(sourcefolder) ; 
    if (!from) error("Cannot open input file",argv[1]) ;
    ofstream to(destinationfolder) ; 
    if (!to) error("Cannot open output file",argv[2]) ;
    char ch;
    while (from.get(ch)) to.put(ch) ;
    if (!from.eof() || !to) error("Error in copy process") ;

    cout << "Success\nExiting..." << endl;

    //free resources
	GlobalFree(pai);
	FreeLibrary(hLib);

	//exit program
	return 0; 
}