reduce the binary size of libpcap based programs that don't use bpf parsing
SVN-Revision: 13686
This commit is contained in:
parent
c3f7c0f121
commit
78babdb954
2 changed files with 119 additions and 1 deletions
|
@ -30,7 +30,8 @@ define Package/libpcap/description
|
||||||
packet capture.
|
packet capture.
|
||||||
endef
|
endef
|
||||||
|
|
||||||
TARGET_CFLAGS += $(FPIC)
|
TARGET_CFLAGS += \
|
||||||
|
-ffunction-sections -fdata-sections
|
||||||
|
|
||||||
CONFIGURE_ARGS += \
|
CONFIGURE_ARGS += \
|
||||||
--enable-shared \
|
--enable-shared \
|
||||||
|
|
117
package/libpcap/patches/105-space_optimization.patch
Normal file
117
package/libpcap/patches/105-space_optimization.patch
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
--- a/gencode.c
|
||||||
|
+++ b/gencode.c
|
||||||
|
@@ -429,20 +429,6 @@ pcap_compile_nopcap(int snaplen_arg, int
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
- * Clean up a "struct bpf_program" by freeing all the memory allocated
|
||||||
|
- * in it.
|
||||||
|
- */
|
||||||
|
-void
|
||||||
|
-pcap_freecode(struct bpf_program *program)
|
||||||
|
-{
|
||||||
|
- program->bf_len = 0;
|
||||||
|
- if (program->bf_insns != NULL) {
|
||||||
|
- free((char *)program->bf_insns);
|
||||||
|
- program->bf_insns = NULL;
|
||||||
|
- }
|
||||||
|
-}
|
||||||
|
-
|
||||||
|
-/*
|
||||||
|
* Backpatch the blocks in 'list' to 'target'. The 'sense' field indicates
|
||||||
|
* which of the jt and jf fields has been resolved and which is a pointer
|
||||||
|
* back to another unresolved block (or nil). At least one of the fields
|
||||||
|
--- a/optimize.c
|
||||||
|
+++ b/optimize.c
|
||||||
|
@@ -2263,36 +2263,6 @@ icode_to_fcode(root, lenp)
|
||||||
|
return fp;
|
||||||
|
}
|
||||||
|
|
||||||
|
-/*
|
||||||
|
- * Make a copy of a BPF program and put it in the "fcode" member of
|
||||||
|
- * a "pcap_t".
|
||||||
|
- *
|
||||||
|
- * If we fail to allocate memory for the copy, fill in the "errbuf"
|
||||||
|
- * member of the "pcap_t" with an error message, and return -1;
|
||||||
|
- * otherwise, return 0.
|
||||||
|
- */
|
||||||
|
-int
|
||||||
|
-install_bpf_program(pcap_t *p, struct bpf_program *fp)
|
||||||
|
-{
|
||||||
|
- size_t prog_size;
|
||||||
|
-
|
||||||
|
- /*
|
||||||
|
- * Free up any already installed program.
|
||||||
|
- */
|
||||||
|
- pcap_freecode(&p->fcode);
|
||||||
|
-
|
||||||
|
- prog_size = sizeof(*fp->bf_insns) * fp->bf_len;
|
||||||
|
- p->fcode.bf_len = fp->bf_len;
|
||||||
|
- p->fcode.bf_insns = (struct bpf_insn *)malloc(prog_size);
|
||||||
|
- if (p->fcode.bf_insns == NULL) {
|
||||||
|
- snprintf(p->errbuf, sizeof(p->errbuf),
|
||||||
|
- "malloc: %s", pcap_strerror(errno));
|
||||||
|
- return (-1);
|
||||||
|
- }
|
||||||
|
- memcpy(p->fcode.bf_insns, fp->bf_insns, prog_size);
|
||||||
|
- return (0);
|
||||||
|
-}
|
||||||
|
-
|
||||||
|
#ifdef BDEBUG
|
||||||
|
static void
|
||||||
|
opt_dump(root)
|
||||||
|
--- a/pcap.c
|
||||||
|
+++ b/pcap.c
|
||||||
|
@@ -463,6 +463,52 @@ static const u_char charmap[] = {
|
||||||
|
(u_char)'\374', (u_char)'\375', (u_char)'\376', (u_char)'\377',
|
||||||
|
};
|
||||||
|
|
||||||
|
+/*
|
||||||
|
+ * Clean up a "struct bpf_program" by freeing all the memory allocated
|
||||||
|
+ * in it.
|
||||||
|
+ */
|
||||||
|
+void
|
||||||
|
+pcap_freecode(struct bpf_program *program)
|
||||||
|
+{
|
||||||
|
+ program->bf_len = 0;
|
||||||
|
+ if (program->bf_insns != NULL) {
|
||||||
|
+ free((char *)program->bf_insns);
|
||||||
|
+ program->bf_insns = NULL;
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+/*
|
||||||
|
+ * Make a copy of a BPF program and put it in the "fcode" member of
|
||||||
|
+ * a "pcap_t".
|
||||||
|
+ *
|
||||||
|
+ * If we fail to allocate memory for the copy, fill in the "errbuf"
|
||||||
|
+ * member of the "pcap_t" with an error message, and return -1;
|
||||||
|
+ * otherwise, return 0.
|
||||||
|
+ */
|
||||||
|
+int
|
||||||
|
+install_bpf_program(pcap_t *p, struct bpf_program *fp)
|
||||||
|
+{
|
||||||
|
+ size_t prog_size;
|
||||||
|
+
|
||||||
|
+ /*
|
||||||
|
+ * Free up any already installed program.
|
||||||
|
+ */
|
||||||
|
+ pcap_freecode(&p->fcode);
|
||||||
|
+
|
||||||
|
+ prog_size = sizeof(*fp->bf_insns) * fp->bf_len;
|
||||||
|
+ p->fcode.bf_len = fp->bf_len;
|
||||||
|
+ p->fcode.bf_insns = (struct bpf_insn *)malloc(prog_size);
|
||||||
|
+ if (p->fcode.bf_insns == NULL) {
|
||||||
|
+ snprintf(p->errbuf, sizeof(p->errbuf),
|
||||||
|
+ "malloc: %s", pcap_strerror(errno));
|
||||||
|
+ return (-1);
|
||||||
|
+ }
|
||||||
|
+ memcpy(p->fcode.bf_insns, fp->bf_insns, prog_size);
|
||||||
|
+ return (0);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+
|
||||||
|
int
|
||||||
|
pcap_strcasecmp(const char *s1, const char *s2)
|
||||||
|
{
|
Loading…
Reference in a new issue