OpenVAS Scanner  7.0.0~git
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  )

Definition at line 157 of file bpf_share.c.

158 {
159  pcap_close (pcaps[bpf]);
160  pcaps[bpf] = NULL;
161 }

References pcaps.

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

Here is the caller graph for this function:

◆ bpf_datalink()

int bpf_datalink ( int  )

Definition at line 151 of file bpf_share.c.

152 {
153  return pcap_datalink (pcaps[bpf]);
154 }

References pcaps.

Referenced by 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  ,
int *   
)

Definition at line 143 of file bpf_share.c.

144 {
145  struct timeval tv = {0, 100000};
146 
147  return bpf_next_tv (bpf, caplen, &tv);
148 }

References bpf_next_tv(), and timeval().

Referenced by 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  ,
int *  ,
struct timeval  
)

Definition at line 112 of file bpf_share.c.

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

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 52 of file bpf_share.c.

53 {
54  char errbuf[PCAP_ERRBUF_SIZE];
55  pcap_t *ret;
56  bpf_u_int32 netmask, network;
57  struct bpf_program filter_prog;
58  int i;
59 
60  for (i = 0; (i < (NUM_CLIENTS - 1)) && (pcaps[i]); i++)
61  ;
62 
63  if (pcaps[i])
64  {
65  g_message ("no free pcap");
66  return -1;
67  }
68 
69  if (iface == NULL)
70  iface = pcap_lookupdev (errbuf);
71 
72  ret = pcap_open_live (iface, 1500, 0, 1, errbuf);
73  if (ret == NULL)
74  {
75  g_message ("%s", errbuf);
76  return -1;
77  }
78 
79  if (pcap_lookupnet (iface, &network, &netmask, 0) < 0)
80  {
81  g_message ("pcap_lookupnet failed");
82  pcap_close (ret);
83  return -1;
84  }
85 
86  if (pcap_compile (ret, &filter_prog, filter, 1, netmask) < 0)
87  {
88  print_pcap_error (ret, "pcap_compile");
89  pcap_close (ret);
90  return -1;
91  }
92 
93  if (pcap_setnonblock (ret, 1, NULL) == -1)
94  {
95  print_pcap_error (ret, "pcap_setnonblock");
96  g_message ("call to pcap_setnonblock failed, some plugins/scripts will"
97  " hang/freeze. Upgrade your version of libcap!");
98  }
99 
100  if (pcap_setfilter (ret, &filter_prog) < 0)
101  {
102  print_pcap_error (ret, "pcap_setfilter\n");
103  pcap_close (ret);
104  return -1;
105  }
106  pcaps[i] = ret;
107  pcap_freecode (&filter_prog);
108  return i;
109 }

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:
pcaps
static pcap_t * pcaps[NUM_CLIENTS]
Definition: bpf_share.c:38
timeval
struct timeval timeval(unsigned long val)
Definition: nasl_builtin_synscan.c:105
bpf_next_tv
u_char * bpf_next_tv(int bpf, int *caplen, struct timeval *tv)
Definition: bpf_share.c:112
print_pcap_error
void print_pcap_error(pcap_t *p, char *prefix)
Definition: bpf_share.c:41
NUM_CLIENTS
#define NUM_CLIENTS
Definition: bpf_share.c:29