jasonmc / forked-daapd

A re-write of the firefly media server (mt-daapd). It's released under GPLv2+. Please note that this git repository is a mirror of the official one at git://git.debian.org/~jblache/forked-daapd.git
http://blog.technologeek.org/2009/06/12/217
GNU General Public License v2.0
328 stars 45 forks source link

Enhancement: Let forked-daapd listen on a specific interface #65

Open cpsoares opened 12 years ago

cpsoares commented 12 years ago

Hi,

I have a Fedora Core 14 Linux box where, after a bit of a struggle, I managed to build the last forked-daapd (v0.19gcd). I have one pending issue though which I will submit into a separate entry. On my Linux box I have several ethernet interfaces where I'm not interested forked-daapd listening on them. I only want forked-daapd to listen on my LAN side interface. In this sense, it would be interesting to have that interface address configurable via forked-daapd.conf. I managed to implement that in a simple way and I don't know if this change will have any side effects whatsoever on the server behaviour in some scenarios. The change will only permit forked-daapd to listen on only one interface though. Next, I'll post the correspondent diffs to the v0.19gcd codebase. Please validate and incorporate into mainstream if you find this useful.

cpsoares


*** forked-daapd.conf.orig      2011-09-12 22:21:32.000000000 +0100
--- forked-daapd.conf   2011-09-12 22:23:35.000000000 +0100
***************
*** 18,23 ****
--- 18,27 ----
        # Name of the library as displayed by the clients
        # %h: hostname, %v: version
        name = "My Music on %h"
+         # IPv4 listen address. Default address is 0.0.0.0
+ #       ipv4addr = "0.0.0.0"
+         # IPv6 listen address. Default address is ::
+ #       ipv6addr = "::"
        # TCP port to listen on. Default port is 3689 (daap)
        port = 3689
        # Password for the library. Optional.

*** src/httpd.c.orig    2011-09-12 22:09:01.000000000 +0100
--- src/httpd.c 2011-09-12 22:17:15.000000000 +0100
***************
*** 1229,1238 ****
--- 1229,1242 ----
  int
  httpd_init(void)
  {
+   char *ipv4addr;
+   char *ipv6addr;
    unsigned short port;
    int v6enabled;
    int ret;

+   ipv4addr = cfg_getstr(cfg_getsec(cfg, "library"), "ipv4addr");
+   ipv6addr = cfg_getstr(cfg_getsec(cfg, "library"), "ipv6addr");
    port = cfg_getint(cfg_getsec(cfg, "library"), "port");
    v6enabled = cfg_getbool(cfg_getsec(cfg, "general"), "ipv6");

***************
*** 1246,1252 ****
        return -1;
      }

!   http4 = http_server_new(L_HTTPD, http_group, "0.0.0.0", port, httpd_cb, httpd_close_cb);
    if (!http4)
      {
        DPRINTF(E_FATAL, L_HTTPD, "Could not create v4 HTTP server\n");
--- 1250,1256 ----
        return -1;
      }

!   http4 = http_server_new(L_HTTPD, http_group, ipv4addr, port, httpd_cb, httpd_close_cb);
    if (!http4)
      {
        DPRINTF(E_FATAL, L_HTTPD, "Could not create v4 HTTP server\n");
***************
*** 1256,1262 ****

    if (v6enabled)
      {
!       http6 = http_server_new(L_HTTPD, http_group, "::", port, httpd_cb, httpd_close_cb);
        if (!http6)
        DPRINTF(E_WARN, L_HTTPD, "Could not create v6 HTTP server; that's OK\n");
      }
--- 1260,1266 ----

    if (v6enabled)
      {
!       http6 = http_server_new(L_HTTPD, http_group, ipv6addr, port, httpd_cb, httpd_close_cb);
        if (!http6)
        DPRINTF(E_WARN, L_HTTPD, "Could not create v6 HTTP server; that's OK\n");
      }

*** src/conffile.c.orig 2011-09-12 22:14:02.000000000 +0100
--- src/conffile.c      2011-09-12 22:14:54.000000000 +0100
***************
*** 57,62 ****
--- 57,64 ----
  static cfg_opt_t sec_library[] =
    {
      CFG_STR("name", "My Music on %h", CFGF_NONE),
+     CFG_STR("ipv4addr", "0.0.0.0", CFGF_NONE),
+     CFG_STR("ipv6addr", "::", CFGF_NONE),
      CFG_INT("port", 3689, CFGF_NONE),
      CFG_STR("password", NULL, CFGF_NONE),
      CFG_STR_LIST("directories", NULL, CFGF_NONE),