Main Page Modules Data Structures File List Data Fields Globals Related Pages

# gencode.c File Reference

`#include <pcap-stdinc.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include <memory.h>`
`#include <setjmp.h>`
`#include <stdarg.h>`
`#include "pcap-int.h"`
`#include "ethertype.h"`
`#include "nlpid.h"`
`#include "llc.h"`
`#include "gencode.h"`
`#include "atmuni31.h"`
`#include "sunatmpos.h"`
`#include "ppp.h"`
`#include "sll.h"`
`#include "arcnet.h"`
`#include "pf.h"`
`#include <pcap-namedb.h>`

Go to the source code of this file.

## Data Structures
struct | chunk
## Defines
#define | ETHERMTU 1500
#define | IPPROTO_SCTP 132
#define | JMP(c) ((c)|BPF_JMP|BPF_K)
#define | NCHUNKS 16
#define | CHUNK0SIZE 1024
#define | SWAPLONG(y) ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
#define | IPPROTO_IGMP 2
#define | IPPROTO_IGRP 9
#define | IPPROTO_PIM 103
#define | IPPROTO_VRRP 112
#define | IPPROTO_AH 51
#define | IPPROTO_ESP 50
#define | IPPROTO_NONE 59
## Functions
void | bpf_error (const char *fmt,...)
void | init_linktype (int)
int | alloc_reg (void)
void | free_reg (int)
void * | newchunk (u_int)
void | freechunks (void)
block * | new_block (int)
slist * | new_stmt (int)
block * | gen_retblk (int)
void | syntax (void)
void | backpatch (struct block *, struct block *)
void | merge (struct block *, struct block *)
block * | gen_cmp (u_int, u_int, bpf_int32)
block * | gen_cmp_gt (u_int, u_int, bpf_int32)
block * | gen_mcmp (u_int, u_int, bpf_int32, bpf_u_int32)
block * | gen_bcmp (u_int, u_int, const u_char *)
block * | gen_ncmp (bpf_u_int32, bpf_u_int32, bpf_u_int32, bpf_u_int32, bpf_u_int32, int)
block * | gen_uncond (int)
block * | gen_true (void)
block * | gen_false (void)
block * | gen_ether_linktype (int)
block * | gen_linktype (int)
block * | gen_snap (bpf_u_int32, bpf_u_int32, u_int)
block * | gen_llc (int)
block * | gen_hostop (bpf_u_int32, bpf_u_int32, int, int, u_int, u_int)
block * | gen_ahostop (const u_char *, int)
block * | gen_ehostop (const u_char *, int)
block * | gen_fhostop (const u_char *, int)
block * | gen_thostop (const u_char *, int)
block * | gen_wlanhostop (const u_char *, int)
block * | gen_ipfchostop (const u_char *, int)
block * | gen_dnhostop (bpf_u_int32, int, u_int)
block * | gen_host (bpf_u_int32, bpf_u_int32, int, int)
block * | gen_gateway (const u_char *, bpf_u_int32 **, int, int)
block * | gen_ipfrag (void)
block * | gen_portatom (int, bpf_int32)
block * | gen_portop (int, int, int)
block * | gen_port (int, int, int)
int | lookup_proto (const char *, int)
block * | gen_protochain (int, int, int)
block * | gen_proto (int, int, int)
slist * | xfer_to_x (struct arth *)
slist * | xfer_to_a (struct arth *)
block * | gen_mac_multicast (int)
block * | gen_len (int, int)
block * | gen_msg_abbrev (int type)
void * | newchunk (n) u_int n
int | pcap_compile (pcap_t *p, struct bpf_program *program, char *buf, int optimize, bpf_u_int32 mask)
| Compiles a packet filter. Converts an high level filtering expression (see Filtering expression syntax ) in a program that can be interpreted by the kernel-level filtering engine.
int | pcap_compile_nopcap (int snaplen_arg, int linktype_arg, struct bpf_program *program, char *buf, int optimize, bpf_u_int32 mask)
| Compiles a packet filter without the need of opening an adapter. Converts an high level filtering expression (see Filtering expression syntax ) in a program that can be interpreted by the kernel-level filtering engine.
void | pcap_freecode (struct bpf_program *program)
| Frees a filter.
void | backpatch (list, target) struct block *list
void | init_linktype (type) int type
void | free_reg (n) int n
block * | gen_broadcast (proto) int proto
## Variables
const char rcsid[] | _U_
jmp_buf | top_ctx
pcap_t * | bpf_pcap
u_int | orig_linktype = -1
u_int | orig_nl = -1
u_int | orig_nl_nosnap = -1
int | pcap_fddipad
block * | root
chunk | chunks [NCHUNKS]
int | cur_chunk
int | snaplen
int | no_optimize
void * | target
* | b1
| size
bpf_int32 | v
bpf_u_int32 | mask
| offset
| jtype
| jvalue
int | reverse
u_int | off_linktype
int | is_atm = 0
int | is_lane = 0
u_int | off_vpi
u_int | off_vci
u_int | off_proto
u_int | off_payload
u_int | off_nl
u_int | off_nl_nosnap
int | linktype
bpf_u_int32 | ptype
int | dir
int | proto
u_int | src_off
u_int | dst_off
u_int | base_off
bpf_u_int32 ** | alist
int | ip_proto
qual | q
* | s2
register int | masklen
* | s1
arth * | index
arth * | a0
arth * | a1
int | reversed
int | curreg
| n
| idx
| val

