summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJochen Dolze <vdr@dolze.de>2010-07-12 11:37:22 +0200
committerJochen Dolze <vdr@dolze.de>2010-07-12 11:37:22 +0200
commitf233276220fe3ecf89b7d69d3f6e9d09f89ced3e (patch)
tree2a1aa227cb6d71028b76123e9a69f1cc6366adfb
parent54043194a2afb962f34fd47ed304e2fe634b61b3 (diff)
downloadvdr-plugin-infosatepg-f233276220fe3ecf89b7d69d3f6e9d09f89ced3e.tar.gz
vdr-plugin-infosatepg-f233276220fe3ecf89b7d69d3f6e9d09f89ced3e.tar.bz2
Added patch for BSD from nox
-rw-r--r--Makefile2
-rw-r--r--filter.cpp51
-rw-r--r--filter.h4
-rw-r--r--global.cpp18
-rw-r--r--global.h4
-rw-r--r--infosatepg.cpp2
-rw-r--r--process.cpp10
-rw-r--r--readline.cpp33
8 files changed, 89 insertions, 35 deletions
diff --git a/Makefile b/Makefile
index 61ffe8c..2ce3c50 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@ VERSION = $(shell grep 'static const char \*VERSION *=' $(PLUGIN).h | awk '{ pri
### The C++ compiler and options:
CXX ?= g++
-CXXFLAGS ?= -fPIC -g0 -O2 -Wall -Wextra -Woverloaded-virtual -Wno-parentheses
+CXXFLAGS ?= -fPIC -g -O2 -Wall -Wextra -Woverloaded-virtual -Wno-parentheses
### The directory environment:
diff --git a/filter.cpp b/filter.cpp
index 1f378d5..0a61bbf 100644
--- a/filter.cpp
+++ b/filter.cpp
@@ -6,6 +6,9 @@
* $Id$
*/
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <unistd.h>
@@ -53,24 +56,32 @@ u_short cFilterInfosatepg::foldsum(u_long sum)
return ((u_short) ~sum);
}
-u_short cFilterInfosatepg::IPChecksum(iphdr *ipHeader)
+u_short cFilterInfosatepg::IPChecksum(ip *ipHeader)
{
- return foldsum(do_sum(0, (u_char*) ipHeader, sizeof(iphdr)));
+ return foldsum(do_sum(0, (u_char*) ipHeader, sizeof(ip)));
} /* IpChecksum() */
-u_short cFilterInfosatepg::UDPChecksum(iphdr *ipHeader, udphdr *udpHeader)
+u_short cFilterInfosatepg::UDPChecksum(ip *ipHeader, udphdr *udpHeader)
{
u_long sum = 0;
// Ip-Pseudo-Header
- sum = do_sum(sum, (u_char*)(&ipHeader->saddr), sizeof(ipHeader->saddr));
- sum = do_sum(sum, (u_char*)(&ipHeader->daddr), sizeof(ipHeader->daddr));
+ sum = do_sum(sum, (u_char*)(&ipHeader->ip_src), sizeof(ipHeader->ip_src));
+ sum = do_sum(sum, (u_char*)(&ipHeader->ip_dst), sizeof(ipHeader->ip_dst));
+#ifdef __linux__
sum += udpHeader->len;
- sum += ipHeader->protocol<<8;
+#else
+ sum += udpHeader->uh_ulen;
+#endif
+ sum += ipHeader->ip_p<<8;
+#ifdef __linux__
sum = do_sum(sum, (u_char*)udpHeader, ntohs(udpHeader->len));
+#else
+ sum = do_sum(sum, (u_char*)udpHeader, ntohs(udpHeader->uh_ulen));
+#endif
return foldsum(sum);
}
@@ -84,27 +95,27 @@ void cFilterInfosatepg::Process(u_short UNUSED(Pid), u_char UNUSED(Tid), const u
if (Data[0]!=0x3E) return;
- struct ethhdr eth_hdr;
- memset(&eth_hdr,0,sizeof(struct ethhdr));
+ struct ether_header eth_hdr;
+ memset(&eth_hdr,0,sizeof(struct ether_header));
- eth_hdr.h_dest[0]=Data[11];
- eth_hdr.h_dest[1]=Data[10];
- eth_hdr.h_dest[2]=Data[9];
- eth_hdr.h_dest[3]=Data[8];
- eth_hdr.h_dest[4]=Data[4];
- eth_hdr.h_dest[5]=Data[3];
+ eth_hdr.ether_dhost[0]=Data[11];
+ eth_hdr.ether_dhost[1]=Data[10];
+ eth_hdr.ether_dhost[2]=Data[9];
+ eth_hdr.ether_dhost[3]=Data[8];
+ eth_hdr.ether_dhost[4]=Data[4];
+ eth_hdr.ether_dhost[5]=Data[3];
// check mac and range
if (!global->CheckMAC(&eth_hdr)) return;
- int mac = eth_hdr.h_dest[5];
+ int mac = eth_hdr.ether_dhost[5];
global->ActualMac=mac;
- struct iphdr *ip_hdr = (iphdr *) &Data[SECT_IP_HDR_START];
+ struct ip *ip_hdr = (ip *) &Data[SECT_IP_HDR_START];
struct udphdr *udp_hdr = (udphdr *) &Data[SECT_UDP_HDR_START];
// Only IPv4
- if (ip_hdr->version!=4) return;
+ if (ip_hdr->ip_v!=4) return;
// Check IP checksum
if (IPChecksum(ip_hdr)!=0)
@@ -114,7 +125,7 @@ void cFilterInfosatepg::Process(u_short UNUSED(Pid), u_char UNUSED(Tid), const u
}
// Only UDP
- if (ip_hdr->protocol!=17) return;
+ if (ip_hdr->ip_p!=17) return;
// Check UDP checksum
if (UDPChecksum(ip_hdr,udp_hdr)!=0)
@@ -155,8 +166,8 @@ void cFilterInfosatepg::Process(u_short UNUSED(Pid), u_char UNUSED(Tid), const u
#ifdef VDRDEBUG
- dsyslog("infosatepg: mac=%02x-%02x-%02x-%02x-%02x-%02x",eth_hdr.h_dest[0],eth_hdr.h_dest[1],
- eth_hdr.h_dest[2],eth_hdr.h_dest[3],eth_hdr.h_dest[4],eth_hdr.h_dest[5] );
+ dsyslog("infosatepg: mac=%02x-%02x-%02x-%02x-%02x-%02x",eth_hdr.ether_dhost[0],eth_hdr.ether_dhost[1],
+ eth_hdr.ether_dhost[2],eth_hdr.ether_dhost[3],eth_hdr.ether_dhost[4],eth_hdr.ether_dhost[5] );
dsyslog("infosatepg: tid=%04i tbl=%04i stbl=%04i day=%02i month=%02i pktnr=%03i pktcnt=%03i len=%i",
ntohs(ishdr->technisatId),ishdr->tableId,ishdr->tablesubId,ishdr->day,
diff --git a/filter.h b/filter.h
index a21b1ff..651e7f2 100644
--- a/filter.h
+++ b/filter.h
@@ -33,8 +33,8 @@ private:
cGlobalInfosatepg *global;
u_long do_sum(u_long sum, u_char *buf, int nBytes);
u_short foldsum(u_long sum);
- u_short IPChecksum(iphdr *ipHeader);
- u_short UDPChecksum(iphdr *ipHeader, udphdr *udpHeader);
+ u_short IPChecksum(ip *ipHeader);
+ u_short UDPChecksum(ip *ipHeader, udphdr *udpHeader);
protected:
virtual void Process(u_short Pid, u_char Tid, const u_char *Data, int Length);
public:
diff --git a/global.cpp b/global.cpp
index bcc15d4..30fb1fa 100644
--- a/global.cpp
+++ b/global.cpp
@@ -195,17 +195,17 @@ bool cGlobalInfosatepg::SetDirectory(const char *Directory)
return true;
}
-bool cGlobalInfosatepg::CheckMAC(struct ethhdr *eth_hdr)
+bool cGlobalInfosatepg::CheckMAC(ether_header *eth_hdr)
{
if (!eth_hdr) return false;
- if (eth_hdr->h_dest[0]!=MAC[0]) return false;
- if (eth_hdr->h_dest[1]!=MAC[1]) return false;
- if (eth_hdr->h_dest[2]!=MAC[2]) return false;
- if (eth_hdr->h_dest[3]!=MAC[3]) return false;
- if (eth_hdr->h_dest[4]!=MAC[4]) return false;
-
- if (eth_hdr->h_dest[5]<EPG_FIRST_DAY_MAC) return false;
- if (eth_hdr->h_dest[5]>EPG_LAST_DAY_MAC) return false;
+ if (eth_hdr->ether_dhost[0]!=MAC[0]) return false;
+ if (eth_hdr->ether_dhost[1]!=MAC[1]) return false;
+ if (eth_hdr->ether_dhost[2]!=MAC[2]) return false;
+ if (eth_hdr->ether_dhost[3]!=MAC[3]) return false;
+ if (eth_hdr->ether_dhost[4]!=MAC[4]) return false;
+
+ if (eth_hdr->ether_dhost[5]<EPG_FIRST_DAY_MAC) return false;
+ if (eth_hdr->ether_dhost[5]>EPG_LAST_DAY_MAC) return false;
return true;
}
diff --git a/global.h b/global.h
index f67dfd1..9352888 100644
--- a/global.h
+++ b/global.h
@@ -9,8 +9,10 @@
#ifndef __global_h_
#define __global_h_
+#include <sys/socket.h>
#include <netinet/if_ether.h>
#include <sys/types.h>
+#include <ctype.h>
#include <vdr/channels.h>
#include <vdr/timers.h>
@@ -162,7 +164,7 @@ public:
return directory;
}
bool SetDirectory (const char *Directory);
- bool CheckMAC (struct ethhdr *eth_hdr);
+ bool CheckMAC (ether_header *eth_hdr);
void SetWaitTimer()
{
timer=time (NULL);
diff --git a/infosatepg.cpp b/infosatepg.cpp
index fd09db5..916013b 100644
--- a/infosatepg.cpp
+++ b/infosatepg.cpp
@@ -407,7 +407,7 @@ cString cPluginInfosatepg::SVDRPCommand(const char *Command, const char *UNUSED(
cString head2;
head2="\n" \
" | | missed | | | unlocated\n" \
- " Day | Date | Packets | Received %% | Processed | Events\n" \
+ " Day | Date | Packets | Received % | Processed | Events\n" \
"------+--------+---------+------------+------------+----------\n";
cString mstr;
diff --git a/process.cpp b/process.cpp
index 4fbb0b5..ebb4f7a 100644
--- a/process.cpp
+++ b/process.cpp
@@ -1047,7 +1047,9 @@ bool cProcessInfosatepg::ParseInfosatepg(FILE *f,time_t *firststarttime)
int ieventnr=1;
cChannel *chan=NULL;
cInfosatevent *ievent=NULL;
-#if VDRVERSNUM < 10701
+// XXX don't default to assuming UTF-8 on FreeBSD (that's what the NULL does),
+// its still often used without.
+#if VDRVERSNUM < 10701 || defined(__FreeBSD__)
cCharSetConv *conv = new cCharSetConv("ISO-8859-1",cCharSetConv::SystemCharacterTable() ?
cCharSetConv::SystemCharacterTable() : "UTF-8");
#else
@@ -1139,7 +1141,13 @@ bool cProcessInfosatepg::ParseInfosatepg(FILE *f,time_t *firststarttime)
}
int shour,sminute;
char *title;
+#ifdef __FreeBSD__
+ title = (char *)malloc(strlen(s));
+ fields=0;
+ if (title) fields=sscanf(s,"%d:%d %[^^]",&shour,&sminute,title);
+#else
fields=sscanf(s,"%d:%d %a[^^]",&shour,&sminute,&title);
+#endif
if (fields==3)
{
if (!ievent) ievent = new cInfosatevent;
diff --git a/readline.cpp b/readline.cpp
index 50d2b2b..90cc517 100644
--- a/readline.cpp
+++ b/readline.cpp
@@ -10,6 +10,15 @@
#include <stdio.h>
#include "readline.h"
+#ifdef __FreeBSD__
+#include <string.h>
+#if __FreeBSD_version > 800000
+#define HAVE_GETLINE
+#endif
+#else
+#define HAVE_GETLINE
+#endif
+
extern char *strcatrealloc(char *dest, const char *src);
// --- cReadLineInfosatepg ---------------------------------------------------
@@ -36,7 +45,31 @@ char *cReadLineInfosatepg::Read(FILE *f,size_t *size)
do
{
ext=false;
+#ifndef HAVE_GETLINE
+ size_t n;
+
+ if (!tempbuffer)
+ {
+ if (!(tempbuffer = (char *)malloc(tempsize = 4096)))
+ return NULL;
+ }
+ if (!fgets(tempbuffer, tempsize, f))
+ {
+ if (tempbuffer) free(tempbuffer);
+ return buffer;
+ }
+ while ((n = strlen(tempbuffer)) >= tempsize - 1 &&
+ tempbuffer[n - 1] != '\n')
+ {
+ if (!(tempbuffer = (char *)realloc(tempbuffer, tempsize * 2)))
+ return NULL;
+ tempsize *= 2;
+ if (!fgets(tempbuffer + n, tempsize - n, f))
+ break;
+ }
+#else
int n = getline(&tempbuffer, &tempsize, f);
+#endif
if (n > 0)
{
if (tempbuffer[n-1] == '\n')