Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inet_aton normalization of a IPv4 address

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
like image 495
sven Avatar asked Apr 05 '13 15:04

sven


1 Answers

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

like image 157
msam Avatar answered Nov 17 '22 20:11

msam