OpenVAS Scanner  21.4.1
Data Structures | Macros | Functions
pcap.c File Reference
#include "bpf_share.h"
#include "network.h"
#include "pcap_openvas.h"
#include "support.h"
#include <arpa/inet.h>
#include <gvm/base/logging.h>
#include <gvm/base/networking.h>
#include <ifaddrs.h>
#include <net/if.h>
#include <netdb.h>
#include <netinet/in.h>
#include <pcap.h>
#include <resolv.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/param.h>
#include <sys/types.h>
#include <unistd.h>

Data Structures

struct  interface_info
 
struct  myroute
 

Macros

#define MAXROUTES   1024
 
#define G_LOG_DOMAIN   "lib misc"
 GLib logging domain. More...
 
#define MAX_IFACE_NAME_LEN   64
 Maximum length of an interface's name. More...
 

Functions

struct interface_infogetinterfaces (int *howmany)
 
struct interface_infov6_getinterfaces (int *howmany)
 
int getipv6routes (struct myroute *myroutes, int *numroutes)
 Get the IPv6 routes and number of routes. More...
 
int ipv6_prefix_to_mask (unsigned prefix, struct in6_addr *mask)
 Generate an ipv6 mask from the given ipv6 prefix. More...
 
int v6_is_local_ip (struct in6_addr *addr)
 
int v6_ipaddr2devname (char *dev, int sz, struct in6_addr *addr)
 
int ipaddr2devname (char *dev, int sz, struct in_addr *addr)
 
int v6_islocalhost (struct in6_addr *addr)
 Tests whether a packet sent to IP is LIKELY to route through the kernel localhost interface. More...
 
int islocalhost (struct in_addr *addr)
 Tests whether a packet sent to IP is LIKELY to route through the kernel localhost interface. More...
 
int get_datalink_size (int datalink)
 
int v6_getsourceip (struct in6_addr *src, struct in6_addr *dst)
 
int getipv4routes (struct myroute *myroutes, int *numroutes)
 Get the ipv4 routes and number of routes. More...
 
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 through. More...
 
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 through. More...
 

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "lib misc"

GLib logging domain.

◆ MAX_IFACE_NAME_LEN

#define MAX_IFACE_NAME_LEN   64

Maximum length of an interface's name.

◆ MAXROUTES

#define MAXROUTES   1024

Function Documentation

◆ get_datalink_size()

int get_datalink_size ( int  datalink)

◆ getinterfaces()

struct interface_info * getinterfaces ( int *  howmany)
Parameters
[out]howmanyReturn location for the number of interfaces found (might be NULL).

◆ getipv4routes()

int getipv4routes ( struct myroute myroutes,
int *  numroutes 
)

Get the ipv4 routes and number of routes.

This function is only used for getting the ipv4 routes in v6_routethrough(). routethrough() overwrites the global myroutes struct with a local version and uses its own logic for getting the routes from /proc/net/route.

Parameters
[out]myroutesArray of routes.
[out]numroutesNumber of routes in myroutes.
Returns
0 on success, -1 on error.

◆ getipv6routes()

int getipv6routes ( struct myroute myroutes,
int *  numroutes 
)

Get the IPv6 routes and number of routes.

This function parses the /proc/net/ipv6_route file into an array of myroute structs.

Parameters
[out]myroutesArray of routes.
[out]numroutesNumber of routes in myroutes.
Returns
0 on success, -1 when no routes are found.

◆ ipaddr2devname()

int ipaddr2devname ( char *  dev,
int  sz,
struct in_addr *  addr 
)

◆ ipv6_prefix_to_mask()

int ipv6_prefix_to_mask ( unsigned  prefix,
struct in6_addr *  mask 
)

Generate an ipv6 mask from the given ipv6 prefix.

This function is a copy of the function ipv6_prefix_to_mask() obtained from GPL-2.0 licensed https://gitlab.com/ipcalc/ipcalc/-/blob/master/ipcalc.c.

Parameters
[in]prefixThe ipv6 prefix.
[out]maskThe mask corresponding to the prefix.
Returns
0 on success, -1 on error.

◆ islocalhost()

int islocalhost ( struct in_addr *  addr)

Tests whether a packet sent to IP is LIKELY to route through the kernel localhost interface.

◆ routethrough()

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 through.

It returns NULL if no appropriate interface is found, otherwise it returns the device name and fills in the source parameter. Some of the stuff is from Stevens' Unix Network Programming V2. He had an easier suggestion for doing this (in the book), but it isn't portable :(

◆ v6_getinterfaces()

struct interface_info * v6_getinterfaces ( int *  howmany)

◆ v6_getsourceip()

int v6_getsourceip ( struct in6_addr *  src,
struct in6_addr *  dst 
)

◆ v6_ipaddr2devname()

int v6_ipaddr2devname ( char *  dev,
int  sz,
struct in6_addr *  addr 
)

◆ v6_is_local_ip()

int v6_is_local_ip ( struct in6_addr *  addr)

◆ v6_islocalhost()

int v6_islocalhost ( struct in6_addr *  addr)

Tests whether a packet sent to IP is LIKELY to route through the kernel localhost interface.

◆ v6_routethrough()

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 through.

It returns NULL if no appropriate interface is found, otherwise it returns the device name and fills in the source parameter. Some of the stuff is from Stevens' Unix Network Programming V2. He had an easier suggestion for doing this (in the book), but it isn't portable :(