OpenVAS Scanner 23.40.3
bpf_share.h File Reference

Header file for module bpf_share. More...

#include <sys/types.h>
Include dependency graph for bpf_share.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int bpf_open_live (char *, char *)
u_char * bpf_next (int, int *)
u_char * bpf_next_tv (int, int *, struct timeval *)
void bpf_close (int)
int bpf_datalink (int)

Detailed Description

Header file for module bpf_share.

Definition in file bpf_share.h.

Function Documentation

◆ bpf_close()

void bpf_close ( int bpf)

Definition at line 164 of file bpf_share.c.

165{
166 pcap_close (pcaps[bpf]);
167 pcaps[bpf] = NULL;
168}
static pcap_t * pcaps[NUM_CLIENTS]
Definition bpf_share.c:23

References pcaps.

Referenced by nasl_pcap_next(), nasl_send_capture(), nasl_send_packet(), nasl_send_v6packet(), nasl_tcp_ping(), nasl_tcp_v6_ping(), scan(), send_frame(), sendpacket(), and v6_sendpacket().

Here is the caller graph for this function:

◆ bpf_datalink()

int bpf_datalink ( int bpf)

Definition at line 158 of file bpf_share.c.

159{
160 return pcap_datalink (pcaps[bpf]);
161}

References pcaps.

Referenced by capture_next_frame(), capture_next_packet(), capture_next_v6_packet(), nasl_pcap_next(), nasl_send_capture(), and scan().

Here is the caller graph for this function:

◆ bpf_next()

u_char * bpf_next ( int bpf,
int * caplen )

Definition at line 150 of file bpf_share.c.

151{
152 struct timeval tv = {0, 100000};
153
154 return bpf_next_tv (bpf, caplen, &tv);
155}
u_char * bpf_next_tv(int bpf, int *caplen, struct timeval *tv)
Definition bpf_share.c:119
static struct timeval timeval(unsigned long val)

References bpf_next_tv(), and timeval().

Referenced by capture_next_frame(), capture_next_packet(), capture_next_v6_packet(), nasl_pcap_next(), nasl_send_capture(), and v6_sendpacket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bpf_next_tv()

u_char * bpf_next_tv ( int bpf,
int * caplen,
struct timeval * tv )

Definition at line 119 of file bpf_share.c.

120{
121 u_char *p = NULL;
122 struct pcap_pkthdr head;
123 struct timeval timeout, now;
124
125 gettimeofday (&timeout, NULL);
126 timeout.tv_sec += tv->tv_sec;
127 timeout.tv_usec += tv->tv_usec;
128 while (timeout.tv_usec >= 1000000)
129 {
130 timeout.tv_sec++;
131 timeout.tv_usec -= 1000000;
132 }
133
134 do
135 {
136 p = (u_char *) pcap_next (pcaps[bpf], &head);
137 *caplen = head.caplen;
138 if (p != NULL)
139 break;
140 gettimeofday (&now, NULL);
141 }
142 while (
143 !((now.tv_sec > timeout.tv_sec)
144 || (now.tv_sec == timeout.tv_sec && now.tv_usec >= timeout.tv_usec)));
145
146 return p;
147}

References pcaps, and timeval().

Referenced by bpf_next(), nasl_tcp_ping(), nasl_tcp_v6_ping(), and sendpacket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bpf_open_live()

int bpf_open_live ( char * iface,
char * filter )
Returns
-1 in case of error, index of the opened pcap_t in pcaps otherwise.

Definition at line 39 of file bpf_share.c.

40{
41 char errbuf[PCAP_ERRBUF_SIZE];
42 pcap_t *ret;
43 pcap_if_t *alldevsp = NULL; /* list of capture devices */
44 bpf_u_int32 netmask, network;
45 struct bpf_program filter_prog;
46 int i;
47
48 for (i = 0; (i < (NUM_CLIENTS - 1)) && (pcaps[i]); i++)
49 ;
50
51 if (pcaps[i])
52 {
53 g_message ("no free pcap");
54 return -1;
55 }
56
57 if (iface == NULL)
58 {
59 if (pcap_findalldevs (&alldevsp, errbuf) < 0)
60 g_message ("Error for pcap_findalldevs(): %s", errbuf);
61 if (alldevsp != NULL)
62 iface = alldevsp->name;
63 }
64
65 ret = pcap_open_live (iface, 1500, 0, 1, errbuf);
66 if (ret == NULL)
67 {
68 g_message ("%s", errbuf);
69 if (alldevsp != NULL)
70 pcap_freealldevs (alldevsp);
71 return -1;
72 }
73
74 if (pcap_lookupnet (iface, &network, &netmask, errbuf) < 0)
75 {
76 g_message ("pcap_lookupnet failed: %s", errbuf);
77 if (alldevsp != NULL)
78 pcap_freealldevs (alldevsp);
79 pcap_close (ret);
80 return -1;
81 }
82
83 if (pcap_compile (ret, &filter_prog, filter, 1, netmask) < 0)
84 {
85 char buffer[2048];
86 snprintf (buffer, sizeof (buffer), "pcap_compile: Filter \"%s\"", filter);
87 print_pcap_error (ret, buffer);
88 if (alldevsp != NULL)
89 pcap_freealldevs (alldevsp);
90 pcap_close (ret);
91 return -1;
92 }
93
94 if (pcap_setnonblock (ret, 1, NULL) == -1)
95 {
96 print_pcap_error (ret, "pcap_setnonblock");
97 g_message ("call to pcap_setnonblock failed, some plugins/scripts will"
98 " hang/freeze. Upgrade your version of libcap!");
99 }
100
101 if (pcap_setfilter (ret, &filter_prog) < 0)
102 {
103 print_pcap_error (ret, "pcap_setfilter\n");
104 if (alldevsp != NULL)
105 pcap_freealldevs (alldevsp);
106 pcap_freecode (&filter_prog);
107 pcap_close (ret);
108 return -1;
109 }
110 pcaps[i] = ret;
111 pcap_freecode (&filter_prog);
112 if (alldevsp != NULL)
113 pcap_freealldevs (alldevsp);
114
115 return i;
116}
#define NUM_CLIENTS
Definition bpf_share.c:14
static void print_pcap_error(pcap_t *p, char *prefix)
Definition bpf_share.c:26

References NUM_CLIENTS, pcaps, and print_pcap_error().

Referenced by init_capture_device(), init_v6_capture_device(), nasl_pcap_next(), nasl_send_capture(), openbpf(), and v6_openbpf().

Here is the call graph for this function:
Here is the caller graph for this function: