#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 85 of file capture_packet.c.
98 bzero (&past,
sizeof (past));
99 bzero (&now,
sizeof (now));
100 gettimeofday (&then, &tz);
103 bcopy (&then, &past,
sizeof (then));
104 packet = (
char *)
bpf_next (bpf, &len);
107 gettimeofday (&now, &tz);
109 if (now.tv_usec < past.tv_usec)
112 now.tv_usec += 1000000;
117 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)
References bpf_datalink(), bpf_next(), get_datalink_size(), and timeval().
◆ capture_next_v6_packet()
struct ip6_hdr* capture_next_v6_packet |
( |
int |
, |
|
|
int |
, |
|
|
int * |
|
|
) |
| |
Definition at line 188 of file capture_packet.c.
194 struct timeval past, now, then;
201 bzero (&past,
sizeof (past));
202 bzero (&now,
sizeof (now));
203 gettimeofday (&then, &tz);
207 bcopy (&then, &past,
sizeof (then));
208 packet = (
char *)
bpf_next (bpf, &len);
213 gettimeofday (&now, &tz);
214 if (now.tv_usec < past.tv_usec)
217 now.tv_usec += 1000000;
222 if ((now.tv_sec - past.tv_sec) >= timeout)
232 ip6 = (
struct ip6_hdr *) (packet + dl_len);
233 #ifdef BSD_BYTE_ORDERING 234 ip6->ip6_plen = ntohs (ip6->ip6_plen);
236 ret = g_malloc0 (len - dl_len);
237 bcopy (ip6, ret, len - dl_len);
242 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)
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 |
dst, |
|
|
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 41 of file capture_packet.c.
44 char *
interface = NULL;
46 char errbuf[PCAP_ERRBUF_SIZE];
49 a_src = g_strdup (inet_ntoa (src));
50 a_dst = g_strdup (inet_ntoa (dst));
52 if ((filter == NULL) || (filter[0] ==
'\0') || (filter[0] ==
'0'))
54 filter = g_malloc0 (256);
57 snprintf (filter, 256,
"ip and (src host %s and dst host %s)",
64 filter = g_strdup (filter);
66 filter = g_malloc0 (1);
74 || (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...
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 144 of file capture_packet.c.
147 char *
interface = NULL;
150 char name[INET6_ADDRSTRLEN];
151 char errbuf[PCAP_ERRBUF_SIZE];
153 a_src = g_strdup (inet_ntop (AF_INET6, &src,
name, INET6_ADDRSTRLEN));
154 a_dst = g_strdup (inet_ntop (AF_INET6, &dst,
name, INET6_ADDRSTRLEN));
156 if ((filter == NULL) || (filter[0] ==
'\0') || (filter[0] ==
'0'))
158 filter = g_malloc0 (256);
161 snprintf (filter, 256,
"ip and (src host %s and dst host %s", a_src,
167 filter = g_strdup (filter);
169 filter = g_malloc0 (1);
177 || (interface = pcap_lookupdev (errbuf)))
180 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)
References bpf_open_live(), name, v6_islocalhost(), and v6_routethrough().
Referenced by nasl_send_v6packet(), and nasl_tcp_v6_ping().