## Define Documentation

#define CHUNK0SIZE 1024

| Definition at line 137 of file gencode.c.

#define ETHERMTU 1500

| Definition at line 81 of file gencode.c.

#define IPPROTO_AH 51

#define IPPROTO_ESP 50

#define IPPROTO_IGMP 2

#define IPPROTO_IGRP 9

#define IPPROTO_NONE 59

#define IPPROTO_PIM 103

#define IPPROTO_SCTP 132

| Definition at line 84 of file gencode.c.

#define IPPROTO_VRRP 112

#define JMP | ( | c |  | ) | ((c)|BPF_JMP|BPF_K)

| Definition at line 91 of file gencode.c.

#define NCHUNKS 16

| Definition at line 136 of file gencode.c.

#define SWAPLONG | ( | y |  | ) | ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))

## Function Documentation

int alloc_reg | ( | void |  | ) | `[static]`

| Definition at line 4595 of file gencode.c. References bpf_error(), curreg, and n.

void backpatch | ( | list | ,
|  | target |
| ) | `[static]`

void backpatch | ( | struct block * | ,
|  | struct block * |
| ) | `[static]`

void bpf_error | ( | const char * | fmt,
|  | ... |
| ) |

| Definition at line 109 of file gencode.c. References bpf_pcap, and pcap_geterr(). Referenced by alloc_reg(), and pcap_compile().

void free_reg | ( | n |  | ) | `[static]`

void free_reg | ( | int |  | ) | `[static]`

void freechunks | ( | void |  | ) | `[static]`

| Referenced by pcap_compile().

struct block* gen_ahostop | ( | const u_char * | ,
|  | int |
| ) | `[static]`

struct block* gen_bcmp | ( | u_int | ,
|  | u_int | ,
|  | const u_char * |
| ) | `[static]`

struct block* gen_broadcast | ( | proto |  | ) |

struct block* gen_cmp | ( | u_int | ,
|  | u_int | ,
|  | bpf_int32 |
| ) | `[static]`

struct block* gen_cmp_gt | ( | u_int | ,
|  | u_int | ,
|  | bpf_int32 |
| ) | `[static]`

struct block* gen_dnhostop | ( | bpf_u_int32 | ,
|  | int | ,
|  | u_int |
| ) | `[static]`

struct block* gen_ehostop | ( | const u_char * | ,
|  | int |
| ) | `[static]`

struct block* gen_ether_linktype | ( | int |  | ) | `[static]`

struct block* gen_false | ( | void |  | ) | `[inline, static]`

struct block* gen_fhostop | ( | const u_char * | ,
|  | int |
| ) | `[static]`

struct block* gen_gateway | ( | const u_char * | ,
|  | bpf_u_int32 ** | ,
|  | int | ,
|  | int |
| ) | `[static]`

struct block* gen_host | ( | bpf_u_int32 | ,
|  | bpf_u_int32 | ,
|  | int | ,
|  | int |
| ) | `[static]`

struct block* gen_hostop | ( | bpf_u_int32 | ,
|  | bpf_u_int32 | ,
|  | int | ,
|  | int | ,
|  | u_int | ,
|  | u_int |
| ) | `[static]`

struct block* gen_ipfchostop | ( | const u_char * | ,
|  | int |
| ) | `[static]`

struct block* gen_ipfrag | ( | void |  | ) | `[static]`

struct block* gen_len | ( | int | ,
|  | int |
| ) | `[static]`

struct block* gen_linktype | ( | int |  | ) | `[static]`

struct block* gen_llc | ( | int |  | ) | `[static]`

struct block* gen_mac_multicast | ( | int |  | ) | `[static]`

struct block* gen_mcmp | ( | u_int | ,
|  | u_int | ,
|  | bpf_int32 | ,
|  | bpf_u_int32 |
| ) | `[static]`

struct block* gen_msg_abbrev | ( | int | type | ) | `[static]`

