c - inet_aton normalization of a IPv4 address -
doesn't inet_aton
suppose normalize dot version of internet address? why different output values 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 documentation
components of dotted address can specified in decimal, octal (with leading 0), or >hexadecimal, leading 0x)
this means
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
Comments
Post a Comment