Commit Graph

75 Commits

Author SHA1 Message Date
Fabio Alessandrelli c1b64740fb Use WINVER values instead of _WIN32_WINNT_[NAME].
WINVER values are well defined, see:

https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?view=msvc-160
2021-03-18 17:11:48 +01:00
Thomas Bernard 200cf4cd75
miniupnpc: update Changelog.txt + 2021 2021-03-03 00:41:49 +01:00
Thomas BERNARD 94f72a63b5
Merge pull request #486 from hrydgard/fix-uwp-build
Fix Windows UWP build.
2021-02-26 15:41:11 +01:00
Pali Rohár bfbe42d392 miniupnpc: Fix usage of IP_MULTICAST_IF with struct ip_mreqn
When struct ip_mreqn is passed to IP_MULTICAST_IF setsockopt option it is
always required to set also ipv4 source address. Otherwise Linux kernel
will choose default system multicast ipv4 address which does not have to
belong to chosen interface specified in struct ip_mreqn.

Therefore on system with more multicast interfaces and more ipv4 addresses,
it may happen that interface chosen by upnpc -m option would use ipv4
address which does not belong to this interface.

This change is fixing above issue and ensure that if interface is chosen by
upnpc -m option then source address which belongs to this interface would
be used.

Without this change upnpc -m eth1 can send multicast traffic over interface
eth1 but with source ipv4 address of interface eth0, which obviously would
be rejected by upnp gateway.
2021-01-04 00:29:58 +01:00
Pali Rohár 36a6913970 miniupnpc: Add missing checks for if_nametoindex() return value
if_nametoindex() returns zero value on failure. Add missing error handling.
2020-12-30 13:41:20 +01:00
Pali Rohár 0d5b416e05 miniupnpc: Fix checking for inet_pton() errors
inet_pton() indicates error by zero or negative return value.
2020-12-30 13:39:36 +01:00
Pali Rohár 26e8f7831a Use GetBestInterface() instead of GetBestInterfaceEx()
GetBestInterfaceEx() is not supported by older i586-mingw32msvc-gcc
compiler. GetBestInterface() works only with IPv4 addresses but in this
case it is enough as it is needed only for IP address 223.255.255.255.
2020-11-04 23:59:03 +01:00
Pali Rohár 23f492fd1b Fix compilation when _WIN32_WINNT_VISTA macro is not defined
Older version of i586-mingw32msvc-gcc compiler does not define
_WIN32_WINNT_VISTA macro. Therefore preprocessor #if condition is
incorrectly evaluated.
2020-11-04 23:57:43 +01:00
Pali Rohár 8cd542a809 Fix snprintf emulation for Windows
* Move it into separate win32_snprintf.h file to de-duplicate its
  implementation from all miniupnp source files.

* Do not use this emulation with mingw32 SDK when __NO_ISOCEXT is not
  defined as in this case mingw32 provides working snprintf function.

* Fix detection for mingw-w64 variants, when __NO_ISOCEXT is defined or
  when older version without UCRT is used.

* Add check if _scprintf function is available. In case it is not available
  just returns length of filled buffer to prevent buffer overflow.
2020-10-18 20:29:53 +02:00
Thomas Bernard 138b4ff3aa
Fix for compiling with old windows SDK 2020-10-17 22:03:22 +02:00
Thomas Bernard 7a66f373fc inet_pton() instead of inet_addr() 2020-10-17 15:19:58 +02:00
Thomas Bernard 11c479fb2a Merge remote-tracking branch 'pali/master' 2020-10-05 22:02:29 +02:00
Thomas Bernard c7cfe2c51a
fix compilation warning (WIN32) 2020-10-05 21:56:32 +02:00
Pali Rohár 7d5fdf0743 miniupnpc: Fix usage of Windows _snprintf() function
_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
2020-10-02 22:32:36 +02:00
Thomas Bernard 426f9a1835 fix warning 2020-09-24 10:38:05 +02:00
Thomas Bernard 2db013d891
use GetTickCount()/GetTickCount64() under windows
GetTickCount() when GetTickCount64() is not available
2020-09-24 10:19:09 +02:00
Thomas Bernard af1ea9f60b
miniupnpc: use clock_gettime() instead of gettimeofday() if possible 2020-09-24 10:19:08 +02:00
Thomas Bernard aa490867b3
prevent infinite loop in upnpDiscover()
fixes #488
2020-09-24 10:19:08 +02:00
Henrik Rydgård 7e229ddd63 Fix Windows UWP build. 2020-07-21 23:42:42 +02:00
Thomas Bernard 47a55b27c7
miniupnpc: use C99 flexible array member for struct UPNPDev
see #462
2020-05-29 17:59:38 +02:00
CodeforEvolution bffb6a828f Add Haiku Support 2020-02-19 16:07:56 -06:00
Thomas Bernard 9132003aa0
simplify Win32 loop
thanks to irwir !
see https://github.com/miniupnp/miniupnp/pull/362
2019-05-08 15:46:52 +02:00
Thomas Bernard 422d42357e
use strncmp() instead of memcmp() when needed
memcmp(s1, s2, l) is valid when both s1 and s2
have at least l bytes acccessible. So
memcmp("a", "abcdefgh", 8)
is not valid