struct block* gen_ncmp | ( | bpf_u_int32 | ,
|  | bpf_u_int32 | ,
|  | bpf_u_int32 | ,
|  | bpf_u_int32 | ,
|  | bpf_u_int32 | ,
|  | int |
| ) | `[static]`

struct block* gen_port | ( | int | ,
|  | int | ,
|  | int |
| ) | `[static]`

struct block* gen_portatom | ( | int | ,
|  | bpf_int32 |
| ) | `[static]`

struct block* gen_portop | ( | int | ,
|  | int | ,
|  | int |
| ) |

struct block* gen_proto | ( | int | ,
|  | int | ,
|  | int |
| ) | `[static]`

struct block* gen_protochain | ( | int | ,
|  | int | ,
|  | int |
| ) | `[static]`

struct block* gen_retblk | ( | int |  | ) | `[static]`

| Referenced by pcap_compile().

struct block* gen_snap | ( | bpf_u_int32 | ,
|  | bpf_u_int32 | ,
|  | u_int |
| ) | `[static]`

struct block* gen_thostop | ( | const u_char * | ,
|  | int |
| ) | `[static]`

struct block* gen_true | ( | void |  | ) | `[inline, static]`

struct block* gen_uncond | ( | int |  | ) | `[static]`

struct block* gen_wlanhostop | ( | const u_char * | ,
|  | int |
| ) | `[static]`

void init_linktype | ( | type |  | ) | `[static]`

| Referenced by pcap_compile().

void init_linktype | ( | int |  | ) | `[static]`

int lookup_proto | ( | const char * | ,
|  | int |
| ) | `[static]`

void merge | ( | struct block * | ,
|  | struct block * |
| ) | `[static]`

struct block* new_block | ( | int |  | ) | `[inline, static]`

struct slist* new_stmt | ( | int |  | ) | `[inline, static]`

void* newchunk | ( | n |  | ) | `[static]`

void* newchunk | ( | u_int |  | ) | `[static]`

int pcap_compile | ( | pcap_t * | p,
|  | struct bpf_program * | fp,
|  | char * | str,
|  | int | optimize,
|  | bpf_u_int32 | netmask
| ) |

| Compiles a packet filter. Converts an high level filtering expression (see Filtering expression syntax ) in a program that can be interpreted by the kernel-level filtering engine. pcap_compile() is used to compile the string str into a filter program. program is a pointer to a bpf_program struct and is filled in by pcap_compile(). optimize controls whether optimization on the resulting code is performed. netmask specifies the netmask of the local net. A return of -1 indicates an error in which case pcap_geterr() may be used to display the error text. See also: pcap_open_live(), pcap_setfilter(), pcap_freecode(), pcap_snapshot() Definition at line 314 of file gencode.c. References bpf_program::bf_insns, bpf_program::bf_len, bpf_error(), bpf_pcap, freechunks(), gen_retblk(), init_linktype(), mask, no_optimize, pcap_datalink(), PCAP_OPENFLAG_NOCAPTURE_RPCAP, pcap_snapshot(), root, snaplen, snprintf, and syntax(). Referenced by main(), pcap_compile_nopcap(), pcap_createfilter_norpcappkt(), and pcap_pack_bpffilter().

int pcap_compile_nopcap | ( | int | snaplen_arg,
|  | int | linktype_arg,
|  | struct bpf_program * | program,
|  | char * | buf,
|  | int | optimize,
|  | bpf_u_int32 | mask
| ) |

| Compiles a packet filter without the need of opening an adapter. Converts an high level filtering expression (see Filtering expression syntax ) in a program that can be interpreted by the kernel-level filtering engine. pcap_compile_nopcap() is similar to pcap_compile() except that instead of passing a pcap structure, one passes the snaplen and linktype explicitly. It is intended to be used for compiling filters for direct BPF usage, without necessarily having called pcap_open(). A return of -1 indicates an error; the error text is unavailable. (pcap_compile_nopcap() is a wrapper around pcap_open_dead(), pcap_compile(), and pcap_close(); the latter three routines can be used directly in order to get the error text for a compilation error.) Look at the Filtering expression syntax section for details on the str parameter. See also: pcap_open_live(), pcap_setfilter(), pcap_freecode(), pcap_snapshot() Definition at line 397 of file gencode.c. References pcap_close(), pcap_compile(), pcap_open_dead(), and pcap_t.

void pcap_freecode | ( | struct bpf_program * | fp | ) |

| Frees a filter. pcap_freecode() is used to free up allocated memory pointed to by a bpf_program struct generated by pcap_compile() when that BPF program is no longer needed, for example after it has been made the filter program for a pcap structure by a call to pcap_setfilter(). See also: pcap_compile(), pcap_compile_nopcap() Definition at line 417 of file gencode.c. References bpf_program::bf_insns, and bpf_program::bf_len. Referenced by pcap_close(), and pcap_startcapture_remote().

