32 Commits

Author SHA1 Message Date
Josh Watzman
ade51e9c94 Fix potential stack smash in getsyshwaddr on OS X
getsyshwaddr assumed that the first ifaddr it came across was the MAC
address, and as such assumes that it has the right length. After
upgrading to OS X 10.13.4, this causes minidlnad to crash on startup due
to tripping stack smash protection -- I'm not sure if the order of
addresses returned previously happened to accidentally hit this
invariant, or if this was always an issue and the stack smash protection
got smarter.

In any event, we just need to look for the AF_LINK address and use that.
As an extra check, we make sure the length is the length we expect to
copy into the target buffer.
2018-04-11 10:01:21 -07:00
Gleb Smirnoff
f9a78d598e Support for pluggable event modules, stage 1. Take out select() loop and associated code into a separate module select.c. Detailed list of changes down below.
The idea is taken from the nginx web server, but much simplified and
almost no copypaste left. This will allow minidlna to use different
event dispatcher APIs, which would be defined at compile time.

My personal goal is to convert minidlna to kqueue(2) on FreeBSD. This
would later allow for kqueue based directory change notification, which
won't conflict with select(2) like the current patch does.
Other platforms will also benefit from the pluggability of the event
system, Linux can switch to epoll(2) or at least to poll(2).

Detailed list of changes:

* event.h [New]
  Our internal API to unify different event dispatch systems.
* select.c [New]
  Much simplified version of nginx's ngx_select_module.c.
* minidlna.c
  - Split out listen socket event processing into separate function
    ProcessListen(), which matches event_process_t type.
  - Create and initialize struct event for the monitor socket, SSDP
    socket, HTTP socket and beacon socket.
  - Simplify and make more precise timeout calculation using
    helper timeval functions from utils.c. Treat gettimeofday() error
    as a fatal event.
  - Rip out all stuff related to select(2). Just call event_module.process().
* upnpevents.c
  - Embed struct event into upnp_event_notify.
  - Merge upnp_event_create_notify() with upnp_event_notify_connect().
    Start connecting immediately after socket creation. Garbage collect
    now useless ECreated state.
  - Make upnp_event_process_notify() of event_process_t type, and use it
    as process callback for upnp_event_notify event.
  - Looks like we always create upnp_event_notify with existing subscriber,
    and never clear it later. Remove checks for obj->sub and assert that it
    is never NULL. Simplifies things.
  - When switching obj state, add/del it to event dispatcher accrodingly.
  - Garbage collect upnpevents_selectfds().
  - Garbage collect select(2) related stuff from upnpevents_processfds().
    Rename function to upnpevents_gc(), since the remaining functionality
    is garbage collecting, not file descriptor processing.
    Actually, this can be simplified even more. We can safely close sockets
    and free objects immediately, eliminating need for upnpevents_gc(). But
    this change would be beyond scope of this commit.
* upnphttp.c, upnphttp.h
  Embed struct event into struct upnphttp. Adjust Process_upnphttp() to match
  event_process_t type. Add/del to event dispatcher once creating/closing a
  socket.
* minissdp.c, minissdp.h
  Make ProcessSSDPRequest() of event_process_t type.
* getifaddr.c, getifaddr.h
  Make ProcessMonitorEvent() of event_process_t type.
