The NASL socket API.
More...
#include "nasl_socket.h"
#include "../misc/network.h"
#include "../misc/pcap_openvas.h"
#include "../misc/plugutils.h"
#include "../misc/support.h"
#include "exec.h"
#include "nasl.h"
#include "nasl_debug.h"
#include "nasl_func.h"
#include "nasl_global_ctxt.h"
#include "nasl_lex_ctxt.h"
#include "nasl_packet_forgery.h"
#include "nasl_tree.h"
#include "nasl_var.h"
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <gnutls/gnutls.h>
#include <gvm/base/logging.h>
#include <gvm/base/networking.h>
#include <gvm/base/prefs.h>
#include <net/if.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <unistd.h>
Go to the source code of this file.
The NASL socket API.
This file contains all the functions related to the handling of the sockets within a NASL script - for example the implementation of the NASL built-ins open_sock_tcp, send, recv, recv_line, and close.
Definition in file nasl_socket.c.
◆ EADDRNOTAVAIL
| #define EADDRNOTAVAIL EADDRINUSE |
◆ G_LOG_DOMAIN
| #define G_LOG_DOMAIN "lib nasl" |
◆ add_udp_data()
| static int add_udp_data |
( |
struct script_infos * |
script_infos, |
|
|
int |
soc, |
|
|
char * |
data, |
|
|
int |
len |
|
) |
| |
|
static |
Definition at line 156 of file nasl_socket.c.
160 int *key = g_memdup2 (&soc,
sizeof (
int));
163 data_record->
data = g_memdup2 ((gconstpointer)
data, (guint)
len);
165 if (udp_data == NULL)
168 g_hash_table_new_full (g_int_hash, g_int_equal, g_free, g_free);
172 g_hash_table_replace (udp_data, (gpointer) key, (gpointer) data_record);
References udp_record::data, len, udp_record::len, and script_infos::udp_data.
Referenced by nasl_send().
◆ block_socket()
| static int block_socket |
( |
int |
soc | ) |
|
|
static |
Definition at line 78 of file nasl_socket.c.
80 int flags = fcntl (soc, F_GETFL, 0);
83 perror (
"fcntl(F_GETFL)");
86 if (fcntl (soc, F_SETFL, (~O_NONBLOCK) & flags) < 0)
88 perror (
"fcntl(F_SETFL,~O_NONBLOCK)");
Referenced by nasl_open_privileged_socket().
◆ get_mtu()
| static int get_mtu |
( |
struct in6_addr * |
dst | ) |
|
|
static |
◆ get_udp_data()
| static char* get_udp_data |
( |
struct script_infos * |
script_infos, |
|
|
int |
soc, |
|
|
int * |
len |
|
) |
| |
|
static |
◆ get_udp_payload_size()
| static int get_udp_payload_size |
( |
struct in6_addr * |
dst | ) |
|
|
static |
◆ nasl_close_socket()
Definition at line 1012 of file nasl_socket.c.
1016 unsigned int opt_len =
sizeof (type);
1027 nasl_perror (lexic,
"close(%d): Invalid socket value\n", soc);
1031 e = getsockopt (soc, SOL_SOCKET, SO_TYPE, &type, &opt_len);
1034 if (type == SOCK_DGRAM)
1043 nasl_perror (lexic,
"close(%d): %s\n", soc, strerror (errno));
References close_stream_connection(), FAKE_CELL, fd_is_stream(), get_int_var_by_num(), lowest_socket, nasl_perror(), rm_udp_data(), struct_lex_ctxt::script_infos, and wait_before_next_probe().
Referenced by http_close_socket().
◆ nasl_get_mtu()
◆ nasl_get_sock_info()
Get info pertaining to a socket.
- NASL Function: get_sock_info\n
This function is used to retrieve various information about an active socket. It requires the NASL socket number and a string to select the information to retrieve.
Supported keywords are:
- dport Return the destination port. This is an integer. NOTE: Not yet implemented.
- sport Return the source port. This is an integer. NOTE: Not yet implemented.
- encaps Return the encapsulation of the socket. Example output: "TLScustom".
- tls-proto Return a string with the actual TLS protocol in use. n/a" is returned if no SSL/TLS session is active. Example
output: "TLSv1".
- tls-kx Return a string describing the key exchange algorithm. Example output: "RSA".
- tls-certtype Return the type of the certificate in use by the session. Example output: "X.509"
- tls-cipher Return the cipher algorithm in use by the session; Example output: "AES-256-CBC".
- tls-mac Return the message authentication algorithms used by the session. Example output: "SHA1".
- tls-auth Return the peer's authentication type. Example output: "CERT".
- tls-cert Return the peer's certificates for an SSL or TLS connection. This is an array of binary strings or NULL if no certificate is known.
- NASL Unnamed Parameters:\n
- A NASL socket
- A string keyword; see above.
- NASL Named Parameters:\n
- asstring If true return a human readable string instead of an integer. Used only with these keywords: encaps.
- NASL Returns:\n An integer or a string or NULL on error.
- Parameters
-
| [in] | lexic | Lexical context of the NASL interpreter. |
- Returns
- A tree cell.
Definition at line 1297 of file nasl_socket.c.
1302 const char *keyword, *s;
1306 gnutls_session_t tls_session;
1313 nasl_perror (lexic,
"error: socket %d is not valid\n");
1322 nasl_perror (lexic,
"error: second argument is not of type string\n");
1340 nasl_perror (lexic,
"error retrieving infos for socket %d: %s\n", sock,
1344 else if (!strcmp (keyword,
"encaps"))
1351 else if (!strcmp (keyword,
"tls-proto"))
1357 gnutls_protocol_get_name (gnutls_protocol_get_version (tls_session));
1358 strval = g_strdup (s ? s :
"[?]");
1360 else if (!strcmp (keyword,
"tls-kx"))
1365 s = gnutls_kx_get_name (gnutls_kx_get (tls_session));
1366 strval = g_strdup (s ? s :
"");
1368 else if (!strcmp (keyword,
"tls-certtype"))
1373 s = gnutls_certificate_type_get_name (
1374 gnutls_certificate_type_get (tls_session));
1375 strval = g_strdup (s ? s :
"");
1377 else if (!strcmp (keyword,
"tls-cipher"))
1382 s = gnutls_cipher_get_name (gnutls_cipher_get (tls_session));
1383 strval = g_strdup (s ? s :
"");
1385 else if (!strcmp (keyword,
"tls-mac"))
1390 s = gnutls_mac_get_name (gnutls_mac_get (tls_session));
1391 strval = g_strdup (s ? s :
"");
1393 else if (!strcmp (keyword,
"tls-auth"))
1399 switch (gnutls_auth_get_type (tls_session))
1401 case GNUTLS_CRD_ANON:
1404 case GNUTLS_CRD_CERTIFICATE:
1407 case GNUTLS_CRD_PSK:
1410 case GNUTLS_CRD_SRP:
1418 strval = g_strdup (s);
1420 else if (!strcmp (keyword,
"tls-cert"))
1425 && gnutls_certificate_type_get (tls_session) == GNUTLS_CRT_X509)
1427 const gnutls_datum_t *
list;
1428 unsigned int nlist = 0;
1432 list = gnutls_certificate_get_peers (tls_session, &nlist);
1439 retc->
x.
ref_val = a = g_malloc0 (
sizeof *a);
1441 for (i = 0; i < nlist; i++)
1443 memset (&v, 0,
sizeof v);
1454 nasl_perror (lexic,
"unknown keyword '%s'\n", keyword);
1466 retc->
size = strlen (strval);
References add_var_to_list(), alloc_typed_cell(), CONST_INT, CONST_STR, DYN_ARRAY, FAKE_CELL, get_encaps_name(), get_int_var_by_name(), get_int_var_by_num(), get_sock_infos(), get_str_var_by_num(), get_var_type_by_num(), TC::i_val, nasl_perror(), TC::ref_val, st_nasl_string::s_siz, st_nasl_string::s_val, TC::size, TC::str_val, st_a_nasl_var::v, st_a_nasl_var::v_str, VAR2_DATA, VAR2_STRING, st_a_nasl_var::var_type, and TC::x.
◆ nasl_get_source_port()
Definition at line 1155 of file nasl_socket.c.
1157 struct sockaddr_in ia;
1162 unsigned int type_len =
sizeof (type);
1167 nasl_perror (lexic,
"get_source_port: missing socket parameter\n");
1171 && getsockopt (s, SOL_SOCKET, SO_TYPE, &type, &type_len) == 0
1172 && type == SOCK_DGRAM)
1179 nasl_perror (lexic,
"get_source_port: invalid socket parameter %d\n", s);
1183 if (getsockname (fd, (
struct sockaddr *) &ia, &l) < 0)
1185 nasl_perror (lexic,
"get_source_port: getsockname(%d): %s\n", fd,
1190 retc->
x.
i_val = ntohs (ia.sin_port);
References alloc_typed_cell(), CONST_INT, fd_is_stream(), get_int_var_by_num(), TC::i_val, nasl_perror(), openvas_get_socket_from_connection(), and TC::x.
◆ nasl_join_multicast_group()
Definition at line 1057 of file nasl_socket.c.
1067 nasl_perror (lexic,
"join_multicast_group: missing parameter\n");
1070 if (!inet_aton (a, &m.imr_multiaddr))
1072 nasl_perror (lexic,
"join_multicast_group: invalid parameter '%s'\n", a);
1075 m.imr_interface.s_addr = INADDR_ANY;
1079 if (
jmg_desc[i].in.s_addr == m.imr_multiaddr.s_addr
1090 int s = socket (AF_INET, SOCK_DGRAM, 0);
1093 nasl_perror (lexic,
"join_multicast_group: socket: %s\n",
1098 if (setsockopt (s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &m,
sizeof (m)) < 0)
1101 lexic,
"join_multicast_group: setsockopt(IP_ADD_MEMBERSHIP): %s\n",
References alloc_typed_cell(), CONST_INT, jmg::count, get_str_var_by_num(), jmg::in, jmg_desc, jmg_max, nasl_perror(), and jmg::s.
◆ nasl_leave_multicast_group()
Definition at line 1123 of file nasl_socket.c.
1132 nasl_perror (lexic,
"leave_multicast_group: missing parameter\n");
1135 if (!inet_aton (a, &ia))
1137 nasl_perror (lexic,
"leave_multicast_group: invalid parameter '%s'\n", a);
1149 nasl_perror (lexic,
"leave_multicast_group: never joined group %s\n", a);
References FAKE_CELL, get_str_var_by_num(), jmg_desc, jmg_max, and nasl_perror().
◆ nasl_open_priv_sock_tcp()
◆ nasl_open_priv_sock_udp()
◆ nasl_open_privileged_socket()
Definition at line 215 of file nasl_socket.c.
218 int sport, current_sport = -1;
222 struct sockaddr_in addr,
daddr;
223 struct sockaddr_in6 addr6, daddr6;
238 lexic,
"open_private_socket: missing or undefined parameter dport!\n");
243 current_sport = 1023;
246 if (proto == IPPROTO_TCP)
249 if (IN6_IS_ADDR_V4MAPPED (p))
252 bzero (&addr,
sizeof (addr));
253 if (proto == IPPROTO_TCP)
254 sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
256 sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
261 bzero (&addr6,
sizeof (addr6));
262 if (proto == IPPROTO_TCP)
263 sock = socket (AF_INET6, SOCK_STREAM, IPPROTO_TCP);
265 sock = socket (AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
277 if (current_sport < 128 && sport < 0)
282 e = gvm_source_set_socket (sock, sport > 0 ? sport : current_sport--, family);
303 if (IN6_IS_ADDR_V4MAPPED (p))
306 daddr.sin_addr.s_addr = p->s6_addr32[3];
307 daddr.sin_family = AF_INET;
308 daddr.sin_port = htons (dport);
310 e = connect (sock, (
struct sockaddr *) &
daddr,
sizeof (
daddr));
314 bzero (&daddr6,
sizeof (daddr6));
315 memcpy (&daddr6.sin6_addr, p, sizeof (
struct in6_addr));
316 daddr6.sin6_family = AF_INET6;
317 daddr6.sin6_port = htons (dport);
319 e = connect (sock, (
struct sockaddr *) &daddr6,
sizeof (daddr6));
332 else if (errno != EINPROGRESS)
345 e = select (sock + 1, NULL, &rd, NULL, to > 0 ? &tv : NULL);
347 while (e < 0 && errno == EINTR);
356 opt_sz =
sizeof (opt);
358 if (getsockopt (sock, SOL_SOCKET, SO_ERROR, &opt, &opt_sz) < 0)
360 g_message (
"[%d] open_priv_sock()->getsockopt() failed : %s", getpid (),
386 if (proto == IPPROTO_TCP)
390 retc->
x.
i_val = sock < 0 ? 0 : sock;
References alloc_typed_cell(), block_socket(), CONST_INT, daddr, EADDRNOTAVAIL, FAKE_CELL, get_int_var_by_name(), TC::i_val, lowest_socket, nasl_perror(), OPENVAS_ENCAPS_IP, openvas_register_connection(), plug_get_host_ip(), struct_lex_ctxt::recv_timeout, struct_lex_ctxt::script_infos, timeval(), unblock_socket(), wait_before_next_probe(), and TC::x.
Referenced by nasl_open_priv_sock_tcp(), and nasl_open_priv_sock_udp().
◆ nasl_open_sock_tcp()
Open a TCP socket to the target host.
- NASL Function: open_sock_tcp\n
This function is used to create a TCP connection to the target host. It requires the port number as its argument and has various optional named arguments to control encapsulation, timeout and buffering.
- NASL Unnamed Parameters:\n
- A non-negative integer with the TCP port number.
- NASL Named Parameters:\n
- bufsz An integer with the the size buffer size. Note that by default, no buffering is used.
- timeout An integer with the timeout value in seconds. The default timeout is controlled by a global value.
- transport One of the ENCAPS_* constants to force a specific encapsulation mode or force trying of all modes (ENCAPS_AUTO). This is for example useful to select a specific TLS or SSL version or use specific TLS connection setup priorities. See get_port_transport for a description of the ENCAPS constants.
- priority A string value with priorities for an TLS encapsulation. For the syntax of the priority string see the GNUTLS manual. This argument is only used in ENCAPS_TLScustom encapsulation.
- NASL Returns:\n A positive integer as a NASL socket, 0 on connection error or
- NULL on other errors.
- Parameters
-
| [in] | lexic | Lexical context of the NASL interpreter. |
- Returns
- A tree cell.
Definition at line 509 of file nasl_socket.c.
References nasl_open_sock_tcp_bufsz().
◆ nasl_open_sock_tcp_bufsz()
Definition at line 409 of file nasl_socket.c.
415 const char *priority;
451 else if (transport == 0)
456 if (bufsz > 0 && soc >= 0)
459 nasl_perror (lexic,
"stream_set_buffer: soc=%d,bufsz=%d\n", soc, bufsz);
463 retc->
x.
i_val = soc < 0 ? 0 : soc;
References alloc_typed_cell(), CONST_INT, get_int_var_by_name(), get_int_var_by_num(), get_str_var_by_name(), get_var_type_by_name(), TC::i_val, nasl_perror(), NO_PRIORITY_FLAGS, open_stream_auto_encaps_ext(), open_stream_connection_ext(), OPENVAS_ENCAPS_TLScustom, struct_lex_ctxt::recv_timeout, struct_lex_ctxt::script_infos, stream_set_buffer(), VAR2_DATA, VAR2_STRING, wait_before_next_probe(), and TC::x.
Referenced by http_open_socket(), and nasl_open_sock_tcp().
◆ nasl_open_sock_udp()
Definition at line 521 of file nasl_socket.c.
526 struct sockaddr_in soca;
527 struct sockaddr_in6 soca6;
538 if (IN6_IS_ADDR_V4MAPPED (ia))
540 bzero (&soca,
sizeof (soca));
541 soca.sin_addr.s_addr = ia->s6_addr32[3];
542 soca.sin_port = htons (port);
543 soca.sin_family = AF_INET;
545 soc = socket (AF_INET, SOCK_DGRAM, 0);
548 gvm_source_set_socket (soc, 0, AF_INET);
549 if (connect (soc, (
struct sockaddr *) &soca,
sizeof (soca)) < 0)
557 bzero (&soca6,
sizeof (soca6));
558 memcpy (&soca6.sin6_addr, ia, sizeof (
struct in6_addr));
559 soca6.sin6_port = htons (port);
560 soca6.sin6_family = AF_INET6;
562 soc = socket (AF_INET6, SOCK_DGRAM, 0);
565 gvm_source_set_socket (soc, 0, AF_INET6);
566 if (connect (soc, (
struct sockaddr *) &soca6,
sizeof (soca6)) < 0)
References alloc_typed_cell(), CONST_INT, get_int_var_by_num(), TC::i_val, lowest_socket, plug_get_host_ip(), struct_lex_ctxt::script_infos, and TC::x.
◆ nasl_recv()
Definition at line 754 of file nasl_socket.c.
756 char *data, *resend_data;
766 unsigned int opt_len =
sizeof (type);
769 if (
len <= 0 || soc <= 0)
775 data = g_malloc0 (
len);
777 e = getsockopt (soc, SOL_SOCKET, SO_TYPE, &type, &opt_len);
781 if (e == 0 && type == SOCK_DGRAM)
787 tv.tv_sec = to / retries;
788 tv.tv_usec = (to % retries) * 100000;
790 for (i = 0; i < retries; i++)
795 if (select (soc + 1, &rd, NULL, NULL, &tv) > 0)
798 alen = recv (soc, data + new_len,
len - new_len, 0);
818 if (resend_data != NULL)
819 send (soc, resend_data, rd_len, 0);
820 tv.tv_sec = to / retries;
821 tv.tv_usec = (to % retries) * 100000;
834 retc->
x.
str_val = g_memdup2 (data, new_len);
835 retc->
size = new_len;
References alloc_typed_cell(), CONST_DATA, fd_is_stream(), get_int_var_by_name(), get_udp_data(), len, read_stream_connection_min(), struct_lex_ctxt::recv_timeout, struct_lex_ctxt::script_infos, TC::size, TC::str_val, stream_set_timeout(), timeval(), and TC::x.
◆ nasl_recv_line()
Definition at line 847 of file nasl_socket.c.
858 if (
len == -1 || soc <= 0)
860 nasl_perror (lexic,
"recv_line: missing or undefined parameter"
861 " length or socket\n");
875 data = g_malloc0 (
len + 1);
883 if (timeout >= 0 && time (NULL) - t1 < timeout)
889 if ((data[n - 1] ==
'\n') || (n >=
len))
902 retc->
size = new_len;
903 retc->
x.
str_val = g_memdup2 (data, new_len + 1);
References alloc_typed_cell(), CONST_DATA, fd_is_stream(), get_int_var_by_name(), len, nasl_perror(), read_stream_connection_min(), TC::size, TC::str_val, stream_get_buffer_sz(), stream_set_buffer(), and TC::x.
◆ nasl_send()
Definition at line 960 of file nasl_socket.c.
971 unsigned int type_len =
sizeof (type);
973 if (soc <= 0 || data == NULL)
975 nasl_perror (lexic,
"Syntax error with the send() function\n");
977 "Correct syntax is : send(socket:<soc>, data:<data>\n");
981 if (length <= 0 || length > data_length)
985 && getsockopt (soc, SOL_SOCKET, SO_TYPE, &type, &type_len) == 0
986 && type == SOCK_DGRAM)
992 "data payload is larger (%d) than max udp payload (%d)\n",
References add_udp_data(), alloc_typed_cell(), CONST_INT, fd_is_stream(), get_int_var_by_name(), get_str_var_by_name(), get_udp_payload_size(), get_var_size_by_name(), TC::i_val, length, nasl_perror(), nsend(), option, plug_get_host_ip(), struct_lex_ctxt::script_infos, wait_before_next_probe(), and TC::x.
Referenced by nasl_send_capture().
◆ nasl_socket_cert_verify()
Verify a certificate.
- NASL Function: socket_cert_verify\n
This function is used to retrieve and verify a certificate from an active socket. It requires the NASL socket number.
- NASL Named Parameters:\n
- NASL Returns:\n 0 in case of successful verification. A positive integer in
- case of a verification error or NULL on other errors.
- Parameters
-
| [in] | lexic | Lexical context of the NASL interpreter. |
- Returns
- A tree cell.
Definition at line 1496 of file nasl_socket.c.
1501 gnutls_x509_crt_t *cert = NULL;
1502 gnutls_x509_trust_list_t ca_list;
1503 unsigned int ca_list_size = 0;
1504 unsigned int i, cert_n = 0;
1505 unsigned int voutput;
1506 const gnutls_datum_t *certs;
1509 gnutls_session_t tls_session;
1514 nasl_perror (lexic,
"socket_get_cert: Erroneous socket value %d\n", soc);
1525 nasl_perror (lexic,
"error retrieving tls_session for socket %d: %s\n",
1526 soc, strerror (err));
1533 && gnutls_certificate_type_get (tls_session) == GNUTLS_CRT_X509)
1535 certs = gnutls_certificate_get_peers (tls_session, &cert_n);
1542 cert = g_malloc0 (
sizeof (*cert) * cert_n);
1543 for (i = 0; i < cert_n; i++)
1545 if (gnutls_x509_crt_init (&cert[i]) != GNUTLS_E_SUCCESS)
1550 if (gnutls_x509_crt_import (cert[i], &certs[i], GNUTLS_X509_FMT_DER)
1551 != GNUTLS_E_SUCCESS)
1559 ret = gnutls_x509_trust_list_init (&ca_list, ca_list_size);
1565 ret = gnutls_x509_trust_list_add_system_trust (ca_list, 0, 0);
1573 if (gnutls_x509_trust_list_verify_crt (ca_list, cert, cert_n, 0, &voutput,
1575 != GNUTLS_E_SUCCESS)
References alloc_typed_cell(), CONST_INT, get_int_var_by_name(), get_sock_infos(), TC::i_val, nasl_perror(), and TC::x.
◆ nasl_socket_check_ssl_safe_renegotiation()
◆ nasl_socket_get_cert()
Definition at line 676 of file nasl_socket.c.
678 int soc, cert_len = 0;
685 nasl_perror (lexic,
"socket_get_cert: Erroneous socket value %d\n", soc);
693 retc->
size = cert_len;
References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), nasl_perror(), TC::size, socket_get_cert(), TC::str_val, and TC::x.
◆ nasl_socket_get_error()
Definition at line 1195 of file nasl_socket.c.
1227 g_message (
"socket_get_error: Erroneous socket value %d", soc);
1231 g_message (
"Unknown error %d %s", err, strerror (err));
References alloc_typed_cell(), CONST_INT, fd_is_stream(), get_int_var_by_num(), TC::i_val, NASL_ERR_ECONNRESET, NASL_ERR_ETIMEDOUT, NASL_ERR_EUNREACH, NASL_ERR_NOERR, stream_get_err(), and TC::x.
◆ nasl_socket_get_ssl_ciphersuite()
◆ nasl_socket_get_ssl_session_id()
◆ nasl_socket_get_ssl_version()
◆ nasl_socket_negotiate_ssl()
Definition at line 582 of file nasl_socket.c.
584 int soc, transport, ret;
592 nasl_perror (lexic,
"socket_ssl_negotiate: Erroneous socket value %d\n",
601 "socket_ssl_negotiate: Erroneous transport value %d\n",
References alloc_typed_cell(), CONST_INT, get_int_var_by_name(), TC::i_val, IS_ENCAPS_SSL, nasl_perror(), OPENVAS_ENCAPS_TLScustom, struct_lex_ctxt::script_infos, socket_negotiate_ssl(), and TC::x.
◆ nasl_socket_ssl_do_handshake()
◆ rm_udp_data()
| static void rm_udp_data |
( |
struct script_infos * |
script_infos, |
|
|
int |
soc |
|
) |
| |
|
static |
◆ unblock_socket()
| static int unblock_socket |
( |
int |
soc | ) |
|
|
static |
Definition at line 61 of file nasl_socket.c.
63 int flags = fcntl (soc, F_GETFL, 0);
66 perror (
"fcntl(F_GETFL)");
69 if (fcntl (soc, F_SETFL, O_NONBLOCK | flags) < 0)
71 perror (
"fcntl(F_SETFL,O_NONBLOCK)");
Referenced by nasl_open_privileged_socket().
◆ wait_before_next_probe()
| static void wait_before_next_probe |
( |
| ) |
|
|
static |
Definition at line 95 of file nasl_socket.c.
97 const char *time_between_request;
100 time_between_request = prefs_get (
"time_between_request");
101 if (time_between_request)
102 minwaittime = atoi (time_between_request);
106 static double lastprobesec = 0;
107 static double lastprobeusec = 0;
112 gettimeofday (&tvnow, NULL);
113 if (lastprobesec <= 0)
115 lastprobesec = tvnow.tv_sec - 10;
116 lastprobeusec = tvnow.tv_usec;
119 tvdiff.tv_sec = tvnow.tv_sec - lastprobesec;
120 tvdiff.tv_usec = tvnow.tv_usec - lastprobeusec;
121 if (tvdiff.tv_usec <= 0)
124 tvdiff.tv_usec *= -1;
127 diff_msec = tvdiff.tv_sec * 1000 + tvdiff.tv_usec / 1000;
128 time2wait = (minwaittime - diff_msec) * 1000;
132 gettimeofday (&tvnow, NULL);
133 lastprobesec = tvnow.tv_sec;
134 lastprobeusec = tvnow.tv_usec;
References timeval().
Referenced by nasl_close_socket(), nasl_open_privileged_socket(), nasl_open_sock_tcp_bufsz(), and nasl_send().
◆ jmg_desc
| struct jmg * jmg_desc = NULL |
|
static |
◆ jmg_max
◆ lowest_socket
int socket_ssl_do_handshake(int fd)
Do a re-handshake of the TLS/SSL protocol.
static char * get_udp_data(struct script_infos *script_infos, int soc, int *len)
int get_var_size_by_name(lex_ctxt *, const char *)
struct in6_addr * plug_get_host_ip(struct script_infos *args)
#define NO_PRIORITY_FLAGS
int openvas_get_socket_from_connection(int fd)
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...
const char * get_encaps_name(openvas_encaps_t code)
int openvas_register_connection(int soc, void *ssl, gnutls_certificate_credentials_t certcred, openvas_encaps_t encaps)
union st_a_nasl_var::@7 v
char * get_str_var_by_name(lex_ctxt *, const char *)
int open_stream_connection_ext(struct script_infos *args, unsigned int port, int transport, int timeout, const char *priority, int flags)
int open_stream_auto_encaps_ext(struct script_infos *args, unsigned int port, int timeout, int force)
void socket_get_cert(int fd, void **cert, int *certlen)
int socket_get_ssl_version(int fd)
#define NASL_ERR_EUNREACH
@ OPENVAS_ENCAPS_TLScustom
int stream_set_buffer(int fd, int sz)
int socket_ssl_safe_renegotiation_status(int fd)
Check if Secure Renegotiation is supported in the server side.
void nasl_perror(lex_ctxt *lexic, char *msg,...)
int get_var_type_by_name(lex_ctxt *, const char *)
static void rm_udp_data(struct script_infos *script_infos, int soc)
static int block_socket(int soc)
int stream_get_err(int fd)
int nsend(int fd, void *data, int length, int i_opt)
static int add_udp_data(struct script_infos *script_infos, int soc, char *data, int len)
#define NASL_ERR_ECONNRESET
long int get_int_var_by_name(lex_ctxt *, const char *, int)
int socket_get_ssl_ciphersuite(int fd)
int read_stream_connection_min(int fd, void *buf0, int min_len, int max_len)
tree_cell * nasl_open_sock_tcp_bufsz(lex_ctxt *lexic, int bufsz)
long int get_int_var_by_num(lex_ctxt *, int, int)
char * get_str_var_by_num(lex_ctxt *, int)
static struct timeval timeval(unsigned long val)
struct script_infos * script_infos
static int get_mtu(struct in6_addr *dst)
int stream_get_buffer_sz(int fd)
static void wait_before_next_probe()
void socket_get_ssl_session_id(int fd, void **sid, size_t *ssize)
int socket_negotiate_ssl(int fd, openvas_encaps_t transport, struct script_infos *args)
Upgrade an ENCAPS_IP socket to an SSL/TLS encapsulated one.
static tree_cell * nasl_open_privileged_socket(lex_ctxt *lexic, int proto)
static int unblock_socket(int soc)
static struct jmg * jmg_desc
static int get_udp_payload_size(struct in6_addr *dst)
int get_var_type_by_num(lex_ctxt *, int)
Returns NASL variable/cell type, VAR2_UNDEF if value is NULL.
int add_var_to_list(nasl_array *a, int i, const anon_nasl_var *v)
int close_stream_connection(int fd)
int get_sock_infos(int sock, int *r_transport, void **r_tls_session)
tree_cell * alloc_typed_cell(int typ)
#define NASL_ERR_ETIMEDOUT
int stream_set_timeout(int fd, int timeout)