void syntax | ( | void |  | ) | `[inline, static]`

| Referenced by pcap_compile().

struct slist* xfer_to_a | ( | struct arth * |  | ) | `[static]`

struct slist* xfer_to_x | ( | struct arth * |  | ) | `[static]`

## Variable Documentation

const char rcsid [] _U_`[static]`

| Initial value:
        "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.196 2004/01/14 01:09:03 guy Exp $ (LBL)"
Definition at line 23 of file gencode.c.

struct arth * a0

| Definition at line 4561 of file gencode.c.

struct arth * a1

| Definition at line 4561 of file gencode.c.

bpf_u_int32** alist

| Definition at line 2756 of file gencode.c.

* b1

| Definition at line 492 of file gencode.c.

u_int base_off

| Definition at line 2456 of file gencode.c.

pcap_t* bpf_pcap`[static]`

| Definition at line 95 of file gencode.c. Referenced by bpf_error(), and pcap_compile().

struct chunk chunks[NCHUNKS]`[static]`

| Definition at line 143 of file gencode.c.

int cur_chunk`[static]`

| Definition at line 144 of file gencode.c.

int curreg`[static]`

| Definition at line 4589 of file gencode.c. Referenced by alloc_reg().

register int dir

| Definition at line 5099 of file gencode.c.

u_int dst_off

| Definition at line 1894 of file gencode.c.

idx

| Definition at line 4661 of file gencode.c.

struct arth* index

| Definition at line 4348 of file gencode.c.

int ip_proto

| Definition at line 3149 of file gencode.c.

int is_atm = 0`[static]`

| Definition at line 658 of file gencode.c.

int is_lane = 0`[static]`

| Definition at line 664 of file gencode.c.

bpf_u_int32 jtype

| Definition at line 5180 of file gencode.c.

bpf_u_int32 jvalue

| Definition at line 5179 of file gencode.c.

int linktype`[static]`

| Definition at line 704 of file gencode.c.

bpf_u_int32 mask

| Definition at line 2528 of file gencode.c. Referenced by pcap_compile().

register int masklen

| Definition at line 4086 of file gencode.c.

n

| Definition at line 4624 of file gencode.c.

int no_optimize

| Definition at line 311 of file gencode.c. Referenced by pcap_compile().

u_int off_linktype`[static]`

| Definition at line 653 of file gencode.c.

u_int off_nl`[static]`

| Definition at line 701 of file gencode.c.

u_int off_nl_nosnap`[static]`

| Definition at line 702 of file gencode.c.

u_int off_payload`[static]`

| Definition at line 677 of file gencode.c.

u_int off_proto`[static]`

| Definition at line 671 of file gencode.c.

u_int off_vci`[static]`

| Definition at line 670 of file gencode.c.

u_int off_vpi`[static]`

| Definition at line 669 of file gencode.c.

u_int offset

| Definition at line 1794 of file gencode.c. Referenced by sock_bufferize().

u_int orig_linktype = -1`[static]`

| Definition at line 98 of file gencode.c.

u_int orig_nl = -1`[static]`

| Definition at line 98 of file gencode.c.

u_int orig_nl_nosnap = -1`[static]`

| Definition at line 98 of file gencode.c.

int pcap_fddipad

| Definition at line 104 of file gencode.c. Referenced by pcap_open_offline().

int proto

| Definition at line 3616 of file gencode.c.

bpf_u_int32 ptype

| Definition at line 1793 of file gencode.c.

struct qual q

| Definition at line 5086 of file gencode.c.

int reverse

| Definition at line 5181 of file gencode.c.

int reversed

| Definition at line 4460 of file gencode.c.

struct block* root`[static]`

| Definition at line 128 of file gencode.c. Referenced by pcap_compile().

* s1

| Definition at line 4312 of file gencode.c. Referenced by pcap_strcasecmp().

* s2

| Definition at line 4085 of file gencode.c. Referenced by pcap_strcasecmp().

int size

| Definition at line 4349 of file gencode.c. Referenced by pcap_remoteact_list(), pcap_setuserbuffer(), sock_bufferize(), sock_discard(), sock_recv(), and sock_send().

int snaplen`[static]`

| Definition at line 310 of file gencode.c. Referenced by pcap_compile().

u_int src_off

| Definition at line 1894 of file gencode.c.

void * target

| Definition at line 434 of file gencode.c.

jmp_buf top_ctx`[static]`

| Definition at line 94 of file gencode.c.

bpf_u_int32 v

| Definition at line 4127 of file gencode.c.

val

| Definition at line 4661 of file gencode.c. Referenced by inet_addrU(), and svc_geterr().

documentation. Copyright (c) 2002-2003 Politecnico di Torino. All rights reserved.