Convert ip address from string to hex

/***********************************************************************************
Convert ip address from string to hex. 
Assumed the string is valid.

  u_pIpAdrsChar				----- IP address stored in string.
  v_pIpAdrsInt				----- Output parameter.
************************************************************************************/
STATUS ipAdrsConverToHex(char* u_pIpAdrsChar, UINT32 *v_pIpAdrsInt)	
{
	char *pDot[4]; 
	unsigned int temp; 
	int i;

	pDot[0] = u_pIpAdrsChar;
	pDot[1] = strchr(pDot[0],'.') + 1;
	pDot[2] = strchr(pDot[1],'.') + 1;
	pDot[3] = strchr(pDot[2],'.') + 1;

	*v_pIpAdrsInt = 0;
	for(i=0;i<4;i++)
	{ 	    
		temp = atoi(pDot[i]);
		*v_pIpAdrsInt |= (temp & 0xff)<<(8*(3 - i));
	}     

	return OK;
}  /* end of ipAdrsConverToHex() */

posted @ 2011-05-27 15:16  无忧一生  阅读(888)  评论(0编辑  收藏  举报