Monthly Archives: June 2015

C++ Get current hour, minutes of the day

#include <time.h>
time_t theTime = time(NULL);
struct tm *aTime = localtime(&theTime);

int day = aTime->tm_mday;
int month = aTime->tm_mon + 1; // Month is 0 – 11, add 1 to get a jan-dec 1-12 concept
int year = aTime->tm_year + 1900; // Year is # years since 1900
int hour=aTime->tm_hour;
int min=aTime->tm_min;

c++ code std::map iterator map


map<DWORD,MACADDR> arpmap=CAddressHelper::GetARPCache();

   	map<DWORD,MACADDR>::iterator it;

    	for (it = arpmap.begin(); it != arpmap.end(); ++it) {
    		MACADDR &sMac = (*it).second;
    		const DWORD &nIP=(*it).first;
 
    		}



c++ 11
for (auto x: arpmap) {
  cout << x.first << endl;
}

C++ Code Convert Hex string back to Char buffer

int _helpper_Hex2Char(unsigned char & p_cChar,unsigned char p_Value,int & p_nOdd)
{
p_cChar&=0xf0;
p_Value&=0x0f;
p_cChar|=p_Value;
if(p_nOdd++%2) p_cChar<<=4; //first part return p_nOdd%2?1:0; //if it is odd, then index need to +1 , other wise, index +0; } string _helper_Hex2Buffer(string p_sHexStr) { string sReturn = ""; unsigned char *buf=new unsigned char[p_sHexStr.length()]; memset(buf,0,p_sHexStr.length()); int nIndex=0; int nOdd=1; for (int i = 0; i < p_sHexStr.length (); ++i) { switch (p_sHexStr [i]) { case '0': { nIndex+=_helpper_Hex2Char(buf[nIndex],0x00,nOdd); break; } case '1': { nIndex+=_helpper_Hex2Char(buf[nIndex],0x01,nOdd); break; } case '2': nIndex+=_helpper_Hex2Char(buf[nIndex],0x02,nOdd); break; case '3': nIndex+=_helpper_Hex2Char(buf[nIndex],0x03,nOdd); break; case '4': nIndex+=_helpper_Hex2Char(buf[nIndex],0x04,nOdd); break; case '5': nIndex+=_helpper_Hex2Char(buf[nIndex],0x05,nOdd); break; case '6': nIndex+=_helpper_Hex2Char(buf[nIndex],0x06,nOdd); break; case '7': nIndex+=_helpper_Hex2Char(buf[nIndex],0x07,nOdd); break; case '8': nIndex+=_helpper_Hex2Char(buf[nIndex],0x08,nOdd); break; case '9': nIndex+=_helpper_Hex2Char(buf[nIndex],0x09,nOdd); break; case 'a': nIndex+=_helpper_Hex2Char(buf[nIndex],0x0a,nOdd); break; case 'b': nIndex+=_helpper_Hex2Char(buf[nIndex],0x0b,nOdd); break; case 'c': nIndex+=_helpper_Hex2Char(buf[nIndex],0x0c,nOdd); break; case 'd': nIndex+=_helpper_Hex2Char(buf[nIndex],0x0d,nOdd); break; case 'e': nIndex+=_helpper_Hex2Char(buf[nIndex],0x0e,nOdd); break; case 'f': nIndex+=_helpper_Hex2Char(buf[nIndex],0x0f,nOdd); break; default: continue; } } sReturn.append((char *)buf,nIndex); delete buf; return sReturn; }