source: trunk/package/libpcap/patches/105-space_optimization.patch @ 15398

Last change on this file since 15398 was 15398, checked in by nbd, 7 years ago

pcap: update to version 1.0.0, add extension for changing the desired protocol for the internal raw socket (useful for reducing the cpu overhead of capture)

File size: 3.1 KB
  • gencode.c

    a b pcap_compile_nopcap(int snaplen_arg, int 
    439439} 
    440440 
    441441/* 
    442  * Clean up a "struct bpf_program" by freeing all the memory allocated 
    443  * in it. 
    444  */ 
    445 void 
    446 pcap_freecode(struct bpf_program *program) 
    447 { 
    448         program->bf_len = 0; 
    449         if (program->bf_insns != NULL) { 
    450                 free((char *)program->bf_insns); 
    451                 program->bf_insns = NULL; 
    452         } 
    453 } 
    454  
    455 /* 
    456442 * Backpatch the blocks in 'list' to 'target'.  The 'sense' field indicates 
    457443 * which of the jt and jf fields has been resolved and which is a pointer 
    458444 * back to another unresolved block (or nil).  At least one of the fields 
  • pcap.c

    a b static const u_char charmap[] = { 
    698698        (u_char)'\374', (u_char)'\375', (u_char)'\376', (u_char)'\377', 
    699699}; 
    700700 
     701/* 
     702 * Clean up a "struct bpf_program" by freeing all the memory allocated 
     703 * in it. 
     704 */ 
     705void 
     706pcap_freecode(struct bpf_program *program) 
     707{ 
     708        program->bf_len = 0; 
     709        if (program->bf_insns != NULL) { 
     710                free((char *)program->bf_insns); 
     711                program->bf_insns = NULL; 
     712        } 
     713} 
     714 
     715/* 
     716 * Make a copy of a BPF program and put it in the "fcode" member of 
     717 * a "pcap_t". 
     718 * 
     719 * If we fail to allocate memory for the copy, fill in the "errbuf" 
     720 * member of the "pcap_t" with an error message, and return -1; 
     721 * otherwise, return 0. 
     722 */ 
     723int 
     724install_bpf_program(pcap_t *p, struct bpf_program *fp) 
     725{ 
     726        size_t prog_size; 
     727 
     728        /* 
     729         * Validate the program. 
     730         */ 
     731        if (!bpf_validate(fp->bf_insns, fp->bf_len)) { 
     732                snprintf(p->errbuf, sizeof(p->errbuf), 
     733                        "BPF program is not valid"); 
     734                return (-1); 
     735        } 
     736 
     737        /* 
     738         * Free up any already installed program. 
     739         */ 
     740        pcap_freecode(&p->fcode); 
     741 
     742        prog_size = sizeof(*fp->bf_insns) * fp->bf_len; 
     743        p->fcode.bf_len = fp->bf_len; 
     744        p->fcode.bf_insns = (struct bpf_insn *)malloc(prog_size); 
     745        if (p->fcode.bf_insns == NULL) { 
     746                snprintf(p->errbuf, sizeof(p->errbuf), 
     747                         "malloc: %s", pcap_strerror(errno)); 
     748                return (-1); 
     749        } 
     750        memcpy(p->fcode.bf_insns, fp->bf_insns, prog_size); 
     751        return (0); 
     752} 
     753 
    701754int 
    702755pcap_strcasecmp(const char *s1, const char *s2) 
    703756{ 
  • optimize.c

    a b icode_to_fcode(root, lenp) 
    22782278        return fp; 
    22792279} 
    22802280 
    2281 /* 
    2282  * Make a copy of a BPF program and put it in the "fcode" member of 
    2283  * a "pcap_t". 
    2284  * 
    2285  * If we fail to allocate memory for the copy, fill in the "errbuf" 
    2286  * member of the "pcap_t" with an error message, and return -1; 
    2287  * otherwise, return 0. 
    2288  */ 
    2289 int 
    2290 install_bpf_program(pcap_t *p, struct bpf_program *fp) 
    2291 { 
    2292         size_t prog_size; 
    2293  
    2294         /* 
    2295          * Validate the program. 
    2296          */ 
    2297         if (!bpf_validate(fp->bf_insns, fp->bf_len)) { 
    2298                 snprintf(p->errbuf, sizeof(p->errbuf), 
    2299                         "BPF program is not valid"); 
    2300                 return (-1); 
    2301         } 
    2302  
    2303         /* 
    2304          * Free up any already installed program. 
    2305          */ 
    2306         pcap_freecode(&p->fcode); 
    2307  
    2308         prog_size = sizeof(*fp->bf_insns) * fp->bf_len; 
    2309         p->fcode.bf_len = fp->bf_len; 
    2310         p->fcode.bf_insns = (struct bpf_insn *)malloc(prog_size); 
    2311         if (p->fcode.bf_insns == NULL) { 
    2312                 snprintf(p->errbuf, sizeof(p->errbuf), 
    2313                          "malloc: %s", pcap_strerror(errno)); 
    2314                 return (-1); 
    2315         } 
    2316         memcpy(p->fcode.bf_insns, fp->bf_insns, prog_size); 
    2317         return (0); 
    2318 } 
    2319  
    23202281#ifdef BDEBUG 
    23212282static void 
    23222283opt_dump(root) 
Note: See TracBrowser for help on using the repository browser.