--- a/filter.cpp +++ b/filter.cpp @@ -6,6 +6,9 @@ * $Id$ */ +#include +#include +#include #include #include @@ -47,24 +50,32 @@ u_short cFilterInfosatepg::foldsum(u_lon 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); } @@ -78,27 +89,27 @@ void cFilterInfosatepg::Process(u_short if (Data[0]!=0x3E) return; - struct ethhdr eth_hdr; - memset(ð_hdr,0,sizeof(struct ethhdr)); + struct ether_header eth_hdr; + memset(ð_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(ð_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) @@ -108,7 +119,7 @@ void cFilterInfosatepg::Process(u_short } // 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) @@ -149,8 +160,8 @@ void cFilterInfosatepg::Process(u_short #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, --- 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: --- a/global.cpp +++ b/global.cpp @@ -194,17 +194,17 @@ bool cGlobalInfosatepg::SetDirectory(con 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->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->h_dest[5]h_dest[5]>EPG_LAST_DAY_MAC) return false; + if (eth_hdr->ether_dhost[5]ether_dhost[5]>EPG_LAST_DAY_MAC) return false; return true; } --- a/global.h +++ b/global.h @@ -9,8 +9,10 @@ #ifndef __global_h_ #define __global_h_ +#include #include #include +#include #include #include @@ -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); --- a/infosatepg.cpp +++ b/infosatepg.cpp @@ -403,7 +403,7 @@ cString cPluginInfosatepg::SVDRPCommand( cString head2; head2="\n" \ " | | missed | | | unlocated\n" \ - " Day | Date | Packets | Received %% | Processed | Events\n" \ + " Day | Date | Packets | Received % | Processed | Events\n" \ "------+--------+---------+------------+------------+----------\n"; cString mstr; --- a/process.cpp +++ b/process.cpp @@ -1047,7 +1047,9 @@ bool cProcessInfosatepg::ParseInfosatepg 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,12 @@ bool cProcessInfosatepg::ParseInfosatepg } int shour,sminute; char *title; +#ifdef __FreeBSD__ + title = (char *)malloc(strlen(s)); + 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; --- a/readline.cpp +++ b/readline.cpp @@ -10,6 +10,15 @@ #include #include "readline.h" +#ifdef __FreeBSD__ +#include +#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, 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')