OpenVAS Libraries  9.0.1
Functions | Variables
openvas_networking.c File Reference
#include "openvas_networking.h"
#include <fcntl.h>
#include <unistd.h>
#include <glib/gstdio.h>

Functions

int openvas_source_iface_init (const char *iface)
 Initializes the source network interface name and related information. More...
 
int openvas_source_iface_is_set (void)
 
int openvas_source_set_socket (int socket, int port, int family)
 Binds a socket to use the global source address. More...
 
void openvas_source_addr (void *addr)
 Gives the source IPv4 address. More...
 
void openvas_source_addr6 (void *addr6)
 Gives the source IPv6 address. More...
 
void openvas_source_addr_as_addr6 (struct in6_addr *addr6)
 Gives the source IPv4 mapped as an IPv6 address. eg. 192.168.20.10 would map to ::ffff:192.168.20.10. More...
 
char * openvas_source_addr_str (void)
 Gives the source IPv4 address in string format. More...
 
char * openvas_source_addr6_str (void)
 Gives the source IPv6 address in string format. More...
 
void ipv4_as_ipv6 (const struct in_addr *ip4, struct in6_addr *ip6)
 Maps an IPv4 address as an IPv6 address. eg. 192.168.10.20 would map to ::ffff:192.168.10.20. More...
 
char * addr6_as_str (const struct in6_addr *addr6)
 
void sockaddr_as_str (const struct sockaddr_storage *addr, char *str)
 Convert an IP address to string format. More...
 
int openvas_resolve (const char *name, void *dst, int family)
 Resolves a hostname to an IPv4 or IPv6 address. More...
 
int openvas_resolve_as_addr6 (const char *name, struct in6_addr *ip6)
 Resolves a hostname to an IPv4-mapped IPv6 or IPv6 address. More...
 
int validate_port_range (const char *port_range)
 Validate a port range string. More...
 
array_tport_range_ranges (const char *port_range)
 Create a range array from a port_range string. More...
 
int port_in_port_ranges (int pnum, port_protocol_t ptype, array_t *pranges)
 Checks if a port num is in port ranges array. More...
 
int ipv6_is_enabled ()
 Checks if IPv6 support is enabled. More...
 

Variables

char global_source_iface [IFNAMSIZ] = { '\0' }
 
struct in_addr global_source_addr = { .s_addr = 0 }
 
struct in6_addr global_source_addr6 = { .s6_addr32 = { 0, 0, 0, 0 } }
 

Function Documentation

◆ addr6_as_str()

char* addr6_as_str ( const struct in6_addr *  addr6)

◆ ipv4_as_ipv6()

void ipv4_as_ipv6 ( const struct in_addr *  ip4,
struct in6_addr *  ip6 
)

Maps an IPv4 address as an IPv6 address. eg. 192.168.10.20 would map to ::ffff:192.168.10.20.

Parameters
[in]ip4IPv4 address to map.
[out]ip6Buffer to store the IPv6 address.

◆ ipv6_is_enabled()

int ipv6_is_enabled ( )

Checks if IPv6 support is enabled.

Returns
1 if IPv6 is enabled, 0 if disabled.

◆ openvas_resolve()

int openvas_resolve ( const char *  name,
void *  dst,
int  family 
)

Resolves a hostname to an IPv4 or IPv6 address.

Parameters
[in]nameHostname to resolve.
[out]dstBuffer to store resolved address. Size must be at least 4 bytes for AF_INET and 16 bytes for AF_INET6.
[in]familyEither AF_INET or AF_INET6.
Returns
-1 if error, 0 otherwise.

◆ openvas_resolve_as_addr6()

int openvas_resolve_as_addr6 ( const char *  name,
struct in6_addr *  ip6 
)

Resolves a hostname to an IPv4-mapped IPv6 or IPv6 address.

Parameters
[in]nameHostname to resolve.
[out]ip6Buffer to store resolved address.
Returns
-1 if error, 0 otherwise.

◆ openvas_source_addr()

void openvas_source_addr ( void *  addr)

Gives the source IPv4 address.

Parameters
[out]addrBuffer of at least 4 bytes.

◆ openvas_source_addr6()

void openvas_source_addr6 ( void *  addr6)

Gives the source IPv6 address.

Parameters
[out]addr6Buffer of at least 16 bytes.

◆ openvas_source_addr6_str()

char* openvas_source_addr6_str ( void  )

Gives the source IPv6 address in string format.

Returns
Source IPv6 string. Free with g_free().

◆ openvas_source_addr_as_addr6()

void openvas_source_addr_as_addr6 ( struct in6_addr *  addr6)

Gives the source IPv4 mapped as an IPv6 address. eg. 192.168.20.10 would map to ::ffff:192.168.20.10.

Parameters
[out]addr6Buffer of at least 16 bytes.

◆ openvas_source_addr_str()

char* openvas_source_addr_str ( void  )

Gives the source IPv4 address in string format.

Returns
Source IPv4 string. Free with g_free().

◆ openvas_source_iface_init()

int openvas_source_iface_init ( const char *  iface)

Initializes the source network interface name and related information.

Parameters
[in]ifaceName of network interface to use as source interface.
Returns
0 if success. If error, return 1 and reset source values to default.

◆ openvas_source_iface_is_set()

int openvas_source_iface_is_set ( void  )

◆ openvas_source_set_socket()

int openvas_source_set_socket ( int  socket,
int  port,
int  family 
)

Binds a socket to use the global source address.

Parameters
[in]socketSocket to set source address for.
[in]portNetwork port for socket.
[in]familyFamily of socket. AF_INET or AF_INET6.
Returns
0 if success, -1 if error.

◆ port_in_port_ranges()

int port_in_port_ranges ( int  pnum,
port_protocol_t  ptype,
array_t pranges 
)

Checks if a port num is in port ranges array.

Parameters
[in]pnumPort number.
[in]ptypePort type.
[in]prangesArray of port ranges.
Returns
1 if port in port ranges, 0 otherwise.

◆ port_range_ranges()

array_t* port_range_ranges ( const char *  port_range)

Create a range array from a port_range string.

Parameters
[in]port_rangeValid port_range string.
Returns
Range array.

◆ sockaddr_as_str()

void sockaddr_as_str ( const struct sockaddr_storage *  addr,
char *  str 
)

Convert an IP address to string format.

Parameters
[in]addrAddress to convert.
[out]strBuffer of INET6_ADDRSTRLEN size.

◆ validate_port_range()

int validate_port_range ( const char *  port_range)

Validate a port range string.

Accepts ranges in form of "103,U:200-1024,3000-4000,T:3-4,U:7".

Parameters
[in]port_rangeA port range.
Returns
0 success, 1 failed.

Variable Documentation

◆ global_source_addr

struct in_addr global_source_addr = { .s_addr = 0 }

◆ global_source_addr6

struct in6_addr global_source_addr6 = { .s6_addr32 = { 0, 0, 0, 0 } }

◆ global_source_iface

char global_source_iface[IFNAMSIZ] = { '\0' }