#include "capture_packet.h"
#include "../misc/bpf_share.h"
#include "../misc/pcap_openvas.h"
#include <arpa/inet.h>
#include <glib.h>
#include <netinet/ip.h>
#include <pcap.h>
#include <string.h>
#include <sys/param.h>
Go to the source code of this file.
◆ capture_next_packet()
struct ip* capture_next_packet |
( |
int |
bpf, |
|
|
int |
timeout, |
|
|
int * |
sz |
|
) |
| |
Definition at line 86 of file capture_packet.c.
References bpf_datalink(), bpf_next(), get_datalink_size(), and timeval().
Referenced by nasl_send_packet().
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;
int get_datalink_size(int datalink)
int bpf_datalink(int bpf)
struct timeval timeval(unsigned long val)
u_char * bpf_next(int bpf, int *caplen)
◆ capture_next_v6_packet()
struct ip6_hdr* capture_next_v6_packet |
( |
int |
bpf, |
|
|
int |
timeout, |
|
|
int * |
sz |
|
) |
| |
Definition at line 186 of file capture_packet.c.
References bpf_datalink(), bpf_next(), get_datalink_size(), and timeval().
Referenced by nasl_send_v6packet().
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 get_datalink_size(int datalink)
int bpf_datalink(int bpf)
struct timeval timeval(unsigned long val)
u_char * bpf_next(int bpf, int *caplen)
◆ init_capture_device()
int init_capture_device |
( |
struct in_addr |
src, |
|
|
struct in_addr |
dest, |
|
|
char * |
filter |
|
) |
| |
Set up the pcap filter, and select the correct interface.
The filter will be changed only if this is necessary
Definition at line 44 of file capture_packet.c.
References bpf_open_live(), islocalhost(), and routethrough().
Referenced by nasl_send_packet(), and nasl_tcp_ping().
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)))
int islocalhost(struct in_addr *)
Tests whether a packet sent to IP is LIKELY to route through the kernel localhost interface...
int bpf_open_live(char *iface, char *filter)
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...
◆ init_v6_capture_device()
int init_v6_capture_device |
( |
struct in6_addr |
src, |
|
|
struct in6_addr |
dest, |
|
|
char * |
filter |
|
) |
| |
Definition at line 143 of file capture_packet.c.
References bpf_open_live(), name, v6_islocalhost(), and v6_routethrough().
Referenced by nasl_send_v6packet(), and nasl_tcp_v6_ping().
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)
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 bpf_open_live(char *iface, char *filter)
◆ islocalhost()
int islocalhost |
( |
struct in_addr * |
| ) |
|