_snprintf() differs from snprintf() in:
* on overflow it returns -1 instead of required buffer size
* on overflow it does not fill nul byte
* does not accept NULL/0 as a buffer
Microsoft implemented snprintf() in Visual Studio 2015 as part of UCRT.
Mingw32 contains snprintf() implementation only when __USE_MINGW_ANSI_STDIO
is defined.
Mingw-w64 versions prior to 8.0.0. contain snprintf() implementation when
__USE_MINGW_ANSI_STDIO or _UCRT is defined. Since version 8.0.0 it is
always supported.
Mingw-w64 defines both __MINGW32__ and __MINGW64_VERSION_MAJOR macros.
Mingw32 defines only __MINGW32__.
_scprintf() just count number of bytes needed for formatting string, so it
is basically return value of snprintf().
This change updates miniupnpc code to use snprintf() when is provided by
compiler/runtime to avoid usage _snprintf().
And also this changes updates miniupnpc emulation of snprintf() by
_snprintf() and _scprintf() functions to avoid buffer overflows.
For inspiration full emulation of snprintf() by _snprintf() is available in
mingw-w64 stdio library:
https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/stdio/snprintf.c
Details :
cast for connect() sendto() arguments
remove unecessary p = NULL;
remove unecessary code
printf format fixes in ssdpDiscoverDevices()
fixes#311
Signed-off-by: Thomas Bernard <miniupnp@free.fr>
* On Solaris `fd_set` is defined in `sys/select.h`.
* `libsocket`, `libnsl` and `libresolv` are required.
This makes it build cleanly if `MINIUPNPC_SET_SOCKET_TIMEOUT` is forced
to `false` (as tested on Joyent's SmartOS).