see #362
2019-04-23 14:16:25 +02:00
Thomas Bernard 5ae326a95e
minissdpc.c: fix variable redeclaration of p 2019-04-10 14:15:33 +02:00
Thomas Bernard 61a18d6b02 getnameinfo() 2nd arg is socklen_t
fixes #350

also fix ressource leak
2019-02-12 14:26:01 +01:00
Thomas Bernard 3e32ea04c8 fix ssdpDiscoverDevices() when building for DEBUG under WIN32 2019-02-11 16:08:55 +01:00
Thomas Bernard e7d99e6b65
fix comment about parseMSEARCHReply() 2019-01-07 09:35:21 +01:00
Cameron Gutman aaa0ed8c86 ensure SSDP reply headers are not partial matches 2019-01-05 12:24:46 -08:00
Thomas Bernard 4b87224e6f fix WIN32 warnings introduced in a31c86b8db 2018-10-31 16:26:01 +01:00
Fabio Alessandrelli a31c86b8db Replace GetBestRoute with UWP-compatible API
Everything should still work with Windows XP as minimum version.
Those API are, according to Microsoft docs, compatible with XP.
2018-09-21 14:56:59 +02:00
irwir a7626af053 Fix conditions for Windows versions below Vista 2018-08-05 15:20:44 +03:00
Thomas Bernard c55d27f46e InetPton() is not available with Win XP so use inet_addr()
see 8babc5d013

Signed-off-by: Thomas Bernard <miniupnp@free.fr>
2018-07-15 12:52:19 +02:00
irwir d8c6433c2e Move common definition to miniupnpc_socketdef.h 2018-07-14 13:39:01 +02:00
Thomas Bernard 8babc5d013 Win32 : use InetPton() etc. to silence MSVC warnings 2018-07-14 12:53:42 +02:00
irwir bded13f390 When code was updated for 64-bit Windows configurations, some changes were not applied.
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>
2018-07-06 11:35:12 +02:00
Thomas Bernard 284db0bb49 miniupnpc: use SOCKET type instead of int for copilation under Win64
see #289
2018-04-06 12:21:36 +02:00
Nikolay Raspopov 1ffb2ea580 Fixed incompatible types (from 'int *' to 'const char *') warning #2
https://msdn.microsoft.com/en-us/library/windows/desktop/ms738574(v=vs.85).aspx
2017-09-18 20:27:10 +03:00
Matthieu Nottale af5c091002 Send error logs to stderr. 2017-04-21 11:25:49 +02:00
Thomas Bernard e6ed3c5b8a do not stop discovery on sendto() failure 2017-03-13 15:33:38 +01:00
Thomas Bernard 8c9ce4dbb4 make sure no unitialized memory is accessed in the sockaddr_un structure 2017-01-09 10:18:16 +01:00
Thomas Bernard d33e1be3a8 avoid useless setsockopt() under solaris
fixes #218
2016-11-11 10:14:14 -05:00
Thomas Bernard c39dda549d better error msg for setsockopt() calls 2016-11-11 10:13:48 -05:00
Thomas Bernard 71ce1d6dfa fix for Solaris 11 compilation
see #216
2016-11-10 21:55:33 +01:00
Thomas Bernard 1579f4a2af 2015 => 2016 2016-10-07 11:16:03 +02:00
Stefan Hertenberger 00121e9830 add NetBSD support 2016-09-03 09:34:15 +02:00
Thomas Bernard 5a284d6b21 fix previous commit. Win32 doesn't have SIOCGIFETADDR 2016-01-17 19:32:05 +01:00
Thomas Bernard aaecdd4190 allow to use interface name for multicast if with *BSD
use SIOCGIFADDR to get interface IP

TODO : check how it works under Win32 ...
2016-01-17 18:49:41 +01:00
Thomas Bernard 899ccb9575 ssdpDiscoverDevices() set error 2015-10-26 11:35:09 +01:00
Wladimir J. van der Laan 4c90b87ce3 Check snprintf result
Verify that the buffer size was large enough to write the output,
raise an error condition if not.
2015-10-25 21:13:23 +01:00
Thomas Bernard 128c8ba7e8 PORT => SSDP_PORT 2015-10-08 18:08:43 +02:00