代码:
/*****************************
* 0xFFFF0000 ==> 255.255.0.0
****************************/
int str_aton(const unsigned bip, char *sip)
{
int count;
char pa[4];
unsigned temp;
unsigned umask = 0xFF;
memset(pa, 0, 4);
memset(sip, 0, LIP);
for (count=3; count>=0; count--){
temp = umask & bip>>(count*8);
sprintf(pa, "%i", temp);
strcat(sip, pa);
if (count != 0){
strcat(sip, ".");
}
}
}
/*****************************
* 255.255.0.0 ==> 0xFFFF0000
*****************************/
unsigned bin_aton(const char *sip)
{
int i;
int M = 8;
unsigned umask;
char str[LIP];
memcpy(str,sip,LIP);
umask = atoi(strtok(str,"."))<<3*M;
for (i=2; i>=0; i--){
umask |= atoi(strtok(NULL,"."))<<i*M;
}
return umask;
}
不用我说 , 一看就明白!