diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2002-02-02 17:20:54 +0100 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2002-02-02 17:20:54 +0100 |
commit | 0b7e9057daceab33b13238f4dea90976b5d2074d (patch) | |
tree | d295db6809e43a22e09e704e8a45bfaf3c10e9cb /config.c | |
parent | fa32be64a8781d8c1cdec9b359a2e8fe62668416 (diff) | |
download | vdr-0b7e9057daceab33b13238f4dea90976b5d2074d.tar.gz vdr-0b7e9057daceab33b13238f4dea90976b5d2074d.tar.bz2 |
Introduced 'svdrphosts.conf'
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 51 |
1 files changed, 50 insertions, 1 deletions
@@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: config.c 1.80 2002/02/02 15:57:48 kls Exp $ + * $Id: config.c 1.81 2002/02/02 17:15:03 kls Exp $ */ #include "config.h" @@ -646,6 +646,40 @@ const char *cCommand::Execute(void) return result; } +// -- cSVDRPhost ------------------------------------------------------------- + +cSVDRPhost::cSVDRPhost(void) +{ + addr.s_addr = 0; + mask = 0; +} + +bool cSVDRPhost::Parse(const char *s) +{ + mask = 0xFFFFFFFF; + const char *p = strchr(s, '/'); + if (p) { + char *error = NULL; + int m = strtoul(p + 1, &error, 10); + if (error && !isspace(*error) || m > 32) + return false; + *(char *)p = 0; // yes, we know it's 'const' - will be restored! + if (m == 0) + mask = 0; + else + mask >>= (32 - m); + } + int result = inet_aton(s, &addr); + if (p) + *(char *)p = '/'; // there it is again + return result != 0 && (mask != 0 || addr.s_addr == 0); +} + +bool cSVDRPhost::Accepts(in_addr_t Address) +{ + return (Address & mask) == addr.s_addr; +} + // -- cKeys ------------------------------------------------------------------ cKeys Keys; @@ -778,6 +812,21 @@ cTimer *cTimers::GetNextActiveTimer(void) return t0; } +// -- cSVDRPhosts ------------------------------------------------------------ + +cSVDRPhosts SVDRPhosts; + +bool cSVDRPhosts::Acceptable(in_addr_t Address) +{ + cSVDRPhost *h = First(); + while (h) { + if (h->Accepts(Address)) + return true; + h = (cSVDRPhost *)h->Next(); + } + return false; +} + // -- cSetup ----------------------------------------------------------------- cSetup Setup; |