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;
int islocalhost(struct in_addr *)
Tests whether a packet sent to IP is LIKELY to route through the kernel localhost interface...
int v6_islocalhost(struct in6_addr *addr)
Tests whether a packet sent to IP is LIKELY to route through the kernel localhost interface...
char * v6_routethrough(struct in6_addr *dest, struct in6_addr *source)
An awesome function to determine what interface a packet to a given destination should be routed thro...
int init_v6_capture_device(struct in6_addr src, struct in6_addr dest, char *filter)
int init_capture_device(struct in_addr src, struct in_addr dest, char *filter)
Set up the pcap filter, and select the correct interface.
int get_datalink_size(int datalink)
int bpf_datalink(int bpf)
int bpf_open_live(char *iface, char *filter)
struct ip * capture_next_packet(int bpf, int timeout, int *sz)
struct timeval timeval(unsigned long val)
char * routethrough(struct in_addr *dest, struct in_addr *source)
An awesome function to determine what interface a packet to a given destination should be routed thro...
u_char * bpf_next(int bpf, int *caplen)
struct ip6_hdr * capture_next_v6_packet(int bpf, int timeout, int *sz)