Inet_addr function and leading zeros

I am trying to use the inet_addr function to translate the char IP, but I think that since the IP address I pass to the 'inet_addr' function has a start of 0 (192.169.055.075) , the 'inet_addr function' interprets this differently. Any suggestion on how to remove leading zeros?

thanks

 char IPAddr[20]; //192.169.055.075 ulAddr = inet_addr(IPAddr); 
+4
source share
2 answers

Instead, you can use inet_pton(3) - it does not interpret the leading zero as an octal prefix.

+6
source

What about:

 string addr("192.168.055.075"); replace( addr.begin(), addr.end(), '.', ' ' ); istringstream iss(addr); int a,b,c,d; iss >> a >> b >> c >> d; ostringstream oss; oss << a << '.' << b << '.' << c << '.' << d; string addrWithoutLeadingZeros( oss.str() ); 
0
source

Source: https://habr.com/ru/post/1285921/


All Articles