switchbrew / libnx

Library for Switch Homebrew
https://switchbrew.github.io/libnx/
ISC License
1.26k stars 167 forks source link

inet_pton() failure for 0.0.0.0 #557

Closed StephenCWills closed 3 years ago

StephenCWills commented 3 years ago

It seems this library uses the same underlying logic for parsing addresses in both inet_addr() and inet_pton(). However, because inet_addr() interprets numbers that start with 0 as octal, this creates an incompatibility with inet_pton() for any address where the last byte is zero. It causes outBase to be returned with the value of 8, and so inet_pton4() reports a failure.

Since this solution for inet_addr() is based on libctru, perhaps it would be good to reference their version of inet_pton() as well. https://github.com/devkitPro/libctru/blob/1f4669fa4c1517cc1018dc53c52662046296dff0/libctru/source/services/soc/soc_inet_pton.c#L7-L14