OpenVAS Libraries  9.0.3
bpf_share.h File Reference
#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)
 

Function Documentation

◆ bpf_close()

void bpf_close ( int  )

Definition at line 153 of file bpf_share.c.

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

154 {
155  pcap_close (pcaps[bpf]);
156  pcaps[bpf] = NULL;
157 }
Here is the caller graph for this function:

◆ bpf_datalink()

int bpf_datalink ( int  )

Definition at line 146 of file bpf_share.c.

Referenced by capture_next_packet(), capture_next_v6_packet(), ids_open_sock_tcp(), ids_send(), nasl_pcap_next(), nasl_send_capture(), scan(), and v6_get_mac_addr().

147 {
148  return pcap_datalink (pcaps[bpf]);
149 }
Here is the caller graph for this function:

◆ bpf_next()

u_char* bpf_next ( int  ,
int *   
)

Definition at line 137 of file bpf_share.c.

References bpf_next_tv(), and timeval().

Referenced by capture_next_packet(), capture_next_v6_packet(), ids_open_sock_tcp(), ids_send(), nasl_pcap_next(), nasl_send_capture(), v6_get_mac_addr(), and v6_sendpacket().

138 {
139  struct timeval tv = { 0, 100000 };
140 
141  return bpf_next_tv (bpf, caplen, &tv);
142 }
struct timeval timeval(unsigned long val)
u_char * bpf_next_tv(int bpf, int *caplen, struct timeval *tv)
Definition: bpf_share.c:104
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 104 of file bpf_share.c.

References timeval().

Referenced by bpf_next(), and sendpacket().

105 {
106  u_char *p = NULL;
107  struct pcap_pkthdr head;
108  struct timeval timeout, now;
109 
110  gettimeofday (&timeout, NULL);
111  timeout.tv_sec += tv->tv_sec;
112  timeout.tv_usec += tv->tv_usec;
113  while (timeout.tv_usec >= 1000000)
114  {
115  timeout.tv_sec++;
116  timeout.tv_usec -= 1000000;
117  }
118 
119  do
120  {
121  p = (u_char *) pcap_next (pcaps[bpf], &head);
122  *caplen = head.caplen;
123  if (p != NULL)
124  break;
125  gettimeofday (&now, NULL);
126  }
127  while (!
128  ((now.tv_sec > timeout.tv_sec)
129  || (now.tv_sec == timeout.tv_sec && now.tv_usec >= timeout.tv_usec)));
130 
131 
132  return p;
133 }
struct timeval timeval(unsigned long val)
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 40 of file bpf_share.c.

References NUM_CLIENTS.

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

41 {
42  char errbuf[PCAP_ERRBUF_SIZE];
43  pcap_t *ret;
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  log_legacy_write ("no free pcap");
54  return -1;
55  }
56 
57 
58  if (iface == NULL)
59  iface = pcap_lookupdev (errbuf);
60 
61  ret = pcap_open_live (iface, 1500, 0, 1, errbuf);
62  if (ret == NULL)
63  {
64  log_legacy_write ("%s", errbuf);
65  return -1;
66  }
67 
68  if (pcap_lookupnet (iface, &network, &netmask, 0) < 0)
69  {
70  log_legacy_write ("pcap_lookupnet failed");
71  pcap_close (ret);
72  return -1;
73  }
74 
75  if (pcap_compile (ret, &filter_prog, filter, 1, netmask) < 0)
76  {
77  pcap_perror (ret, "pcap_compile");
78  pcap_close (ret);
79  return -1;
80  }
81 
82  if (pcap_setnonblock (ret, 1, NULL) == -1)
83  {
84  pcap_perror (ret, "pcap_setnonblock");
86  ("call to pcap_setnonblock failed, some plugins/scripts will"
87  " hang/freeze. Upgrade your version of libcap!");
88  }
89 
90  if (pcap_setfilter (ret, &filter_prog) < 0)
91  {
92  pcap_perror (ret, "pcap_setfilter\n");
93  pcap_close (ret);
94  return -1;
95  }
96  pcaps[i] = ret;
97  pcap_freecode (&filter_prog);
98  return i;
99 }
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
#define NUM_CLIENTS
Definition: bpf_share.c:30
Here is the caller graph for this function: