From fc926f81da5ac3d0a310a7fc8c960aee2b04c9bb Mon Sep 17 00:00:00 2001 From: Jochen Dolze Date: Sat, 3 Jan 2009 18:57:48 +0100 Subject: Changed wakeup (now set automatically) Changed setup Changed device chooser Bugfixed segfault with obsolete channels --- filter.cpp | 214 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 107 insertions(+), 107 deletions(-) (limited to 'filter.cpp') diff --git a/filter.cpp b/filter.cpp index 7a3bc89..2eacea6 100644 --- a/filter.cpp +++ b/filter.cpp @@ -15,61 +15,60 @@ cFilterInfosatepg::cFilterInfosatepg(cGlobalInfosatepg *Global) { - global = Global; - Set(global->Pid,0,0); + global = Global; + Set(global->Pid,0,0); } u_long cFilterInfosatepg::do_sum(u_long sum, u_char *buf, int nBytes) { - int nleft=nBytes; - u_short *w = (u_short*)buf; - - while (nleft > 1) - { - sum += *w++; - nleft -= 2; - } - - if (nleft == 1) - { - u_short answer = 0; - *(u_char*)(&answer) = *(u_char*)w; - sum += answer; - } - return sum; + int nleft=nBytes; + u_short *w = (u_short*)buf; + + while (nleft > 1) + { + sum += *w++; + nleft -= 2; + } + + if (nleft == 1) + { + u_short answer = 0; + *(u_char*)(&answer) = *(u_char*)w; + sum += answer; + } + return sum; } u_short cFilterInfosatepg::foldsum(u_long sum) { - while (sum>>16) - sum = (sum >> 16) + (sum & 0xFFFF); + while (sum>>16) + sum = (sum >> 16) + (sum & 0xFFFF); - return ((u_short) ~sum); + return ((u_short) ~sum); } u_short cFilterInfosatepg::IPChecksum(iphdr *ipHeader) { - return foldsum(do_sum(0, (u_char*) ipHeader, sizeof(iphdr))); + return foldsum(do_sum(0, (u_char*) ipHeader, sizeof(iphdr))); } /* IpChecksum() */ u_short cFilterInfosatepg::UDPChecksum(iphdr *ipHeader, udphdr *udpHeader) { - u_long sum = 0; + 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 += udpHeader->len; - sum += ipHeader->protocol<<8; + // 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 += udpHeader->len; + sum += ipHeader->protocol<<8; - sum = do_sum(sum, (u_char*)udpHeader, ntohs(udpHeader->len)); + sum = do_sum(sum, (u_char*)udpHeader, ntohs(udpHeader->len)); - return foldsum(sum); + return foldsum(sum); } - void cFilterInfosatepg::Process(u_short Pid, u_char Tid, const u_char *Data, int Length) { #define SECT_IP_HDR_START 12 @@ -77,111 +76,112 @@ void cFilterInfosatepg::Process(u_short Pid, u_char Tid, const u_char *Data, int #define SECT_IS_HDR_START 40 #define SECT_IS_DATA_START 52 - if (Data[0]!=0x3E) return; + if (Data[0]!=0x3E) return; - struct ethhdr eth_hdr; - memset(ð_hdr,0,sizeof(struct ethhdr)); + struct ethhdr eth_hdr; + memset(ð_hdr,0,sizeof(struct ethhdr)); - 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.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]; - if (!global->CheckMAC(ð_hdr)) return; + // check mac and range + if (!global->CheckMAC(ð_hdr)) return; - int mac = eth_hdr.h_dest[5]; + int mac = eth_hdr.h_dest[5]; - struct iphdr *ip_hdr = (iphdr *) &Data[SECT_IP_HDR_START]; - struct udphdr *udp_hdr = (udphdr *) &Data[SECT_UDP_HDR_START]; + struct iphdr *ip_hdr = (iphdr *) &Data[SECT_IP_HDR_START]; + struct udphdr *udp_hdr = (udphdr *) &Data[SECT_UDP_HDR_START]; - // Only IPv4 - if (ip_hdr->version!=4) return; + // Only IPv4 + if (ip_hdr->version!=4) return; - // Check IP checksum - if (IPChecksum(ip_hdr)!=0) - { - dsyslog("infosatepg: ip checksum error"); - return; - } + // Check IP checksum + if (IPChecksum(ip_hdr)!=0) + { + dsyslog("infosatepg: ip checksum error"); + return; + } - // Only UDP - if (ip_hdr->protocol!=17) return; + // Only UDP + if (ip_hdr->protocol!=17) return; - // Check UDP checksum - if (UDPChecksum(ip_hdr,udp_hdr)!=0) - { - dsyslog("infosatepg: udp checksum error"); - return; - } + // Check UDP checksum + if (UDPChecksum(ip_hdr,udp_hdr)!=0) + { + dsyslog("infosatepg: udp checksum error"); + return; + } - struct infosathdr *ishdr = (struct infosathdr*) &Data[SECT_IS_HDR_START]; + struct infosathdr *ishdr = (struct infosathdr*) &Data[SECT_IS_HDR_START]; - if (ntohs(ishdr->technisatId)!=0x0001) return; + if (ntohs(ishdr->technisatId)!=0x0001) return; - const u_char *infosatdata = &Data[SECT_IS_DATA_START]; - int len = Length - SECT_IS_DATA_START-4; + const u_char *infosatdata = &Data[SECT_IS_DATA_START]; + int len = Length - SECT_IS_DATA_START-4; - char file[1024]; - snprintf(file,sizeof(file),"%s/infosatepg%02i%02i_%03i.dat",global->Directory(),ishdr->day,ishdr->month, - ntohs(ishdr->pktcnt)); + char file[1024]; + snprintf(file,sizeof(file),"%s/infosatepg%02i%02i_%03i.dat",global->Directory(),ishdr->day,ishdr->month, + ntohs(ishdr->pktcnt)); - if (global->Infosatdata[mac].NeverSeen(ishdr->day,ishdr->month,ntohs(ishdr->pktcnt))) - { - // never seen such a packet -> init structure - global->Infosatdata[mac].Init(file,ishdr->day,ishdr->month,ntohs(ishdr->pktcnt)); - } + if (global->Infosatdata[mac].NeverSeen(ishdr->day,ishdr->month,ntohs(ishdr->pktcnt))) + { + // never seen such a packet -> init structure + global->Infosatdata[mac].Init(file,ishdr->day,ishdr->month,ntohs(ishdr->pktcnt)); + } - // Check if we already have this packet - if (global->Infosatdata[mac].GetBit(ntohs(ishdr->pktnr))) return; + // Check if we already have this packet + if (global->Infosatdata[mac].GetBit(ntohs(ishdr->pktnr))) return; - // set bit in Infosatdata bitfield - global->Infosatdata[mac].SetBit(ntohs(ishdr->pktnr),true); + // set bit in Infosatdata bitfield + global->Infosatdata[mac].SetBit(ntohs(ishdr->pktnr),true); #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.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: 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, - ishdr->month, ntohs(ishdr->pktnr), ntohs(ishdr->pktcnt), len); + 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, + ishdr->month, ntohs(ishdr->pktnr), ntohs(ishdr->pktcnt), len); - dsyslog("infosatepg: save to %s", file); + dsyslog("infosatepg: save to %s", file); #endif - int f=open(file,O_RDWR|O_CREAT,0664); - if (f==-1) - { - if (errno!=ENOSPC) + int f=open(file,O_RDWR|O_CREAT,0664); + if (f==-1) { - esyslog("infosatepg: unable to create file '%s'", file); + if (errno!=ENOSPC) + { + esyslog("infosatepg: unable to create file '%s'", file); + } + return; } - return; - } - off_t offset = (off_t) (ntohs(ishdr->pktnr)*1400); - if (lseek(f,offset,SEEK_SET)!=(off_t) -1) - { + off_t offset = (off_t) (ntohs(ishdr->pktnr)*1400); + if (lseek(f,offset,SEEK_SET)!=(off_t) -1) + { #ifdef VDRDEBUG - dsyslog("infosatepg: writing to %li",offset); + dsyslog("infosatepg: writing to %li",offset); #endif - write(f,infosatdata,len); - } - close(f); + write(f,infosatdata,len); + } + close(f); #ifdef WRITE_RAW - sprintf(file,"%s/%03i.dat",dir,ntohs(ishdr->pktnr)); - f=open(file,O_RDWR|O_CREAT,0664); - if (f==-1) return; - write(f,Data,Length); - close(f); + sprintf(file,"%s/%03i.dat",dir,ntohs(ishdr->pktnr)); + f=open(file,O_RDWR|O_CREAT,0664); + if (f==-1) return; + write(f,Data,Length); + close(f); #endif - // check if we have all packets - if (global->Infosatdata[mac].ReceivedAll()) - { - // we have all packets - isyslog("infosatepg: day=%02i month=%02i fully received", ishdr->day,ishdr->month); - } + // check if we have all packets + if (global->Infosatdata[mac].CheckReceivedAll()) + { + // we have all packets + isyslog("infosatepg: day=%02i month=%02i fully received", ishdr->day,ishdr->month); + } } -- cgit v1.2.3