source: rtems-libbsd/freebsd/contrib/libpcap/bpf_image.c @ 97c5f8e8

55-freebsd-126-freebsd-12
Last change on this file since 97c5f8e8 was 97c5f8e8, checked in by Sebastian Huber <sebastian.huber@…>, on 10/09/17 at 07:59:36

Update libpcap to FreeBSD head 2017-04-04

Update libpcap from Git mirror commit
99a648a912e81e29d9c4c159cbbe263462f2d719 to
642b174daddbd0efd9bb5f242c43f4ab4db6869f.

  • Property mode set to 100644
File size: 5.3 KB
Line 
1#include <machine/rtems-bsd-user-space.h>
2
3/*
4 * Copyright (c) 1990, 1991, 1992, 1994, 1995, 1996
5 *      The Regents of the University of California.  All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
18 * written permission.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 */
23
24#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
28#ifdef _WIN32
29#include <pcap-stdinc.h>
30#else /* _WIN32 */
31#if HAVE_INTTYPES_H
32#include <inttypes.h>
33#elif HAVE_STDINT_H
34#include <stdint.h>
35#endif
36#ifdef HAVE_SYS_BITYPES_H
37#include <sys/bitypes.h>
38#endif
39#include <sys/types.h>
40#endif /* _WIN32 */
41
42#include <stdio.h>
43#include <string.h>
44
45#include "pcap-int.h"
46
47#ifdef HAVE_OS_PROTO_H
48#include "os-proto.h"
49#endif
50
51char *
52bpf_image(p, n)
53        const struct bpf_insn *p;
54        int n;
55{
56        int v;
57        const char *fmt, *op;
58        static char image[256];
59        char operand[64];
60
61        v = p->k;
62        switch (p->code) {
63
64        default:
65                op = "unimp";
66                fmt = "0x%x";
67                v = p->code;
68                break;
69
70        case BPF_RET|BPF_K:
71                op = "ret";
72                fmt = "#%d";
73                break;
74
75        case BPF_RET|BPF_A:
76                op = "ret";
77                fmt = "";
78                break;
79
80        case BPF_LD|BPF_W|BPF_ABS:
81                op = "ld";
82                fmt = "[%d]";
83                break;
84
85        case BPF_LD|BPF_H|BPF_ABS:
86                op = "ldh";
87                fmt = "[%d]";
88                break;
89
90        case BPF_LD|BPF_B|BPF_ABS:
91                op = "ldb";
92                fmt = "[%d]";
93                break;
94
95        case BPF_LD|BPF_W|BPF_LEN:
96                op = "ld";
97                fmt = "#pktlen";
98                break;
99
100        case BPF_LD|BPF_W|BPF_IND:
101                op = "ld";
102                fmt = "[x + %d]";
103                break;
104
105        case BPF_LD|BPF_H|BPF_IND:
106                op = "ldh";
107                fmt = "[x + %d]";
108                break;
109
110        case BPF_LD|BPF_B|BPF_IND:
111                op = "ldb";
112                fmt = "[x + %d]";
113                break;
114
115        case BPF_LD|BPF_IMM:
116                op = "ld";
117                fmt = "#0x%x";
118                break;
119
120        case BPF_LDX|BPF_IMM:
121                op = "ldx";
122                fmt = "#0x%x";
123                break;
124
125        case BPF_LDX|BPF_MSH|BPF_B:
126                op = "ldxb";
127                fmt = "4*([%d]&0xf)";
128                break;
129
130        case BPF_LD|BPF_MEM:
131                op = "ld";
132                fmt = "M[%d]";
133                break;
134
135        case BPF_LDX|BPF_MEM:
136                op = "ldx";
137                fmt = "M[%d]";
138                break;
139
140        case BPF_ST:
141                op = "st";
142                fmt = "M[%d]";
143                break;
144
145        case BPF_STX:
146                op = "stx";
147                fmt = "M[%d]";
148                break;
149
150        case BPF_JMP|BPF_JA:
151                op = "ja";
152                fmt = "%d";
153                v = n + 1 + p->k;
154                break;
155
156        case BPF_JMP|BPF_JGT|BPF_K:
157                op = "jgt";
158                fmt = "#0x%x";
159                break;
160
161        case BPF_JMP|BPF_JGE|BPF_K:
162                op = "jge";
163                fmt = "#0x%x";
164                break;
165
166        case BPF_JMP|BPF_JEQ|BPF_K:
167                op = "jeq";
168                fmt = "#0x%x";
169                break;
170
171        case BPF_JMP|BPF_JSET|BPF_K:
172                op = "jset";
173                fmt = "#0x%x";
174                break;
175
176        case BPF_JMP|BPF_JGT|BPF_X:
177                op = "jgt";
178                fmt = "x";
179                break;
180
181        case BPF_JMP|BPF_JGE|BPF_X:
182                op = "jge";
183                fmt = "x";
184                break;
185
186        case BPF_JMP|BPF_JEQ|BPF_X:
187                op = "jeq";
188                fmt = "x";
189                break;
190
191        case BPF_JMP|BPF_JSET|BPF_X:
192                op = "jset";
193                fmt = "x";
194                break;
195
196        case BPF_ALU|BPF_ADD|BPF_X:
197                op = "add";
198                fmt = "x";
199                break;
200
201        case BPF_ALU|BPF_SUB|BPF_X:
202                op = "sub";
203                fmt = "x";
204                break;
205
206        case BPF_ALU|BPF_MUL|BPF_X:
207                op = "mul";
208                fmt = "x";
209                break;
210
211        case BPF_ALU|BPF_DIV|BPF_X:
212                op = "div";
213                fmt = "x";
214                break;
215
216        case BPF_ALU|BPF_MOD|BPF_X:
217                op = "mod";
218                fmt = "x";
219                break;
220
221        case BPF_ALU|BPF_AND|BPF_X:
222                op = "and";
223                fmt = "x";
224                break;
225
226        case BPF_ALU|BPF_OR|BPF_X:
227                op = "or";
228                fmt = "x";
229                break;
230
231        case BPF_ALU|BPF_XOR|BPF_X:
232                op = "xor";
233                fmt = "x";
234                break;
235
236        case BPF_ALU|BPF_LSH|BPF_X:
237                op = "lsh";
238                fmt = "x";
239                break;
240
241        case BPF_ALU|BPF_RSH|BPF_X:
242                op = "rsh";
243                fmt = "x";
244                break;
245
246        case BPF_ALU|BPF_ADD|BPF_K:
247                op = "add";
248                fmt = "#%d";
249                break;
250
251        case BPF_ALU|BPF_SUB|BPF_K:
252                op = "sub";
253                fmt = "#%d";
254                break;
255
256        case BPF_ALU|BPF_MUL|BPF_K:
257                op = "mul";
258                fmt = "#%d";
259                break;
260
261        case BPF_ALU|BPF_DIV|BPF_K:
262                op = "div";
263                fmt = "#%d";
264                break;
265
266        case BPF_ALU|BPF_MOD|BPF_K:
267                op = "mod";
268                fmt = "#%d";
269                break;
270
271        case BPF_ALU|BPF_AND|BPF_K:
272                op = "and";
273                fmt = "#0x%x";
274                break;
275
276        case BPF_ALU|BPF_OR|BPF_K:
277                op = "or";
278                fmt = "#0x%x";
279                break;
280
281        case BPF_ALU|BPF_XOR|BPF_K:
282                op = "xor";
283                fmt = "#0x%x";
284                break;
285
286        case BPF_ALU|BPF_LSH|BPF_K:
287                op = "lsh";
288                fmt = "#%d";
289                break;
290
291        case BPF_ALU|BPF_RSH|BPF_K:
292                op = "rsh";
293                fmt = "#%d";
294                break;
295
296        case BPF_ALU|BPF_NEG:
297                op = "neg";
298                fmt = "";
299                break;
300
301        case BPF_MISC|BPF_TAX:
302                op = "tax";
303                fmt = "";
304                break;
305
306        case BPF_MISC|BPF_TXA:
307                op = "txa";
308                fmt = "";
309                break;
310        }
311        (void)pcap_snprintf(operand, sizeof operand, fmt, v);
312        if (BPF_CLASS(p->code) == BPF_JMP && BPF_OP(p->code) != BPF_JA) {
313                (void)pcap_snprintf(image, sizeof image,
314                              "(%03d) %-8s %-16s jt %d\tjf %d",
315                              n, op, operand, n + 1 + p->jt, n + 1 + p->jf);
316        } else {
317                (void)pcap_snprintf(image, sizeof image,
318                              "(%03d) %-8s %s",
319                              n, op, operand);
320        }
321        return image;
322}
Note: See TracBrowser for help on using the repository browser.