doesn't inet_aton
suppose to normalize the dot version of the internet address? why do I get different output values for the example below?
int main(){
char USER_IP[16] = "192.168.002.025";
char USER_IP2[16] = "192.168.2.25";
struct sockaddr_in addr;
struct sockaddr_in addr2;
inet_aton(USER_IP2, &addr.sin_addr);
inet_aton(USER_IP, &addr2.sin_addr);
printf("addr.sin_addr:%lu\n", addr.sin_addr);
printf("addr2.sin_addr:%lu\n", addr2.sin_addr);
return 0;
}
output:
addr.sin_addr:419604672
addr2.sin_addr:352495808
from the documentation
components of the dotted address can be specified in decimal, octal (with a leading 0), or >hexadecimal, with a leading 0X)
this means that
char USER_IP[16] = "192.168.002.025";
implies 192 168 2 (25 Octal == 21) and
char USER_IP2[16] = "192.168.2.25";
implies 192 168 2 25
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With