2018-01-16 16:53:08 -08:00
Justin Maggard
e7ec55a2ad getifaddrs: Fix buffer overrun with >3 interfaces. 2015-07-30 16:25:48 -07:00
Justin Maggard
34cb08928c portability: add support for Illumos
This still won't work on older Solaris systems, but modern Illumos
at least should build and run now.
2014-05-14 17:53:25 -07:00
Justin Maggard
d492b43ef8 Fix various potential illegal access and memory leaks in error conditions. 2014-04-07 11:20:19 -07:00
whosane
301b045cd1 Fix Broken SSDP Multicast Membership Addition. 2014-03-31 09:15:37 -07:00
Justin Maggard
fe7c26da2f ssdp: send a full byebye + alive set when a new interface comes online
If an interface comes online after startup, we really need to send a
complete byebye + alive set on that interface, but we don't want to do
it for other interfaces.  So do it as the interfaces come up, and
skip it for interfaces that existed before the reload.
2014-02-26 15:04:46 -08:00
Justin Maggard
a7c8ffb88d cosmetic: whitespace cleanup 2014-02-26 12:37:14 -08:00
Justin Maggard
a3252bd2dd minissdp: Use struct ip_mreqn for multicast membership if it's available. 2014-02-03 15:02:30 -08:00
Justin Maggard
67fd1fe45a getifaddrs: Fix building on systems without IFF_SLAVE. 2014-02-03 11:57:34 -08:00
Justin Maggard
a21bbe557d Fix a couple file descriptor leaks. 2014-01-16 13:11:54 -08:00
Justin Maggard
c96e6e2adb Skip the initial ssdp:alive packets when initially registering our network
interfaces during startup, so the byebye's can come first.
2013-10-22 18:50:09 -07:00
Justin Maggard
62b6e235b1 Don't require a configured network interface to start up, and add network interface monitoring support on Linux. 2013-05-08 23:52:02 -07:00
Justin Maggard
1e4cf74436 * Enable all network interfaces by default if none were specified. 2013-04-30 21:09:30 +00:00
Justin Maggard
1c748c1d5a * Consolidate client detection code.
* Add forced sorting support for Panasonic devices.
2013-03-18 05:37:46 +00:00
Justin Maggard
08172a4ed2 * Enhance error checking in some additional places as required by the latest UPnP CTT. 2012-01-21 01:00:26 +00:00
Justin Maggard
713fd03ddc * Fix crash on interface list walk with IP-less interfaces. (Thanks Jan Kiszka) 2011-11-02 07:07:39 +00:00
Justin Maggard
773e1f6566 * Add support for other operating systems (kFreeBSD, FreeBSD, and OSX for now).
* Switch to autoconf from genconfig.sh.
2011-09-16 23:39:58 +00:00
Justin Maggard
9a9270cecf * Fix some issues reported by cppcheck. 2011-05-02 23:50:52 +00:00
Justin Maggard
7f51618f71 * Properly get and use the interface's netmask during LAN address configuration. 2011-04-11 22:52:34 +00:00
Justin Maggard
8e0fcd56f9 * Complete/clarify license information. 2010-11-11 23:48:14 +00:00
Justin Maggard
9985630b73 * Fix bug in zero-MAC detection, so UUIDs are actually unique. 2010-09-29 07:46:59 +00:00
Justin Maggard
41f204029b * Fix some issues with uClibc. 2009-10-28 07:44:45 +00:00
Justin Maggard
745457e814 * Don't use getifaddrs(), since it's not portable; and rework the MAC address reading code. 2009-10-23 22:01:05 +00:00
Justin Maggard
51e61e3973 * Track MAC addresses in the client cache (when we can find them); so if we have an expired cache entry, but the MAC hasn't changed, we can assume the original ID is still valid. 2009-07-31 01:41:10 +00:00
Justin Maggard
944729cf12 * Increment version to 1.0.14.
* Fix TiVo beacon issue where it would only broadcast on eth0.
* Fix a couple gcc4.4 warnings.
2009-06-16 01:08:29 +00:00
Justin Maggard
45f294b404 * Use our own logging mechanism instead of syslog/printf. 2009-02-20 10:21:23 +00:00
Justin Maggard
0d3505656d * Fix accidental double-scan from last checkin.
* Add XBox360 compatibility.
2009-02-10 07:41:50 +00:00
Justin Maggard
0324818d86 * Fix some possible memory leaks.
* Pay attention to the specified port number.
* Add support for multiple media directories, and allow content filtering on the directories.
2009-02-03 03:36:59 +00:00
Justin Maggard
3f454a5762 * Don't depend on libavutil carrying the ff_get_fourcc() function.
* Try determining our IP address with hostname lookup before trying eth0 and eth1.
2009-02-02 22:10:39 +00:00
Justin Maggard
74d73037d0 Lots of changes, but notably:
* MiniDLNA can now pass the DLNA Conformance Test!
 * Dependence on libdlna has been removed, and the ffmpeg libs are used directly.
 * Lots of unused code has been cleaned up.
 * File transfers will now be forked off into a new process, so as not to tie up the server when sending data.
2009-01-22 00:25:20 +00:00
Justin Maggard
f557f8ea77 Initial checkin 2008-10-23 17:30:45 +00:00