I am trying to convert a number in IP address using pointers in C.
for example: IP = 3229305093 192.123.73.5
and the error i have is:
error: invalid operands to binary * (have ‘int *’ and ‘int’)
bytes[i] = (*ip1 >> (int )i8) & 0xFF;
Here is my function:
void print_ip(int* ip1) {
unsigned char bytes[4];
int i;
for(i=0; i<4; i++) {
bytes[i] = (*ip1 >> (int *)i*8) & 0xFF;
}
printf("%d.%d.%d.%d
", bytes[3], bytes[2], bytes[1], bytes[0]);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…