Some functions in libpcap were changed some time ago to take const pointer 
arguments rather than non-const pointer arguments and to return a const pointer 
value:

        the prefix argument to pcap_perror();

        the return value of pcap_strerror();

        the filter expression argument to pcap_compile() and 
pcap_compile_nopcap();

        the BPF filter program argument to bpf_image().

This patch makes OpenBSD's libpcap function signatures match those of 
tcpdump.org's libpcap in that regard.

Index: bpf_image.c
===================================================================
RCS file: /cvs/src/lib/libpcap/bpf_image.c,v
retrieving revision 1.9
diff -u -r1.9 bpf_image.c
--- bpf_image.c 27 Jan 2004 06:58:02 -0000      1.9
+++ bpf_image.c 31 May 2018 08:04:26 -0000
@@ -35,7 +35,7 @@
 
 char *
 bpf_image(p, n)
-       struct bpf_insn *p;
+       const struct bpf_insn *p;
        int n;
 {
        int v;
Index: gencode.c
===================================================================
RCS file: /cvs/src/lib/libpcap/gencode.c,v
retrieving revision 1.48
diff -u -r1.48 gencode.c
--- gencode.c   6 Feb 2018 02:55:48 -0000       1.48
+++ gencode.c   31 May 2018 08:04:27 -0000
@@ -275,7 +275,7 @@
 
 int
 pcap_compile(pcap_t *p, struct bpf_program *program,
-            char *buf, int optimize, bpf_u_int32 mask)
+            const char *buf, int optimize, bpf_u_int32 mask)
 {
        extern int n_errors;
        int len;
@@ -322,7 +322,7 @@
 int
 pcap_compile_nopcap(int snaplen_arg, int linktype_arg,
                    struct bpf_program *program,
-            char *buf, int optimize, bpf_u_int32 mask)
+            const char *buf, int optimize, bpf_u_int32 mask)
 {
        extern int n_errors;
        int len;
Index: gencode.h
===================================================================
RCS file: /cvs/src/lib/libpcap/gencode.h,v
retrieving revision 1.17
diff -u -r1.17 gencode.h
--- gencode.h   27 Apr 2017 15:46:14 -0000      1.17
+++ gencode.h   31 May 2018 08:04:27 -0000
@@ -200,7 +200,7 @@
 
 struct bpf_insn *icode_to_fcode(struct block *, int *);
 int pcap_parse(void);
-void lex_init(char *);
+void lex_init(const char *);
 void sappend(struct slist *, struct slist *);
 
 /* XXX */
Index: pcap.c
===================================================================
RCS file: /cvs/src/lib/libpcap/pcap.c,v
retrieving revision 1.23
diff -u -r1.23 pcap.c
--- pcap.c      5 Apr 2018 03:47:27 -0000       1.23
+++ pcap.c      31 May 2018 08:04:28 -0000
@@ -415,7 +415,7 @@
 }
 
 void
-pcap_perror(pcap_t *p, char *prefix)
+pcap_perror(pcap_t *p, const char *prefix)
 {
        fprintf(stderr, "%s: %s\n", prefix, p->errbuf);
 }
@@ -531,7 +531,7 @@
 /*
  * Not all systems have strerror().
  */
-char *
+const char *
 pcap_strerror(int errnum)
 {
 #ifdef HAVE_STRERROR
Index: pcap.h
===================================================================
RCS file: /cvs/src/lib/libpcap/pcap.h,v
retrieving revision 1.19
diff -u -r1.19 pcap.h
--- pcap.h      5 Apr 2018 03:47:27 -0000       1.19
+++ pcap.h      31 May 2018 08:04:28 -0000
@@ -188,16 +188,16 @@
 int    pcap_setdirection(pcap_t *, pcap_direction_t);
 int    pcap_getnonblock(pcap_t *, char *);
 int    pcap_setnonblock(pcap_t *, int, char *);
-void   pcap_perror(pcap_t *, char *);
+void   pcap_perror(pcap_t *, const char *);
 int    pcap_inject(pcap_t *, const void *, size_t);
 int    pcap_sendpacket(pcap_t *, const u_char *, int);
 const char *pcap_statustostr(int);
-char   *pcap_strerror(int);
+const char *pcap_strerror(int);
 char   *pcap_geterr(pcap_t *);
-int    pcap_compile(pcap_t *, struct bpf_program *, char *, int,
+int    pcap_compile(pcap_t *, struct bpf_program *, const char *, int,
            bpf_u_int32);
 int    pcap_compile_nopcap(int, int, struct bpf_program *,
-           char *, int, bpf_u_int32);
+           const char *, int, bpf_u_int32);
 void   pcap_freecode(struct bpf_program *);
 int    pcap_offline_filter(const struct bpf_program *,
            const struct pcap_pkthdr *, const u_char *);
@@ -230,7 +230,7 @@
 
 const char *pcap_lib_version(void);
 
-char   *bpf_image(struct bpf_insn *, int);
+char   *bpf_image(const struct bpf_insn *, int);
 
 int    pcap_get_selectable_fd(pcap_t *);
 
Index: scanner.l
===================================================================
RCS file: /cvs/src/lib/libpcap/scanner.l,v
retrieving revision 1.24
diff -u -r1.24 scanner.l
--- scanner.l   9 Jul 2017 15:32:09 -0000       1.24
+++ scanner.l   31 May 2018 08:04:28 -0000
@@ -54,7 +54,7 @@
 #undef YY_INPUT
 #define YY_INPUT(buf, result, max)\
  {\
-       char *src = in_buffer;\
+       const char *src = in_buffer;\
        int i;\
 \
        if (*src == 0)\
@@ -73,7 +73,7 @@
 
 extern YYSTYPE yylval;
 
-static char *in_buffer;
+static const char *in_buffer;
 
 %}
 
@@ -315,7 +315,7 @@
 %%
 void
 lex_init(buf)
-       char *buf;
+       const char *buf;
 {
        in_buffer = buf;
        yyrestart(NULL);

Reply via email to