> I'm porting a simple Unix program, that uses sockets, to Windows with the use
> of wingw gcc.
> I'm getting a linker error "undefined reference to `inet_aton'" when I
> compile my program:
> \mingw\bin\gcc -o ir2diskc ir2diskc.c -lsw2_32
> Do I need to link with some other library in addition to sw2_32 or is
> inet_aton() simply not available in Windows?
> If it is the latter how do you convert an address to binary in Windows?
This must be a typo, because if you really did specify "-lsw2_32" then
you would have gotten an error like "cannot find -lsw2_32: No such file"
because that is not the correct spelling. The name of the library is
ws2_32, the 32 bit Winsock API, revision 2.
But Winsock2 doesn't have inet_aton(), so it wouldn't have mattered if
you spelled it correctly. A suitable replacement would probably be
inet_addr(), or even getaddrinfo(). The latter is complicated by
backwards compatibility issues: Windows natively did not have
getaddrinfo() until XP, and so to support it for prior versions the MS
PSDK includes an inline replacement definition in its headers. The
MinGW w32api does not yet have a corresponding workaround
implementation, so if you want to use getaddrinfo() with MinGW you
currently must only support XP and later -- that is, #define
_WIN32_WINNT to 0x0501 or higher before including the windows headers,
and accept that the resulting binary won't run on 2k/NT/9x.