105-space_optimization.patch 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. --- a/gencode.c
  2. +++ b/gencode.c
  3. @@ -429,20 +429,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/optimize.c
  24. +++ b/optimize.c
  25. @@ -2263,36 +2263,6 @@ icode_to_fcode(root, lenp)
  26. return fp;
  27. }
  28. -/*
  29. - * Make a copy of a BPF program and put it in the "fcode" member of
  30. - * a "pcap_t".
  31. - *
  32. - * If we fail to allocate memory for the copy, fill in the "errbuf"
  33. - * member of the "pcap_t" with an error message, and return -1;
  34. - * otherwise, return 0.
  35. - */
  36. -int
  37. -install_bpf_program(pcap_t *p, struct bpf_program *fp)
  38. -{
  39. - size_t prog_size;
  40. -
  41. - /*
  42. - * Free up any already installed program.
  43. - */
  44. - pcap_freecode(&p->fcode);
  45. -
  46. - prog_size = sizeof(*fp->bf_insns) * fp->bf_len;
  47. - p->fcode.bf_len = fp->bf_len;
  48. - p->fcode.bf_insns = (struct bpf_insn *)malloc(prog_size);
  49. - if (p->fcode.bf_insns == NULL) {
  50. - snprintf(p->errbuf, sizeof(p->errbuf),
  51. - "malloc: %s", pcap_strerror(errno));
  52. - return (-1);
  53. - }
  54. - memcpy(p->fcode.bf_insns, fp->bf_insns, prog_size);
  55. - return (0);
  56. -}
  57. -
  58. #ifdef BDEBUG
  59. static void
  60. opt_dump(root)
  61. --- a/pcap.c
  62. +++ b/pcap.c
  63. @@ -463,6 +463,52 @@ static const u_char charmap[] = {
  64. (u_char)'\374', (u_char)'\375', (u_char)'\376', (u_char)'\377',
  65. };
  66. +/*
  67. + * Clean up a "struct bpf_program" by freeing all the memory allocated
  68. + * in it.
  69. + */
  70. +void
  71. +pcap_freecode(struct bpf_program *program)
  72. +{
  73. + program->bf_len = 0;
  74. + if (program->bf_insns != NULL) {
  75. + free((char *)program->bf_insns);
  76. + program->bf_insns = NULL;
  77. + }
  78. +}
  79. +
  80. +
  81. +/*
  82. + * Make a copy of a BPF program and put it in the "fcode" member of
  83. + * a "pcap_t".
  84. + *
  85. + * If we fail to allocate memory for the copy, fill in the "errbuf"
  86. + * member of the "pcap_t" with an error message, and return -1;
  87. + * otherwise, return 0.
  88. + */
  89. +int
  90. +install_bpf_program(pcap_t *p, struct bpf_program *fp)
  91. +{
  92. + size_t prog_size;
  93. +
  94. + /*
  95. + * Free up any already installed program.
  96. + */
  97. + pcap_freecode(&p->fcode);
  98. +
  99. + prog_size = sizeof(*fp->bf_insns) * fp->bf_len;
  100. + p->fcode.bf_len = fp->bf_len;
  101. + p->fcode.bf_insns = (struct bpf_insn *)malloc(prog_size);
  102. + if (p->fcode.bf_insns == NULL) {
  103. + snprintf(p->errbuf, sizeof(p->errbuf),
  104. + "malloc: %s", pcap_strerror(errno));
  105. + return (-1);
  106. + }
  107. + memcpy(p->fcode.bf_insns, fp->bf_insns, prog_size);
  108. + return (0);
  109. +}
  110. +
  111. +
  112. int
  113. pcap_strcasecmp(const char *s1, const char *s2)
  114. {