void change_IP_str(uint32_t num, char *str){
if(!str)
return;
uint32_t andval = 0xff000000;
int i = 0;
for( i = 3;~i;--i){
uint32_t tmp = (num&andval) >> (i<<3);
if(tmp){
int arr[] = {-1, -1, -1};
int cnt = 0;
while(tmp){
arr[cnt++] = tmp%10;
tmp /= 10;
}
while(cnt){
*str++ = ('0' + arr[--cnt]);
}
}
else{
*str++ = '0';
}
if(i) *str++ = '.';
andval >>= 8;
}
return;
}
将u_int32_t的IP地址转为字符串(点分十进制)
于 2022-03-11 23:24:11 首次发布