#include <netinet/in.h>
#include <netinet/ip6.h>
Go to the source code of this file.
◆ capture_next_packet()
struct ip* capture_next_packet |
( |
int |
, |
|
|
int |
, |
|
|
int * |
|
|
) |
| |
Definition at line 86 of file capture_packet.c.
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);
References bpf_datalink(), bpf_next(), get_datalink_size(), and timeval().
Referenced by nasl_send_packet().
◆ capture_next_v6_packet()
struct ip6_hdr* capture_next_v6_packet |
( |
int |
, |
|
|
int |
, |
|
|
int * |
|
|
) |
| |
Definition at line 186 of file capture_packet.c.
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);
References bpf_datalink(), bpf_next(), get_datalink_size(), and timeval().
Referenced by nasl_send_v6packet().
◆ 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.
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)))
References bpf_open_live(), islocalhost(), and routethrough().
Referenced by nasl_send_packet(), and nasl_tcp_ping().
◆ init_v6_capture_device()
int init_v6_capture_device |
( |
struct in6_addr |
, |
|
|
struct in6_addr |
, |
|
|
char * |
|
|
) |
| |
Definition at line 143 of file capture_packet.c.
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)
References bpf_open_live(), name, v6_islocalhost(), and v6_routethrough().
Referenced by nasl_send_v6packet(), and nasl_tcp_v6_ping().