[include] rename PATCH to KPATCH
[openwrt.git] / package / libpcap / patches / 201-space_optimization.patch
1 --- a/gencode.c
2 +++ b/gencode.c
3 @@ -439,20 +439,6 @@ pcap_compile_nopcap(int snaplen_arg, int
4 }
5
6 /*
7 - * Clean up a "struct bpf_program" by freeing all the memory allocated
8 - * in it.
9 - */
10 -void
11 -pcap_freecode(struct bpf_program *program)
12 -{
13 - program->bf_len = 0;
14 - if (program->bf_insns != NULL) {
15 - free((char *)program->bf_insns);
16 - program->bf_insns = NULL;
17 - }
18 -}
19 -
20 -/*
21 * Backpatch the blocks in 'list' to 'target'. The 'sense' field indicates
22 * which of the jt and jf fields has been resolved and which is a pointer
23 * back to another unresolved block (or nil). At least one of the fields
24 --- a/pcap.c
25 +++ b/pcap.c
26 @@ -698,6 +698,59 @@ static const u_char charmap[] = {
27 (u_char)'\374', (u_char)'\375', (u_char)'\376', (u_char)'\377',
28 };
29
30 +/*
31 + * Clean up a "struct bpf_program" by freeing all the memory allocated
32 + * in it.
33 + */
34 +void
35 +pcap_freecode(struct bpf_program *program)
36 +{
37 + program->bf_len = 0;
38 + if (program->bf_insns != NULL) {
39 + free((char *)program->bf_insns);
40 + program->bf_insns = NULL;
41 + }
42 +}
43 +
44 +/*
45 + * Make a copy of a BPF program and put it in the "fcode" member of
46 + * a "pcap_t".
47 + *
48 + * If we fail to allocate memory for the copy, fill in the "errbuf"
49 + * member of the "pcap_t" with an error message, and return -1;
50 + * otherwise, return 0.
51 + */
52 +int
53 +install_bpf_program(pcap_t *p, struct bpf_program *fp)
54 +{
55 + size_t prog_size;
56 +
57 + /*
58 + * Validate the program.
59 + */
60 + if (!bpf_validate(fp->bf_insns, fp->bf_len)) {
61 + snprintf(p->errbuf, sizeof(p->errbuf),
62 + "BPF program is not valid");
63 + return (-1);
64 + }
65 +
66 + /*
67 + * Free up any already installed program.
68 + */
69 + pcap_freecode(&p->fcode);
70 +
71 + prog_size = sizeof(*fp->bf_insns) * fp->bf_len;
72 + p->fcode.bf_len = fp->bf_len;
73 + p->fcode.bf_insns = (struct bpf_insn *)malloc(prog_size);
74 + if (p->fcode.bf_insns == NULL) {
75 + snprintf(p->errbuf, sizeof(p->errbuf),
76 + "malloc: %s", pcap_strerror(errno));
77 + return (-1);
78 + }
79 + memcpy(p->fcode.bf_insns, fp->bf_insns, prog_size);
80 + return (0);
81 +}
82 +
83 int
84 pcap_strcasecmp(const char *s1, const char *s2)
85 {
86 --- a/optimize.c
87 +++ b/optimize.c
88 @@ -2278,45 +2278,6 @@ icode_to_fcode(root, lenp)
89 return fp;
90 }
91
92 -/*
93 - * Make a copy of a BPF program and put it in the "fcode" member of
94 - * a "pcap_t".
95 - *
96 - * If we fail to allocate memory for the copy, fill in the "errbuf"
97 - * member of the "pcap_t" with an error message, and return -1;
98 - * otherwise, return 0.
99 - */
100 -int
101 -install_bpf_program(pcap_t *p, struct bpf_program *fp)
102 -{
103 - size_t prog_size;
104 -
105 - /*
106 - * Validate the program.
107 - */
108 - if (!bpf_validate(fp->bf_insns, fp->bf_len)) {
109 - snprintf(p->errbuf, sizeof(p->errbuf),
110 - "BPF program is not valid");
111 - return (-1);
112 - }
113 -
114 - /*
115 - * Free up any already installed program.
116 - */
117 - pcap_freecode(&p->fcode);
118 -
119 - prog_size = sizeof(*fp->bf_insns) * fp->bf_len;
120 - p->fcode.bf_len = fp->bf_len;
121 - p->fcode.bf_insns = (struct bpf_insn *)malloc(prog_size);
122 - if (p->fcode.bf_insns == NULL) {
123 - snprintf(p->errbuf, sizeof(p->errbuf),
124 - "malloc: %s", pcap_strerror(errno));
125 - return (-1);
126 - }
127 - memcpy(p->fcode.bf_insns, fp->bf_insns, prog_size);
128 - return (0);
129 -}
130 -
131 #ifdef BDEBUG
132 static void
133 opt_dump(root)
This page took 0.046025 seconds and 5 git commands to generate.