Skip to main content

Windows Mobile / WinCE Custom Ping function

I am back and yet again Windows Mobile / WinCE tutorial but this time soemthing interesting and on networking side. Lately i was developing Wireless PDA Update application which requires me to check if server which contains ROM image files is reachble before attempting to download files from the same. I thought that there is a WinCE API available to perform this task but to my surprise there is NO direct API however helper API is available. Then i have constructed an API which takes parameters and returns true if ping successful.

Here is the function .... If you require full application do let me know so that i can upload to any free server.

int Ping(PWCHAR wszHostname, int iWaitTime) {

WCHAR wszAdd[MAX_PATH] = L"\0";
in_addr addr;
HANDLE hFile;
IP_OPTION_INFORMATION ipInfo ;
IPAddr ipAddress ;
ICMP_ECHO_REPLY icmpEcho;
int iRet = -1;
char* pMBHost = (char*) malloc(MAX_PATH);
char* pMBAddr;

wcstombs(pMBHost, wszHostname, MAX_PATH ); // Convert Unicode to Multibyte

hostent* phe = gethostbyname(pMBHost);

if(phe) {
ipAddress = *(DWORD*)(phe->h_addr_list[0]);
}

if(ipAddress != INADDR_NONE) {
memcpy(&addr, phe->h_addr_list[0], sizeof(in_addr) );
pMBAddr = inet_ntoa(addr);
mbstowcs(wszAdd, pMBAddr, sizeof(CHAR)*strlen(pMBAddr));
// AfxMessageBox(wszAdd);

iRet = 0;

hFile = IcmpCreateFile();
// Set some reasonable default values
ipInfo.Ttl = 128 ;
ipInfo.Tos = 0;
ipInfo.Flags = 0;
ipInfo.OptionsSize = 0 ;
ipInfo.OptionsData = NULL ;

icmpEcho.Status = IP_SUCCESS;

IcmpSendEcho(hFile, ipAddress, NULL, 0,
(PIP_OPTION_INFORMATION)&ipInfo,
&icmpEcho, sizeof(ICMP_ECHO_REPLY),iWaitTime);

IcmpCloseHandle(hFile) ;
if ( icmpEcho.Status == IP_SUCCESS ) {
iRet = 1 ;
}
}

free(pMBHost);

return iRet;
}

Comments

Popular posts from this blog

Android ANR Time, UI Thread

Useful Android Performance / Stability debugging info  1. ANR Waiting times: Performing heavy I/O , Network access or orher heavy operations on UI thread ?? A BIG NO NO ..you are inviting ANR.   No response to an input event (such as key press or screen touch events) within 5 seconds. A  BroadcastReceiver  hasn't finished executing within 10 seconds.

Andoird Key codes , adb keyevent

Useful Android Keyevents inputs: Some time it is extremely useful to send keyevent via adb for automation and other purposes. #adb shell  #input usage: input [text|keyevent] input text input keyevent adb shell input text "HELLO" LIST OF KEY CODES:  1 --> "KEYCODE_MENU" 3 --> "KEYCODE_HOME" 4 --> "KEYCODE_BACK" 19 --> "KEYCODE_DPAD_UP" 20 --> "KEYCODE_DPAD_DOWN" 21 --> "KEYCODE_DPAD_LEFT" 22 --> "KEYCODE_DPAD_RIGHT" 23 --> "KEYCODE_DPAD_CENTER" 24 --> "KEYCODE_VOLUME_UP" 25 --> "KEYCODE_VOLUME_DOWN" 26 --> "KEYCODE_POWER" 27 --> "KEYCODE_CAMERA" 28 --> "KEYCODE_CLEAR" 55 --> "KEYCODE_COMMA" 56 --> "KEYCODE_PERIOD" 57 --> "KEYCODE_ALT_LEFT" 58 --> "KEYCODE_ALT_RIGHT" 59 --> "KEYCODE_SHIFT_LEFT" 60...

What is the Current Directory in Windows CE & Windows Mobile ?

Lately i encountered  a situation where i had to find the current directory from where my application is running and all my config files reside. Question is "How do I find the current directory?" on Windows CE/Mobile devices. Desktop / PC it is just piece of cake but Windows CE / Mobile devices don't have a concept of a current directory.  Which means all pats are absolute and there is no concept called relative path. Due to lack of relative paths most of the files are loaded to the "Windows" directory and that is how Windows directory is crowded. Alternatively you can hard code directory path and insist user to load files always there. But i hate to hard code values or copy files to Windows directory.  So this has triggered to find a solution to identify my current directory. Since there is no concept of a current directory on a Windows CE / Windows Mobile device how would one locate a resource for which only a relative path is known?  That is what following c...