POGEL::IMAGE::IMAGE(const char *filename, int filter) { data=(char*)NULL; base=(unsigned int)NULL; tstr = fileid = ""; sizeX = sizeY = 0; channels = 0; setfilter(IMAGE_DEFAULT_FILTER); setfilter(filter); loadandbuild(filename); }
int populate(void) { regex_t re; int r; /* Can fail when permissions change while browsing */ if (canopendir(path) == 0) return -1; /* Search filter */ r = setfilter(&re, fltr); if (r != 0) return -1; dentfree(dents, n); n = 0; dents = NULL; n = dentfill(path, &dents, visible, &re); qsort(dents, n, sizeof(*dents), entrycmp); /* Find cur from history */ cur = dentfind(dents, n, path, oldpath); free(oldpath); oldpath = NULL; return 0; }
static NTSTATUS drv_control(PDEVICE_OBJECT device, PIRP irp) { PIO_STACK_LOCATION irpstack; ULONG controlcode; NTSTATUS status; irp->IoStatus.Status=STATUS_SUCCESS; irp->IoStatus.Information=0; irpstack=IoGetCurrentIrpStackLocation(irp); controlcode=irpstack->Parameters.DeviceIoControl.IoControlCode; switch(controlcode) { case IOCTL_PEERGUARDIAN_HOOK: if(irp->AssociatedIrp.SystemBuffer!=NULL && irpstack->Parameters.DeviceIoControl.InputBufferLength==sizeof(int)) { int *hook=(int*)irp->AssociatedIrp.SystemBuffer; setfilter((*hook)?filter_cb:NULL); } else irp->IoStatus.Status=STATUS_INVALID_PARAMETER; break; case IOCTL_PEERGUARDIAN_HTTP: if(irp->AssociatedIrp.SystemBuffer!=NULL && irpstack->Parameters.DeviceIoControl.InputBufferLength==sizeof(int)) { g_internal->blockhttp=*((int*)irp->AssociatedIrp.SystemBuffer); } else irp->IoStatus.Status=STATUS_INVALID_PARAMETER; break; case IOCTL_PEERGUARDIAN_SETRANGES: { PGRANGES *ranges; ULONG inputlen; ranges = irp->AssociatedIrp.SystemBuffer; inputlen = irpstack->Parameters.DeviceIoControl.InputBufferLength; if(inputlen >= offsetof(PGRANGES, ranges[0]) && inputlen >= offsetof(PGRANGES, ranges[ranges->count])) { SetRanges(ranges, ranges->block); } else { irp->IoStatus.Status = STATUS_INVALID_PARAMETER; } } break; case IOCTL_PEERGUARDIAN_GETNOTIFICATION: return Notification_Recieve(&g_internal->queue, irp); case IOCTL_PEERGUARDIAN_CONNECTION_LIMIT: if(irp->AssociatedIrp.SystemBuffer!=NULL && irpstack->Parameters.DeviceIoControl.InputBufferLength==sizeof(int)) { g_internal->f_cons_last_received_IP_count_limit=*((int*)irp->AssociatedIrp.SystemBuffer); } else irp->IoStatus.Status=STATUS_INVALID_PARAMETER; break; case IOCTL_PEERGUARDIAN_SET_PORT: if(irp->AssociatedIrp.SystemBuffer!=NULL && irpstack->Parameters.DeviceIoControl.InputBufferLength==sizeof(int)) { int param = *((int*)irp->AssociatedIrp.SystemBuffer); char openstatus = (char)(0xFF & param); unsigned short portnumber = param >> 16; if( portnumber == 0 || openstatus == 0) irp->IoStatus.Status=STATUS_INVALID_PARAMETER; g_internal->f_port_open_ports[ portnumber ] = openstatus - 1; } else irp->IoStatus.Status=STATUS_INVALID_PARAMETER;
void OGL_refresh (void) { if (!ogl_enabled) return; createscanlines (0); setfilter (); OGL_swapinterval (); OGL_render (); }
POGEL::IMAGE::IMAGE() { data=(char*)NULL; base=(unsigned int)NULL; tstr = fileid = ""; sizeX = sizeY = 0; channels = 0; setfilter(IMAGE_DEFAULT_FILTER); }
void OGL_resize (int width, int height) { if (!ogl_enabled) return; w_width = width; w_height = height; glViewport (0, 0, w_width, w_height); glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho (0.0f, w_width, w_height, 0, -1.0f, 1.0f); createscanlines (1); setfilter (); OGL_swapinterval (); }
static NTSTATUS drv_cleanup(PDEVICE_OBJECT device, PIRP irp) { setfilter(NULL); SetRanges(NULL, 0); SetRanges(NULL, 1); #ifndef USE_FIXED_LIST FreeAllocatedBanList(); #endif DestroyNotificationQueue(&g_internal->queue); irp->IoStatus.Status=STATUS_SUCCESS; irp->IoStatus.Information=0; IoCompleteRequest(irp, IO_NO_INCREMENT); return STATUS_SUCCESS; }
static NTSTATUS drv_cleanup(PDEVICE_OBJECT device, PIRP irp) { DbgPrint("pbfilter: > Entering drv_cleanup()\n"); setfilter(NULL); SetRanges(NULL, 0); SetRanges(NULL, 1); DestroyNotificationQueue(&g_internal->queue); irp->IoStatus.Status=STATUS_SUCCESS; irp->IoStatus.Information=0; IoCompleteRequest(irp, IO_NO_INCREMENT); DbgPrint("pbfilter: < Leaving drv_cleanup()\n"); return STATUS_SUCCESS; }
Capture::Capture(){ *errBuf = 0; // 减少错误信息 running = true; if (instance){ *this = *instance; return; } devStr= pcap_lookupdev(errBuf); if(!devStr){ error(); } device = pcap_open_live(devStr, 65535, 1, 0, errBuf); if(!device) { error(); } setfilter("port 80"); instance = this; signal(SIGINT, sig_handler); }
POGEL::IMAGE::IMAGE(std::string s,bool bob) { tstr = s; fileid = POGEL::getStringSection('[',1,false,']',1,false, s); unsigned int x, y; int filter=IMAGE_DEFAULT_FILTER; std::string fileid=""; get_things(s,&fileid,&x,&y,&filter); setfilter(filter); std::ifstream ifs ( fileid.c_str(), std::ifstream::in ); bool ret = ifs.good(); ifs.close(); if(ret && bob) { load(fileid.c_str()); } else { data = NULL; } base = (unsigned int) NULL; }
//void retrans(u_char *user, struct pcap_pkthdr *h, u_char *pack ) { //void retrans(struct pcap_pkthdr *h, u_char *pack ) { int main (int argc, char *argv[]) { //struct pcap_file_header fheader; struct my_pkthdr pheader; struct contents *z; char pktbuff[20000]; int fd, bytes, i, b; long long sstart = 0, ustart = 0, timesec = 0, timeusec = 0; if(argc !=3){ fprintf(stderr, "USAGE: ./executable [log file] [config file]\n"); return(-1); } if((fd = open(argv[1], O_RDONLY)) == -1){ fprintf(stderr, "ERROR: on fd = open(argv[1], O_RDONLY)\n"); return(-1); } if((bytes = read(fd, &pheader, 24)) !=24){ fprintf(stderr, "ERROR: on bytes = read()\n"); return(-1); } fprintf(stdout, "**********************START************************\n"); readcfg1(argv[2]); fprintf(stdout, "Configuration file opened properly\n"); open_devices(); fprintf(stdout, "Devices properly opened\n"); setfilter(); fprintf(stdout, "Filters have been compiled\n"); struct eth_hdr *ethin; struct pcap_pkthdr h; ethin = malloc(sizeof(struct eth_hdr)); i = 0; while((bytes = read(fd, &pheader, 16)) == 16){ if(i == 0){ ustart = pheader.ts.tv_usec; sstart = pheader.ts.tv_sec; } else { timeusec = pheader.ts.tv_usec-ustart; timesec = pheader.ts.tv_sec-sstart; if (timeusec < 0){ timeusec += 1000000; timesec--; } } printf("\nPacket %d\n%05lld.%06lld\nCaptured Packet Length = %d\n",i,timesec,timeusec,pheader.caplen); printf("Actual Packet Length = %d\n", pheader.len); if((bytes = read(fd, &pktbuff, pheader.caplen)) !=pheader.caplen){ fprintf(stdout, "End of file or error on packet read\n"); fprintf(stdout, "%d\n", pheader.caplen); return(-1); } retrans(&pheader, pktbuff); layer2((struct eth_hdr *) &pktbuff, bytes); i++; b = 0; b = pcap_next_ex(p, &h, (const u_char **)ðin); fprintf(stdout, "\tPCAP Read: %d\n", b); } sleep(1); return(0); }
// // Beachtung der Stuffing tables (ST) fehlt noch // int SIsections :: readSections(const unsigned short pid, const unsigned char filter, const unsigned char mask, int readNext, unsigned timeoutInSeconds) { int fd; struct SI_section_header header; unsigned long long firstKey=(unsigned long long)-1; SIsections missingSections; char *buf; if ((fd = open(DEMUX_DEVICE, O_RDWR)) == -1) { perror(DEMUX_DEVICE); return 1; } if (!setfilter(fd, pid, filter, mask, DMX_IMMEDIATE_START | DMX_CHECK_CRC)) { close(fd); return 2; } time_t szeit=time(NULL); // printf("reading first\n"); // Erstes Segment lesen do { if(time(NULL)>szeit+(long)(timeoutInSeconds)) { close(fd); return 0; // timeout -> kein EPG } int rc=readNbytes(fd, (char *)&header, sizeof(header), timeoutInSeconds); if(!rc) { close(fd); return 0; // timeout -> kein EPG } else if(rc<0) { close(fd); // perror ("read header"); return 3; } buf=new char[sizeof(header)+header.section_length-5]; if(!buf) { close(fd); fprintf(stderr, "Not enough memory!\n"); return 4; } // Den Header kopieren memcpy(buf, &header, sizeof(header)); rc=readNbytes(fd, buf+sizeof(header), header.section_length-5, timeoutInSeconds); if(!rc) { close(fd); delete[] buf; return 0; // timeout -> kein EPG } else if(rc<0) { close(fd); // perror ("read section"); delete[] buf; return 5; } if(readNext || header.current_next_indicator) { // Wir wollen nur aktuelle sections insert(SIsection(sizeof(header)+header.section_length-5, buf)); firstKey=SIsection::key(&header); // Sonderfall: Nur eine Section // d.h. wir sind fertig if(!header.section_number && !header.last_section_number) { close(fd); return 0; } } else delete[] buf; } while (firstKey==(unsigned long long) -1); // Die restlichen Segmente lesen szeit=time(NULL); // printf("reading next\n"); for(;;) { if(time(NULL)>szeit+(long)(timeoutInSeconds)) break; // timeout int rc=readNbytes(fd, (char *)&header, sizeof(header), timeoutInSeconds); if(!rc) break; // timeout else if(rc<0) { close(fd); // perror ("read header"); return 6; } if(firstKey==SIsection::key(&header)) // Wir haben die 1. section wieder gefunden break; buf=new char[sizeof(header)+header.section_length-5]; if(!buf) { close(fd); fprintf(stderr, "Not enough memory!\n"); return 7; } // Den Header kopieren (evtl. malloc und realloc nehmen) memcpy(buf, &header, sizeof(header)); // den Rest der Section einlesen rc=readNbytes(fd, buf+sizeof(header), header.section_length-5, timeoutInSeconds); if(!rc) { delete[] buf; break; // timeout } else if(rc<0) { close(fd); delete[] buf; // perror ("read section"); return 8; } if(readNext || header.current_next_indicator) insert(SIsection(sizeof(header)+header.section_length-5, buf)); else delete[] buf; } close(fd); #ifdef DEBUG // Die Sections ausgeben printf("----------------Found sections-----------------------\n"); // for_each(begin(), end(), printSIsection()); for_each(begin(), end(), printSIsectionEIT()); printf("-----------------------------------------------------\n"); #endif // DEBUG // Jetzt erstellen wir eine Liste der fehlenden Sections unsigned actualTableIDextension=(unsigned)-1; unsigned actualTableID=(unsigned)-1; unsigned maxNr=0; unsigned lastNr=0; for(SIsections::iterator k=begin(); k!=end(); k++) { if(k->tableIDextension()!=actualTableIDextension || k->tableID()!=actualTableID) { // Neue Table-ID-Extension maxNr=k->lastSectionNumber(); lastNr=k->sectionNumber(); actualTableIDextension=k->tableIDextension(); actualTableID=k->tableID(); } else if(k->sectionNumber()!=lastNr+1) { // Es fehlen Sections for(unsigned l=lastNr+1; l<k->sectionNumber(); l++) { // printf("Debug: t: 0x%02x s: %u nr: %u last: %u max: %u l: %u\n", actualTableID, actualTableIDextension, k->sectionNumber(), lastNr, maxNr, l); struct SI_section_header h; memcpy(&h, k->header(), sizeof(struct SI_section_header)); h.section_number=l; missingSections.insert(SIsection(&h)); } lastNr=k->sectionNumber(); } else lastNr=k->sectionNumber(); } #ifdef DEBUG printf("Sections read: %d\n\n", size()); #endif // DEBUG if(!missingSections.size()) return 0; #ifdef DEBUG printf("----------------Missing sections---------------------\n"); for_each(missingSections.begin(), missingSections.end(), printSmallSIsectionHeader()); printf("-----------------------------------------------------\n"); printf("Sections read: %d\n\n", size()); printf("Sections misssing: %d\n", missingSections.size()); printf("Searching missing sections\n"); #endif // DEBUG szeit=time(NULL); // printf("reading missing\n"); if ((fd = open(DEMUX_DEVICE, O_RDWR)) == -1) { perror(DEMUX_DEVICE); return 9; } if (!setfilter(fd, pid, filter, mask, DMX_IMMEDIATE_START | DMX_CHECK_CRC)) { close(fd); return 10; } // Jetzt lesen wir die fehlenden Sections ein for(;;) { if(time(NULL)>szeit+(long)(timeoutInSeconds)) break; // Timeout int rc=readNbytes(fd, (char *)&header, sizeof(header), timeoutInSeconds); if(!rc) break; // timeout else if(rc<0) { close(fd); // perror ("read header"); return 11; } buf=new char[sizeof(header)+header.section_length-5]; if(!buf) { close(fd); fprintf(stderr, "Not enough memory!\n"); return 12; } // Den Header kopieren (evtl. malloc und realloc nehmen) memcpy(buf, &header, sizeof(header)); // den Rest der Section einlesen rc=readNbytes(fd, buf+sizeof(header), header.section_length-5, timeoutInSeconds); if(!rc) { delete[] buf; break; // timeout } else if(rc<0) { close(fd); delete[] buf; // perror ("read section"); return 13; } if(missingSections.find(SIsection(&header))!=missingSections.end()) { #ifdef DEBUG printf("Find missing section:"); SIsection::dumpSmallSectionHeader(&header); #endif // DEBUG // War bisher vermisst // In die Menge einfuegen insert(SIsection(sizeof(header)+header.section_length-5, buf)); // Und aus der vermissten Menge entfernen // printf("Sections misssing: %d\n", missingSections.size()); missingSections.erase(SIsection(&header)); #ifdef DEBUG printf("Sections misssing: %d\n", missingSections.size()); #endif // DEBUG } else // Puffer wieder loeschen delete[] buf; } close(fd); return 0; }
logpid_filter::logpid_filter(unsigned int pid) { setfilter(pid); }
logtid_filter::logtid_filter(unsigned int tid) { setfilter(tid); }
void browse(const char *ipath, const char *ifilter) { int r, fd; regex_t re; char *newpath; struct stat sb; char *name, *bin, *dir, *tmp, *run, *env; int nowtyping = 0; FILE *fp; oldpath = NULL; path = xstrdup(ipath); fltr = xstrdup(ifilter); begin: /* Path and filter should be malloc(3)-ed strings at all times */ r = populate(); if (r == -1) { if (!nowtyping) { printwarn(); goto nochange; } } for (;;) { redraw(); /* Handle filter-as-you-type mode */ if (nowtyping) goto moretyping; nochange: switch (nextsel(&run, &env)) { case SEL_QUIT: free(path); free(fltr); dentfree(dents, n); return; case SEL_BACK: /* There is no going back */ if (strcmp(path, "/") == 0 || strcmp(path, ".") == 0 || strchr(path, '/') == NULL) goto nochange; dir = xdirname(path); if (canopendir(dir) == 0) { free(dir); printwarn(); goto nochange; } /* Save history */ oldpath = path; path = dir; /* Reset filter */ free(fltr); fltr = xstrdup(ifilter); goto begin; case SEL_GOIN: /* Cannot descend in empty directories */ if (n == 0) goto nochange; name = dents[cur].name; newpath = mkpath(path, name); DPRINTF_S(newpath); /* Get path info */ fd = open(newpath, O_RDONLY | O_NONBLOCK); if (fd == -1) { printwarn(); free(newpath); goto nochange; } r = fstat(fd, &sb); if (r == -1) { printwarn(); close(fd); free(newpath); goto nochange; } close(fd); DPRINTF_U(sb.st_mode); switch (sb.st_mode & S_IFMT) { case S_IFDIR: if (canopendir(newpath) == 0) { printwarn(); free(newpath); goto nochange; } free(path); path = newpath; /* Reset filter */ free(fltr); fltr = xstrdup(ifilter); goto begin; case S_IFREG: bin = openwith(newpath); if (bin == NULL) { printmsg("No association"); free(newpath); goto nochange; } exitcurses(); spawn(bin, newpath, NULL); initcurses(); free(newpath); continue; default: printmsg("Unsupported file"); goto nochange; } case SEL_FLTR: /* Read filter */ printprompt("filter: "); tmp = readln(); if (tmp == NULL) tmp = xstrdup(ifilter); /* Check and report regex errors */ r = setfilter(&re, tmp); if (r != 0) { free(tmp); goto nochange; } free(fltr); fltr = tmp; DPRINTF_S(fltr); /* Save current */ if (n > 0) oldpath = mkpath(path, dents[cur].name); goto begin; case SEL_TYPE: nowtyping = 1; tmp = NULL; moretyping: printprompt("type: "); if (tmp != NULL) printw("%s", tmp); r = readmore(&tmp); DPRINTF_D(r); DPRINTF_S(tmp); if (r == 1) nowtyping = 0; /* Check regex errors */ if (tmp != NULL) { r = setfilter(&re, tmp); if (r != 0) if (nowtyping) { goto moretyping; } else { free(tmp); goto nochange; } } /* Copy or reset filter */ free(fltr); if (tmp != NULL) fltr = xstrdup(tmp); else fltr = xstrdup(ifilter); /* Save current */ if (n > 0) oldpath = mkpath(path, dents[cur].name); if (!nowtyping) free(tmp); goto begin; case SEL_NEXT: if (cur < n - 1) cur++; break; case SEL_PREV: if (cur > 0) cur--; break; case SEL_PGDN: if (cur < n - 1) cur += MIN((LINES - 4) / 2, n - 1 - cur); break; case SEL_PGUP: if (cur > 0) cur -= MIN((LINES - 4) / 2, cur); break; case SEL_HOME: cur = 0; break; case SEL_END: cur = n - 1; break; case SEL_CD: /* Read target dir */ printprompt("chdir: "); tmp = readln(); if (tmp == NULL) { clearprompt(); goto nochange; } newpath = mkpath(path, tmp); free(tmp); if (canopendir(newpath) == 0) { free(newpath); printwarn(); goto nochange; } free(path); path = newpath; free(fltr); fltr = xstrdup(ifilter); /* Reset filter */ DPRINTF_S(path); goto begin; case SEL_MTIME: mtimeorder = !mtimeorder; /* Save current */ if (n > 0) oldpath = mkpath(path, dents[cur].name); goto begin; case SEL_REDRAW: /* Save current */ if (n > 0) oldpath = mkpath(path, dents[cur].name); goto begin; case SEL_RUN: run = xgetenv(env, run); exitcurses(); spawn(run, NULL, path); initcurses(); break; case SEL_RUNARG: name = dents[cur].name; run = xgetenv(env, run); exitcurses(); spawn(run, name, path); initcurses(); break; case SEL_PRINT: name = dents[cur].name; fp = fopen("savelist.txt", "a"); fprintf(fp, "%s/%s\n", path, name); fclose(fp); break; } /* Screensaver */ if (idletimeout != 0 && idle == idletimeout) { idle = 0; exitcurses(); spawn(idlecmd, NULL, NULL); initcurses(); } } }
logprocessname_filter::logprocessname_filter(const std::wstring& process_name) { setfilter(process_name); }
static NTSTATUS drv_control(PDEVICE_OBJECT device, PIRP irp) { PIO_STACK_LOCATION irpstack; ULONG controlcode; NTSTATUS status; irp->IoStatus.Status=STATUS_SUCCESS; irp->IoStatus.Information=0; irpstack=IoGetCurrentIrpStackLocation(irp); controlcode=irpstack->Parameters.DeviceIoControl.IoControlCode; switch(controlcode) { case IOCTL_PEERBLOCK_HOOK: DbgPrint("pbfilter: > IOCTL_PEERBLOCK_HOOK\n"); if(irp->AssociatedIrp.SystemBuffer!=NULL && irpstack->Parameters.DeviceIoControl.InputBufferLength==sizeof(int)) { int *hook=(int*)irp->AssociatedIrp.SystemBuffer; DbgPrint("pbfilter: setting filter...\n"); setfilter((*hook)?filter_cb:NULL); DbgPrint("pbfilter: ...filter set\n"); } else { DbgPrint("pbfilter: * ERROR: invalid parameter\n"); irp->IoStatus.Status=STATUS_INVALID_PARAMETER; } DbgPrint("pbfilter: < IOCTL_PEERBLOCK_HOOK\n"); break; case IOCTL_PEERBLOCK_SETRANGES: { PBRANGES *ranges; ULONG inputlen; DbgPrint("pbfilter: > IOCTL_PEERBLOCK_SETRANGES\n"); ranges = irp->AssociatedIrp.SystemBuffer; inputlen = irpstack->Parameters.DeviceIoControl.InputBufferLength; if(inputlen >= offsetof(PBRANGES, ranges[0]) && inputlen >= offsetof(PBRANGES, ranges[ranges->count])) { DbgPrint("pbfilter: calling SetRanges()\n"); SetRanges(ranges, ranges->block); } else { DbgPrint("pbfilter: * Error: STATUS_INVALID_PARAMETER\n"); irp->IoStatus.Status = STATUS_INVALID_PARAMETER; } DbgPrint("pbfilter: < IOCTL_PEERBLOCK_SETRANGES\n"); } break; case IOCTL_PEERBLOCK_GETNOTIFICATION: return Notification_Recieve(&g_internal->queue, irp); case IOCTL_PEERBLOCK_SETDESTINATIONPORTS: { USHORT *ports; ULONG count; DbgPrint("pbfilter: > IOCTL_PEERBLOCK_SETDESTINATIONPORTS\n"); ports = irp->AssociatedIrp.SystemBuffer; count = irpstack->Parameters.DeviceIoControl.InputBufferLength; SetDestinationPorts(ports, (USHORT) (count / sizeof(USHORT))); DbgPrint("pbfilter: < IOCTL_PEERBLOCK_SETDESTINATIONPORTS\n"); } break; case IOCTL_PEERBLOCK_SETSOURCEPORTS: { USHORT *ports; ULONG count; DbgPrint("pbfilter: > IOCTL_PEERBLOCK_SETSOURCEPORTS\n"); ports = irp->AssociatedIrp.SystemBuffer; count = irpstack->Parameters.DeviceIoControl.InputBufferLength; SetSourcePorts(ports, (USHORT) (count / sizeof(USHORT))); DbgPrint("pbfilter: < IOCTL_PEERBLOCK_SETSOURCEPORTS\n"); } break; default: DbgPrint("pbfilter: * ERROR: invalid parameter for IOCTL!\n"); irp->IoStatus.Status=STATUS_INVALID_PARAMETER; } status=irp->IoStatus.Status; IoCompleteRequest(irp, IO_NO_INCREMENT); return status; }
bool logtag_filter::load(component_creator *, serializer *s) { setfilter(s->get_property(L"tag")); return true; }
MTInstrument::~MTInstrument() { setfilter(false); }
SIevent SIevent::readActualEvent(unsigned short serviceID, unsigned timeoutInSeconds) { int fd; SIevent evt; // Std-Event das bei Fehler zurueckgeliefert wird struct SI_section_header header; char *buf; if ((fd = open(DEMUX_DEVICE, O_RDWR)) == -1) { perror(DEMUX_DEVICE); return evt; } if (!setfilter(fd, 0x12, 0x4e, 0xff, DMX_IMMEDIATE_START | DMX_CHECK_CRC)) { close(fd); return evt; } time_t szeit=time(NULL); // printf("reading first\n"); // Segment mit Event fuer sid suchen do { int rc=readNbytes(fd, (char *)&header, sizeof(header), timeoutInSeconds); if(!rc) break; // timeout else if(rc<0) { close(fd); perror ("read header"); return evt; } buf=new char[sizeof(header)+header.section_length-5]; if(!buf) { close(fd); printf("Not enough memory!\n"); return evt; } // Den Header kopieren memcpy(buf, &header, sizeof(header)); rc=readNbytes(fd, buf+sizeof(header), header.section_length-5, timeoutInSeconds); if(!rc) { delete[] buf; break; // timeout } if(rc<0) { close(fd); delete[] buf; perror ("read section"); return evt; } if(header.current_next_indicator) { // Wir wollen nur aktuelle sections SIsectionEIT e(SIsection(sizeof(header)+header.section_length-5, buf)); time_t zeit=time(NULL); for(SIevents::iterator k=e.events().begin(); k!=e.events().end(); k++) if(k->serviceID==serviceID) for(SItimes::iterator t=k->times.begin(); t!=k->times.end(); t++) if(t->startzeit<=zeit && zeit<=(long)(t->startzeit+t->dauer)) { close(fd); return SIevent(*k); } } else delete[] buf; } while (time(NULL)<szeit+(long)(timeoutInSeconds)); close(fd); return evt; }
bool logprocessname_filter::load(component_creator *, serializer *s) { setfilter(s->get_property(L"process_name")); return true; }
int main (int argc, char *argv[]) { struct my_pkthdr pheader; struct contents *z; char pktbuff[20000]; int fd, bytes, i, b; long long sstart = 0, ustart = 0, timesec = 0, timeusec = 0; struct eth_hdr *ethin; struct pcap_pkthdr h; struct tcp_hdr *tcphdr; next_ack=0; next_seq=0; int holder; char *progname="HOWDIDTHISGETHEREIAMNOTGOODWITHCOMPUTER"; argv[0]=progname; if(argc !=3){ fprintf(stderr, "USAGE: %s [log file] [config file]\n", argv[0]); return(-1); } if((fd = open(argv[1], O_RDONLY)) == -1){ fprintf(stderr, "ERROR: on fd = open(argv[1], O_RDONLY)\n"); return(-1); } if((bytes = read(fd, &pheader, 24)) !=24){ fprintf(stderr, "ERROR: on bytes = read()\n"); return(-1); } readcfg(argv[2]); open_devices(); setfilter(); ethin = malloc(sizeof(struct eth_hdr)); i = 0; while((bytes = read(fd, &pheader, 16)) == 16){ if(i == 0){ ustart = pheader.ts.tv_usec; sstart = pheader.ts.tv_sec; } else { timeusec = pheader.ts.tv_usec-ustart; timesec = pheader.ts.tv_sec-sstart; if (timeusec < 0){ timeusec += 1000000; timesec--; } } printf("\nPacket %d\n%05lld.%06lld\nCaptured Packet Length = %d\n",i,timesec,timeusec,pheader.caplen); printf("Actual Packet Length = %d\n", pheader.len); if((bytes = read(fd, &pktbuff, pheader.caplen)) !=pheader.caplen){ fprintf(stdout, "End of file or error on packet read\n"); fprintf(stdout, "%d\n", pheader.caplen); return(-1); } retrans(&pheader, pktbuff); layer2((struct eth_hdr *) &pktbuff, bytes); i++; if(strcmp(timing,"delay")==0){ sleep(2); } b = 0; if((b = pcap_next_ex(p, &h, (const u_char **)ðin))==1){ //tcphdr=(struct tcp_hdr *)(ethin+ETH_HDR_LEN+TCP_HDR_LEN); /* if(tcphdr->th_seq==next_seq){ holder=next_ack; next_ack=tcphdr->th_seq+1; next_seq=holder+1; }*/ } } return(0); }
logtag_filter::logtag_filter(const std::wstring& tag) { setfilter(tag); }