Skip to content

Commit

Permalink
Use pcap_findalldevs() instead of deprecated function pcap_lookupdev()
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnoStiefvater authored and ArnoStiefvater committed Nov 12, 2019
1 parent 5a260c2 commit 683be20
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- The logging of the NASL internal regexp functions was extended to include the pattern in case of a failed regcomp(). [#397](https://github.com/greenbone/openvas/pull/397)
- Add config for gpg keyring path (OPENVAS_GPG_BASE_DIR) [#407](https://github.com/greenbone/openvas/pull/407)
- Use __func__ instead of __FUNCTION__ [#419](https://github.com/greenbone/openvas/pull/419)
- Use pcap_findalldevs() instead of deprecated function pcap_lookupdev() [#422](https://github.com/greenbone/openvas/pull/422)

[Unreleased]: https://github.com/greenbone/openvas/compare/openvas-7.0...master

Expand Down
10 changes: 9 additions & 1 deletion misc/bpf_share.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ bpf_open_live (char *iface, char *filter)
{
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t *ret;
pcap_if_t **alldevsp = NULL; /* list of capture devices */
bpf_u_int32 netmask, network;
struct bpf_program filter_prog;
int i;
Expand All @@ -67,7 +68,14 @@ bpf_open_live (char *iface, char *filter)
}

if (iface == NULL)
iface = pcap_lookupdev (errbuf);
{
if (pcap_findalldevs (alldevsp, errbuf) == -1)
g_message ("Error for pcap_findalldevs(): %s", errbuf);
if (alldevsp != NULL)
/* get first device in list */
iface = g_strdup ((*alldevsp)->name);
pcap_freealldevs (*alldevsp);
}

ret = pcap_open_live (iface, 1500, 0, 1, errbuf);
if (ret == NULL)
Expand Down
36 changes: 30 additions & 6 deletions nasl/capture_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ init_capture_device (struct in_addr src, struct in_addr dest, char *filter)
char *a_dst, *a_src;
char errbuf[PCAP_ERRBUF_SIZE];
int free_filter = 0;
pcap_if_t **alldevsp = NULL; /* list of capture devices */

a_src = g_strdup (inet_ntoa (src));
a_dst = g_strdup (inet_ntoa (dest));
Expand All @@ -72,9 +73,20 @@ init_capture_device (struct in_addr src, struct in_addr dest, char *filter)
g_free (a_dst);
g_free (a_src);

if ((interface = routethrough (&src, &dest))
|| (interface = pcap_lookupdev (errbuf)))
ret = bpf_open_live (interface, filter);
if ((interface = routethrough (&src, &dest)))
{
ret = bpf_open_live (interface, filter);
}
else
{
if (pcap_findalldevs (alldevsp, errbuf) == -1)
g_message ("Error for pcap_findalldevs(): %s", errbuf);
if (alldevsp != NULL)
/* get first device in list */
interface = g_strdup ((*alldevsp)->name);
pcap_freealldevs (*alldevsp);
ret = bpf_open_live (interface, filter);
}

if (free_filter != 0)
g_free (filter);
Expand Down Expand Up @@ -148,6 +160,7 @@ init_v6_capture_device (struct in6_addr src, struct in6_addr dest, char *filter)
int free_filter = 0;
char name[INET6_ADDRSTRLEN];
char errbuf[PCAP_ERRBUF_SIZE];
pcap_if_t **alldevsp = NULL; /* list of capture devices */

a_src = g_strdup (inet_ntop (AF_INET6, &src, name, INET6_ADDRSTRLEN));
a_dst = g_strdup (inet_ntop (AF_INET6, &dest, name, INET6_ADDRSTRLEN));
Expand All @@ -172,9 +185,20 @@ init_v6_capture_device (struct in6_addr src, struct in6_addr dest, char *filter)
g_free (a_dst);
g_free (a_src);

if ((interface = v6_routethrough (&src, &dest))
|| (interface = pcap_lookupdev (errbuf)))
ret = bpf_open_live (interface, filter);
if ((interface = v6_routethrough (&src, &dest)))
{
ret = bpf_open_live (interface, filter);
}
else
{
if (pcap_findalldevs (alldevsp, errbuf) == -1)
g_message ("Error for pcap_findalldevs(): %s", errbuf);
if (alldevsp != NULL)
/* get first device in list */
interface = g_strdup ((*alldevsp)->name);
pcap_freealldevs (*alldevsp);
ret = bpf_open_live (interface, filter);
}

if (free_filter != 0)
g_free (filter);
Expand Down
20 changes: 18 additions & 2 deletions nasl/nasl_packet_forgery.c
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,7 @@ nasl_pcap_next (lex_ctxt *lexic)
struct ip *ret = NULL;
struct ip6_hdr *ret6 = NULL;
char *filter = get_str_var_by_name (lexic, "pcap_filter");
pcap_if_t **alldevsp = NULL; /* list of capture devices */
int timeout = get_int_var_by_name (lexic, "timeout", 5);
tree_cell *retc;
int sz;
Expand Down Expand Up @@ -1536,7 +1537,14 @@ nasl_pcap_next (lex_ctxt *lexic)
interface = v6_routethrough (dst, &src);
}
if (interface == NULL)
interface = pcap_lookupdev (errbuf);
{
if (pcap_findalldevs (alldevsp, errbuf) == -1)
g_message ("Error for pcap_findalldevs(): %s", errbuf);
if (alldevsp != NULL)
/* get first device in list */
interface = g_strdup ((*alldevsp)->name);
pcap_freealldevs (*alldevsp);
}
}

if (interface != NULL)
Expand Down Expand Up @@ -1640,6 +1648,7 @@ nasl_send_capture (lex_ctxt *lexic)
struct ip *ret = NULL;
struct ip6_hdr *ret6 = NULL;
char *filter = get_str_var_by_name (lexic, "pcap_filter");
pcap_if_t **alldevsp = NULL; /* list of capture devices */
int timeout = get_int_var_by_name (lexic, "timeout", 5);
tree_cell *retc;
int sz;
Expand All @@ -1666,7 +1675,14 @@ nasl_send_capture (lex_ctxt *lexic)
interface = v6_routethrough (dst, &src);
}
if (interface == NULL)
interface = pcap_lookupdev (errbuf);
{
if (pcap_findalldevs (alldevsp, errbuf) == -1)
g_message ("Error for pcap_findalldevs(): %s", errbuf);
if (alldevsp != NULL)
/* get first device in list */
interface = g_strdup ((*alldevsp)->name);
pcap_freealldevs (*alldevsp);
}
}

if (interface != NULL)
Expand Down

0 comments on commit 683be20

Please sign in to comment.