201-space_optimization.patch 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. --- a/gencode.c
  2. +++ b/gencode.c
  3. @@ -543,20 +543,6 @@ pcap_compile_nopcap(int snaplen_arg, int
  4. }
  5. /*
  6. - * Clean up a "struct bpf_program" by freeing all the memory allocated
  7. - * in it.
  8. - */
  9. -void
  10. -pcap_freecode(struct bpf_program *program)
  11. -{
  12. - program->bf_len = 0;
  13. - if (program->bf_insns != NULL) {
  14. - free((char *)program->bf_insns);
  15. - program->bf_insns = NULL;
  16. - }
  17. -}
  18. -
  19. -/*
  20. * Backpatch the blocks in 'list' to 'target'. The 'sense' field indicates
  21. * which of the jt and jf fields has been resolved and which is a pointer
  22. * back to another unresolved block (or nil). At least one of the fields
  23. --- a/pcap.c
  24. +++ b/pcap.c
  25. @@ -1087,6 +1087,59 @@ static const u_char charmap[] = {
  26. (u_char)'\374', (u_char)'\375', (u_char)'\376', (u_char)'\377',
  27. };
  28. +/*
  29. + * Clean up a "struct bpf_program" by freeing all the memory allocated
  30. + * in it.
  31. + */
  32. +void
  33. +pcap_freecode(struct bpf_program *program)
  34. +{
  35. + program->bf_len = 0;
  36. + if (program->bf_insns != NULL) {
  37. + free((char *)program->bf_insns);
  38. + program->bf_insns = NULL;
  39. + }
  40. +}
  41. +
  42. +/*
  43. + * Make a copy of a BPF program and put it in the "fcode" member of
  44. + * a "pcap_t".
  45. + *
  46. + * If we fail to allocate memory for the copy, fill in the "errbuf"
  47. + * member of the "pcap_t" with an error message, and return -1;
  48. + * otherwise, return 0.
  49. + */
  50. +int
  51. +install_bpf_program(pcap_t *p, struct bpf_program *fp)
  52. +{
  53. + size_t prog_size;
  54. +
  55. + /*
  56. + * Validate the program.
  57. + */
  58. + if (!bpf_validate(fp->bf_insns, fp->bf_len)) {
  59. + snprintf(p->errbuf, sizeof(p->errbuf),
  60. + "BPF program is not valid");
  61. + return (-1);
  62. + }
  63. +
  64. + /*
  65. + * Free up any already installed program.
  66. + */
  67. + pcap_freecode(&p->fcode);
  68. +
  69. + prog_size = sizeof(*fp->bf_insns) * fp->bf_len;
  70. + p->fcode.bf_len = fp->bf_len;
  71. + p->fcode.bf_insns = (struct bpf_insn *)malloc(prog_size);
  72. + if (p->fcode.bf_insns == NULL) {
  73. + snprintf(p->errbuf, sizeof(p->errbuf),
  74. + "malloc: %s", pcap_strerror(errno));
  75. + return (-1);
  76. + }
  77. + memcpy(p->fcode.bf_insns, fp->bf_insns, prog_size);
  78. + return (0);
  79. +}
  80. +
  81. int
  82. pcap_strcasecmp(const char *s1, const char *s2)
  83. {
  84. --- a/optimize.c
  85. +++ b/optimize.c
  86. @@ -2203,45 +2203,6 @@ icode_to_fcode(struct block *root, u_int
  87. return fp;
  88. }
  89. -/*
  90. - * Make a copy of a BPF program and put it in the "fcode" member of
  91. - * a "pcap_t".
  92. - *
  93. - * If we fail to allocate memory for the copy, fill in the "errbuf"
  94. - * member of the "pcap_t" with an error message, and return -1;
  95. - * otherwise, return 0.
  96. - */
  97. -int
  98. -install_bpf_program(pcap_t *p, struct bpf_program *fp)
  99. -{
  100. - size_t prog_size;
  101. -
  102. - /*
  103. - * Validate the program.
  104. - */
  105. - if (!bpf_validate(fp->bf_insns, fp->bf_len)) {
  106. - snprintf(p->errbuf, sizeof(p->errbuf),
  107. - "BPF program is not valid");
  108. - return (-1);
  109. - }
  110. -
  111. - /*
  112. - * Free up any already installed program.
  113. - */
  114. - pcap_freecode(&p->fcode);
  115. -
  116. - prog_size = sizeof(*fp->bf_insns) * fp->bf_len;
  117. - p->fcode.bf_len = fp->bf_len;
  118. - p->fcode.bf_insns = (struct bpf_insn *)malloc(prog_size);
  119. - if (p->fcode.bf_insns == NULL) {
  120. - snprintf(p->errbuf, sizeof(p->errbuf),
  121. - "malloc: %s", pcap_strerror(errno));
  122. - return (-1);
  123. - }
  124. - memcpy(p->fcode.bf_insns, fp->bf_insns, prog_size);
  125. - return (0);
  126. -}
  127. -
  128. #ifdef BDEBUG
  129. static void
  130. dot_dump_node(struct block *block, struct bpf_program *prog, FILE *out)
  131. --- a/pcap-common.c
  132. +++ b/pcap-common.c
  133. @@ -1372,14 +1372,23 @@ swap_pseudo_headers(int linktype, struct
  134. switch (linktype) {
  135. case DLT_USB_LINUX:
  136. +#ifndef PCAP_SUPPORT_USB
  137. + return;
  138. +#endif
  139. swap_linux_usb_header(hdr, data, 0);
  140. break;
  141. case DLT_USB_LINUX_MMAPPED:
  142. +#ifndef PCAP_SUPPORT_USB
  143. + return;
  144. +#endif
  145. swap_linux_usb_header(hdr, data, 1);
  146. break;
  147. case DLT_NFLOG:
  148. +#ifndef PCAP_SUPPORT_NETFILTER
  149. + return;
  150. +#endif
  151. swap_nflog_header(hdr, data);
  152. break;
  153. }