On 3/2/22 08:58, Paul Gofman wrote:
The imported algorithm modified to match the tests.
Fixes a regression introduced by commit 671cf16f773e5dafc7edbf7766aed9e52e4e7b56.
Windows inet_addr() behaves basically the same as Unix inet_addr() which is different from inet_pton().
Signed-off-by: Paul Gofman <pgofman(a)codeweavers.com> --- v2: - add TRACE(); - formatting.
dlls/ws2_32/protocol.c | 51 +++++++++++++++++++++-- dlls/ws2_32/tests/protocol.c | 80 ++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 4 deletions(-)
While you're at it, would you mind removing the existing, broken tests for inet_addr() from test_inet_pton()? Or I can send a followup patch to remove those...
diff --git a/dlls/ws2_32/protocol.c b/dlls/ws2_32/protocol.c index 0f56b1604d8..3194fff93cd 100644 --- a/dlls/ws2_32/protocol.c +++ b/dlls/ws2_32/protocol.c @@ -1834,17 +1834,60 @@ int WINAPI WSAAddressToStringW( struct sockaddr *addr, DWORD addr_len, return 0; }
- /*********************************************************************** * inet_addr (ws2_32.11) */ u_long WINAPI inet_addr( const char *str ) { + unsigned long a[4] = { 0 }; + const char *s = str; + unsigned char *d; + unsigned int i; u_long addr; + char *z; + + TRACE( "str %s.\n", debugstr_a(str) ); + + if (!s) + { + SetLastError( WSAEFAULT ); + return INADDR_NONE; + } + + d = (unsigned char *)&addr; + + if (s[0] == ' ' && !s[1]) return 0;
- if (inet_pton( AF_INET, str, &addr ) == 1) - return addr; - return INADDR_NONE; + for (i = 0; i < 4; ++i) + { + a[i] = strtoul( s, &z, 0 ); + if (z == s || !isdigit( *s )) return INADDR_NONE; + if (!*z || *z == ' ') break;
A quick test implies that \t is valid here as well; tests for other whitespace characters would probably be useful.
+ if (*z != '.') return INADDR_NONE; + s = z + 1; +