Date: Wed, 7 Feb 2007 19:44:12 GMT From: "Christian S.J. Peron" <csjp@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 114203 for review Message-ID: <200702071944.l17JiCUe063184@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=114203 Change 114203 by csjp@csjp_rnd01 on 2007/02/07 19:43:27 Add -t for touch headers only Add -T for touching each byte in the packet Affected files ... .. //depot/projects/zcopybpf/utils/bpfnull/bpfnull.c#9 edit Differences ... ==== //depot/projects/zcopybpf/utils/bpfnull/bpfnull.c#9 (text+ko) ==== @@ -63,6 +63,8 @@ static int wflag; static int vflag; static int zflag; +static int tflag; +static int Tflag; static u_char *bufa, *bufb; static int @@ -99,8 +101,21 @@ clen = bhp->bh_caplen; hlen = bhp->bh_hdrlen; p = (u_char *)bp + hlen; - (void) gettimeofday(&phd.ts, NULL); + phd.ts.tv_sec = bhp->bh_tstamp.tv_sec; + phd.ts.tv_usec = bhp->bh_tstamp.tv_usec; phd.caplen = phd.len = bhp->bh_datalen; + if (Tflag) { + int i; + char c; + for (i = 0; i < phd.caplen; i++) + c = p[i]; + bp += BPF_WORDALIGN(clen + hlen); + continue; + } + if (tflag) { + bp += BPF_WORDALIGN(clen + hlen); + continue; + } pcap_dump((u_char *)dp, &phd, p); if (ferror((FILE *)dp)) { perror("dump.pcap"); @@ -117,12 +132,17 @@ fd_set s_set, r_set; struct bpf_zbuf bz; char *pbuf; - int n; + int processed_data, n; struct bpf_zbuf_header *bzha, *bzhb; + struct timeval tv; + void *prev2, *prev; + prev2 = prev = NULL; pbuf = malloc(bflag + 1); if (pbuf == NULL) err(1, "malloc"); + tv.tv_sec = 1; + tv.tv_usec = 0; FD_SET(fd, &s_set); for (;;) { r_set = s_set; @@ -131,13 +151,11 @@ fprintf(stderr,"owned by select\n"); err(1, "select failed"); } - if (!FD_ISSET(fd, &r_set)) { - fprintf(stderr, "FD is NOT set\n"); - continue; - } + if (n != 0 && !FD_ISSET(fd, &r_set)) + printf("No timeout and fd is not ready!\n"); if (vflag) (void) fprintf(stderr, - "DEBUG: wokeup and bpf is ready to read from\n"); + "DEBUG: wokeup and bpf is ready to read from: %d\n", n); if (zflag == 0) { n = read(fd, pbuf, bflag); if (n < 0) @@ -147,8 +165,18 @@ if (wflag) bpf_process_packets(&bz, "W"); } else { + processed_data = 0; bzha = (struct bpf_zbuf_header *)bufa; bzhb = (struct bpf_zbuf_header *)bufb; + + if (n == 0) { + if (ioctl(fd, BIOCROTZBUF, &bz) < 0) + err(1, "ioctl"); + if (bz.bz_bufa == NULL) { + printf("timeout no data\n"); + continue; + } + } if (bzha->bzh_kernel_gen > bzha->bzh_user_gen) { bz.bz_bufa = bufa; bz.bz_bufa += sizeof(struct bpf_zbuf_header); @@ -156,15 +184,17 @@ if (wflag) bpf_process_packets(&bz, "A"); bzha->bzh_user_gen++; - } - if (bzhb->bzh_kernel_gen > bzhb->bzh_user_gen) { + processed_data++; + } else if (bzhb->bzh_kernel_gen > bzhb->bzh_user_gen) { bz.bz_bufa = bufb; bz.bz_bufa += sizeof(struct bpf_zbuf_header); bz.bz_buflen = bzhb->bzh_kernel_len; if (wflag) bpf_process_packets(&bz, "B"); bzhb->bzh_user_gen++; + processed_data++; } + assert(processed_data != 0); } } } @@ -250,7 +280,7 @@ char ch; signal(SIGINT, (void *)handle_int); - while ((ch = getopt(argc, argv, "b:f:hIi:wvz")) != -1) { + while ((ch = getopt(argc, argv, "b:f:hIi:tTwvz")) != -1) { switch (ch) { case 'b': bflag = atoi(optarg); @@ -265,6 +295,12 @@ case 'I': Iflag = 1; break; + case 't': + tflag = 1; + break; + case 'T': + Tflag = 1; + break; case 'w': wflag = 1; break;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200702071944.l17JiCUe063184>