21 #include "../misc/bpf_share.h"
22 #include "../misc/pcap_openvas.h"
24 #include <arpa/inet.h>
26 #include <netinet/ip.h>
29 #include <sys/param.h>
31 #include <sys/socket.h>
47 char *
interface = NULL;
49 char errbuf[PCAP_ERRBUF_SIZE];
52 a_src = g_strdup (inet_ntoa (src));
53 a_dst = g_strdup (inet_ntoa (dest));
55 if ((filter == NULL) || (filter[0] ==
'\0') || (filter[0] ==
'0'))
57 filter = g_malloc0 (256);
60 snprintf (filter, 256,
"ip and (src host %s and dst host %s)", a_src,
66 filter = g_strdup (filter);
68 filter = g_malloc0 (1);
76 || (interface = pcap_lookupdev (errbuf)))
99 bzero (&past,
sizeof (past));
100 bzero (&now,
sizeof (now));
101 gettimeofday (&then, &tz);
104 bcopy (&then, &past,
sizeof (then));
105 packet = (
char *)
bpf_next (bpf, &len);
108 gettimeofday (&now, &tz);
110 if (now.tv_usec < past.tv_usec)
113 now.tv_usec += 1000000;
118 if ((now.tv_sec - past.tv_sec) >= timeout)
128 ip = (
struct ip *) (packet + dl_len);
129 #ifdef BSD_BYTE_ORDERING
130 ip->ip_len = ntohs (ip->ip_len);
131 ip->ip_off = ntohs (ip->ip_off);
133 ip->ip_id = ntohs (ip->ip_id);
134 ret = g_malloc0 (len - dl_len);
135 bcopy (ip, ret, len - dl_len);
139 return ((
struct ip *) ret);
146 char *
interface = NULL;
149 char name[INET6_ADDRSTRLEN];
150 char errbuf[PCAP_ERRBUF_SIZE];
152 a_src = g_strdup (inet_ntop (AF_INET6, &src,
name, INET6_ADDRSTRLEN));
153 a_dst = g_strdup (inet_ntop (AF_INET6, &dest,
name, INET6_ADDRSTRLEN));
155 if ((filter == NULL) || (filter[0] ==
'\0') || (filter[0] ==
'0'))
157 filter = g_malloc0 (256);
160 snprintf (filter, 256,
"ip and (src host %s and dst host %s", a_src,
166 filter = g_strdup (filter);
168 filter = g_malloc0 (1);
176 || (interface = pcap_lookupdev (errbuf)))
179 if (free_filter != 0)
192 struct timeval past, now, then;
199 bzero (&past,
sizeof (past));
200 bzero (&now,
sizeof (now));
201 gettimeofday (&then, &tz);
205 bcopy (&then, &past,
sizeof (then));
206 packet = (
char *)
bpf_next (bpf, &len);
211 gettimeofday (&now, &tz);
212 if (now.tv_usec < past.tv_usec)
215 now.tv_usec += 1000000;
220 if ((now.tv_sec - past.tv_sec) >= timeout)
230 ip6 = (
struct ip6_hdr *) (packet + dl_len);
231 #ifdef BSD_BYTE_ORDERING
232 ip6->ip6_plen = ntohs (ip6->ip6_plen);
234 ret = g_malloc0 (len - dl_len);
235 bcopy (ip6, ret, len - dl_len);
240 return ((
struct ip6_hdr *) ret);