OpenVAS Libraries  9.0.3
nasl_socket.c File Reference

The NASL socket API. More...

#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/time.h>
#include <gnutls/gnutls.h>
#include "../misc/network.h"
#include "../base/openvas_networking.h"
#include "../misc/plugutils.h"
#include "../misc/openvas_logging.h"
#include "../misc/prefs.h"
#include "nasl.h"
#include "nasl_tree.h"
#include "nasl_global_ctxt.h"
#include "nasl_func.h"
#include "nasl_var.h"
#include "nasl_lex_ctxt.h"
#include "exec.h"
#include "nasl_packet_forgery.h"
#include "nasl_debug.h"
Include dependency graph for nasl_socket.c:

Go to the source code of this file.

Data Structures

struct  udp_record
 
struct  jmg
 

Macros

#define EADDRNOTAVAIL   EADDRINUSE
 

Functions

tree_cellnasl_open_priv_sock_tcp (lex_ctxt *lexic)
 
tree_cellnasl_open_priv_sock_udp (lex_ctxt *lexic)
 
tree_cellnasl_open_sock_tcp_bufsz (lex_ctxt *lexic, int bufsz)
 
tree_cellnasl_open_sock_tcp (lex_ctxt *lexic)
 Open a TCP socket to the target host. More...
 
tree_cellnasl_open_sock_udp (lex_ctxt *lexic)
 
tree_cellnasl_socket_negotiate_ssl (lex_ctxt *lexic)
 
tree_cellnasl_socket_get_cert (lex_ctxt *lexic)
 
tree_cellnasl_socket_get_ssl_session_id (lex_ctxt *lexic)
 
tree_cellnasl_socket_get_ssl_compression (lex_ctxt *lexic)
 
tree_cellnasl_socket_get_ssl_version (lex_ctxt *lexic)
 
tree_cellnasl_socket_get_ssl_ciphersuite (lex_ctxt *lexic)
 
tree_cellnasl_recv (lex_ctxt *lexic)
 
tree_cellnasl_recv_line (lex_ctxt *lexic)
 
tree_cellnasl_send (lex_ctxt *lexic)
 
tree_cellnasl_close_socket (lex_ctxt *lexic)
 
tree_cellnasl_join_multicast_group (lex_ctxt *lexic)
 
tree_cellnasl_leave_multicast_group (lex_ctxt *lexic)
 
tree_cellnasl_get_source_port (lex_ctxt *lexic)
 
tree_cellnasl_socket_get_error (lex_ctxt *lexic)
 
tree_cellnasl_get_sock_info (lex_ctxt *lexic)
 Get info pertaining to a socket. More...
 

Variables

int lowest_socket = 0
 

Detailed Description

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.

Macro Definition Documentation

◆ EADDRNOTAVAIL

#define EADDRNOTAVAIL   EADDRINUSE

Definition at line 70 of file nasl_socket.c.

Function Documentation

◆ nasl_close_socket()

tree_cell* nasl_close_socket ( lex_ctxt lexic)

Definition at line 947 of file nasl_socket.c.

References fd_is_stream(), and get_int_var_by_num().

Referenced by http_close_socket().

948 {
949  int soc;
950  int type;
951  unsigned int opt_len = sizeof (type);
952  int e;
953 
954  soc = get_int_var_by_num (lexic, 0, -1);
955  if (fd_is_stream (soc))
956  {
957  wait_before_next_probe ();
958  return close_stream_connection (soc) < 0 ? NULL : FAKE_CELL;
959  }
960  if (lowest_socket == 0 || soc < lowest_socket)
961  {
962  nasl_perror (lexic, "close(%d): Invalid socket value\n", soc);
963  return NULL;
964  }
965 
966  e = getsockopt (soc, SOL_SOCKET, SO_TYPE, &type, &opt_len);
967  if (e == 0)
968  {
969  if (type == SOCK_DGRAM)
970  {
971  rm_udp_data (lexic->script_infos, soc);
972  return FAKE_CELL;
973  }
974  close (soc);
975  return FAKE_CELL;
976  }
977  else
978  nasl_perror (lexic, "close(%d): %s\n", soc, strerror (errno));
979 
980  return NULL;
981 }
#define FAKE_CELL
Definition: nasl_tree.h:120
int fd_is_stream(int fd)
Definition: network.c:2146
int lowest_socket
Definition: nasl_socket.c:223
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition: nasl_var.c:1226
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
struct arglist * script_infos
Definition: nasl_lex_ctxt.h:39
int close_stream_connection(int fd)
Definition: network.c:1699
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nasl_get_sock_info()

tree_cell* nasl_get_sock_info ( lex_ctxt lexic)

Get info pertaining to a socket.

NASL Function: get_sock_info

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-comp Return the compression algorithms in use by the session. Example output: "DEFLATE".
  • 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:
  • A NASL socket
  • A string keyword; see above.
NASL Named Parameters:
  • asstring If true return a human readable string instead of an integer. Used only with these keywords: encaps.
NASL Returns: An integer or a string or NULL on error.
Parameters
[in]lexicLexical context of the NASL interpreter.
Returns
A tree cell.

Definition at line 1240 of file nasl_socket.c.

References add_var_to_list(), alloc_tree_cell(), alloc_typed_cell(), CONST_INT, CONST_STR, DYN_ARRAY, err, FAKE_CELL, get_encaps_name(), get_int_local_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, TC::type, st_a_nasl_var::v, st_a_nasl_var::v_str, VAR2_DATA, VAR2_STRING, st_a_nasl_var::var_type, and TC::x.

1241 {
1242  int sock;
1243  int type;
1244  int err;
1245  const char *keyword, *s;
1246  tree_cell *retc;
1247  int as_string;
1248  int transport;
1249  gnutls_session_t tls_session;
1250  char *strval;
1251  int intval;
1252 
1253  sock = get_int_var_by_num (lexic, 0, -1);
1254  if (sock <= 0)
1255  {
1256  nasl_perror (lexic, "error: socket %d is not valid\n");
1257  return NULL;
1258  }
1259 
1260  keyword = get_str_var_by_num (lexic, 1);
1261  if (!keyword || !((type = get_var_type_by_num (lexic, 1)) == VAR2_STRING
1262  || type == VAR2_DATA))
1263  {
1264  nasl_perror (lexic, "error: second argument is not of type string\n");
1265  return NULL;
1266  }
1267 
1268  as_string = !!get_int_local_var_by_name (lexic, "asstring", 0);
1269 
1270  transport = 0;
1271  strval = NULL;
1272  intval = 0;
1273  retc = FAKE_CELL; /* Dummy value to detect retc == NULL. */
1274 
1275  {
1276  void *tmp = NULL;
1277  err = get_sock_infos (sock, &transport, &tmp);
1278  tls_session = tmp;
1279  }
1280  if (err)
1281  {
1282  nasl_perror (lexic, "error retrieving infos for socket %d: %s\n",
1283  sock, strerror (err));
1284  retc = NULL;
1285  }
1286  else if (!strcmp (keyword, "encaps"))
1287  {
1288  if (as_string)
1289  strval = g_strdup (get_encaps_name (transport));
1290  else
1291  intval = transport;
1292  }
1293  else if (!strcmp (keyword, "tls-proto"))
1294  {
1295  if (!tls_session)
1296  s = "n/a";
1297  else
1298  s = gnutls_protocol_get_name
1299  (gnutls_protocol_get_version (tls_session));
1300  strval = g_strdup (s?s:"[?]");
1301  }
1302  else if (!strcmp (keyword, "tls-kx"))
1303  {
1304  if (!tls_session)
1305  s = "n/a";
1306  else
1307  s = gnutls_kx_get_name (gnutls_kx_get (tls_session));
1308  strval = g_strdup (s?s:"");
1309  }
1310  else if (!strcmp (keyword, "tls-certtype"))
1311  {
1312  if (!tls_session)
1313  s = "n/a";
1314  else
1315  s = gnutls_certificate_type_get_name
1316  (gnutls_certificate_type_get (tls_session));
1317  strval = g_strdup (s?s:"");
1318  }
1319  else if (!strcmp (keyword, "tls-cipher"))
1320  {
1321  if (!tls_session)
1322  s = "n/a";
1323  else
1324  s = gnutls_cipher_get_name (gnutls_cipher_get (tls_session));
1325  strval = g_strdup (s?s:"");
1326  }
1327  else if (!strcmp (keyword, "tls-mac"))
1328  {
1329  if (!tls_session)
1330  s = "n/a";
1331  else
1332  s = gnutls_mac_get_name (gnutls_mac_get (tls_session));
1333  strval = g_strdup (s?s:"");
1334  }
1335  else if (!strcmp (keyword, "tls-comp"))
1336  {
1337  if (!tls_session)
1338  s = "n/a";
1339  else
1340  s = gnutls_compression_get_name
1341  (gnutls_compression_get (tls_session));
1342  strval = g_strdup (s?s:"");
1343  }
1344  else if (!strcmp (keyword, "tls-auth"))
1345  {
1346  if (!tls_session)
1347  s = "n/a";
1348  else
1349  {
1350  switch (gnutls_auth_get_type (tls_session))
1351  {
1352  case GNUTLS_CRD_ANON: s = "ANON"; break;
1353  case GNUTLS_CRD_CERTIFICATE: s = "CERT"; break;
1354  case GNUTLS_CRD_PSK: s = "PSK"; break;
1355  case GNUTLS_CRD_SRP: s = "SRP"; break;
1356  default: s = "[?]"; break;
1357  }
1358  }
1359  strval = g_strdup (s?s:"");
1360  }
1361  else if (!strcmp (keyword, "tls-cert"))
1362  {
1363  /* We only support X.509 for now. GNUTLS also allows for
1364  OpenPGP, but we are not prepared for that. */
1365  if (tls_session
1366  && gnutls_certificate_type_get (tls_session) == GNUTLS_CRT_X509)
1367  {
1368  const gnutls_datum_t *list;
1369  unsigned int nlist = 0;
1370  nasl_array *a;
1371  anon_nasl_var v;
1372 
1373  list = gnutls_certificate_get_peers (tls_session, &nlist);
1374  if (!list)
1375  retc = NULL; /* No certificate or other error. */
1376  else
1377  {
1378  int i;
1379  retc = alloc_tree_cell (0, NULL);
1380  retc->type = DYN_ARRAY;
1381  retc->x.ref_val = a = g_malloc0 (sizeof *a);
1382 
1383  for (i=0; i < nlist; i++)
1384  {
1385  memset (&v, 0, sizeof v);
1386  v.var_type = VAR2_DATA;
1387  v.v.v_str.s_val = list[i].data;
1388  v.v.v_str.s_siz = list[i].size;
1389  add_var_to_list (a, i, &v);
1390  }
1391  }
1392  }
1393  }
1394  else
1395  {
1396  nasl_perror (lexic, "unknown keyword '%s'\n", keyword);
1397  retc = NULL;
1398  }
1399 
1400  if (!retc)
1401  ;
1402  else if (retc != FAKE_CELL)
1403  ; /* Already allocated. */
1404  else if (strval)
1405  {
1406  retc = alloc_typed_cell (CONST_STR);
1407  retc->x.str_val = strval;
1408  retc->size = strlen (strval);
1409  }
1410  else
1411  {
1412  retc = alloc_typed_cell (CONST_INT);
1413  retc->x.i_val = intval;
1414  }
1415 
1416  return retc;
1417 }
#define FAKE_CELL
Definition: nasl_tree.h:120
#define err(x)
const char * get_encaps_name(openvas_encaps_t code)
Definition: network.c:1729
short type
Definition: nasl_tree.h:107
union st_a_nasl_var::@9 v
char * str_val
Definition: nasl_tree.h:113
void * ref_val
Definition: nasl_tree.h:115
nasl_string_t v_str
Definition: nasl_var.h:60
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
union TC::@7 x
int add_var_to_list(nasl_array *a, int i, const anon_nasl_var *v)
Definition: nasl_var.c:1403
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:53
int var_type
Definition: nasl_var.h:54
Definition: nasl_tree.h:105
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition: nasl_var.c:1226
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
char * get_str_var_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1248
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
unsigned char * s_val
Definition: nasl_var.h:35
int get_sock_infos(int sock, int *r_transport, void **r_tls_session)
Definition: network.c:2376
int get_var_type_by_num(lex_ctxt *, int)
Returns NASL variable/cell type, VAR2_UNDEF if value is NULL.
Definition: nasl_var.c:1315
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ nasl_get_source_port()

tree_cell* nasl_get_source_port ( lex_ctxt lexic)

Definition at line 1094 of file nasl_socket.c.

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.

1095 {
1096  struct sockaddr_in ia;
1097  int s, fd;
1098  unsigned int l;
1099  tree_cell *retc;
1100  int type;
1101  unsigned int type_len = sizeof (type);
1102 
1103  s = get_int_var_by_num (lexic, 0, -1);
1104  if (s < 0)
1105  {
1106  nasl_perror (lexic, "get_source_port: missing socket parameter\n");
1107  return NULL;
1108  }
1109  if (!fd_is_stream (s)
1110  && getsockopt (s, SOL_SOCKET, SO_TYPE, &type, &type_len) == 0
1111  && type == SOCK_DGRAM)
1112  fd = s;
1113  else
1115 
1116 
1117  if (fd < 0)
1118  {
1119  nasl_perror (lexic, "get_source_port: invalid socket parameter %d\n", s);
1120  return NULL;
1121  }
1122  l = sizeof (ia);
1123  if (getsockname (fd, (struct sockaddr *) &ia, &l) < 0)
1124  {
1125  nasl_perror (lexic, "get_source_port: getsockname(%d): %s\n", fd,
1126  strerror (errno));
1127  return NULL;
1128  }
1129  retc = alloc_typed_cell (CONST_INT);
1130  retc->x.i_val = ntohs (ia.sin_port);
1131  return retc;
1132 }
int openvas_get_socket_from_connection(int fd)
Definition: network.c:395
union TC::@7 x
int fd_is_stream(int fd)
Definition: network.c:2146
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:53
Definition: nasl_tree.h:105
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition: nasl_var.c:1226
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
long int i_val
Definition: nasl_tree.h:114
Here is the call graph for this function:

◆ nasl_join_multicast_group()

tree_cell* nasl_join_multicast_group ( lex_ctxt lexic)

Definition at line 993 of file nasl_socket.c.

References get_str_var_by_num(), and nasl_perror().

994 {
995  char *a;
996  int i, j;
997  struct ip_mreq m;
998  tree_cell *retc = NULL;
999 
1000  a = get_str_var_by_num (lexic, 0);
1001  if (a == NULL)
1002  {
1003  nasl_perror (lexic, "join_multicast_group: missing parameter\n");
1004  return NULL;
1005  }
1006  if (!inet_aton (a, &m.imr_multiaddr))
1007  {
1008  nasl_perror (lexic, "join_multicast_group: invalid parameter '%s'\n", a);
1009  return NULL;
1010  }
1011  m.imr_interface.s_addr = INADDR_ANY;
1012 
1013  j = -1;
1014  for (i = 0; i < jmg_max; i++)
1015  if (jmg_desc[i].in.s_addr == m.imr_multiaddr.s_addr
1016  && jmg_desc[i].count > 0)
1017  {
1018  jmg_desc[i].count++;
1019  break;
1020  }
1021  else if (jmg_desc[i].count <= 0)
1022  j = i;
1023 
1024 
1025  if (i >= jmg_max)
1026  {
1027  int s = socket (AF_INET, SOCK_DGRAM, 0);
1028  if (s < 0)
1029  {
1030  nasl_perror (lexic, "join_multicast_group: socket: %s\n",
1031  strerror (errno));
1032  return NULL;
1033  }
1034 
1035  if (setsockopt (s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &m, sizeof (m)) < 0)
1036  {
1037  nasl_perror (lexic,
1038  "join_multicast_group: setsockopt(IP_ADD_MEMBERSHIP): %s\n",
1039  strerror (errno));
1040  close (s);
1041  return NULL;
1042  }
1043 
1044  if (j < 0)
1045  {
1046  jmg_desc = g_realloc (jmg_desc, sizeof (*jmg_desc) * (jmg_max + 1));
1047  j = jmg_max++;
1048  }
1049  jmg_desc[j].s = s;
1050  jmg_desc[j].in = m.imr_multiaddr;
1051  jmg_desc[j].count = 1;
1052  }
1053 
1054  retc = alloc_typed_cell (CONST_INT);
1055  retc->x.i_val = 1;
1056  return retc;
1057 }
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:53
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
char * get_str_var_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1248
Here is the call graph for this function:

◆ nasl_leave_multicast_group()

tree_cell* nasl_leave_multicast_group ( lex_ctxt lexic)

Definition at line 1061 of file nasl_socket.c.

References get_str_var_by_num(), and nasl_perror().

1062 {
1063  char *a;
1064  struct in_addr ia;
1065  int i;
1066 
1067  a = get_str_var_by_num (lexic, 0);
1068  if (a == NULL)
1069  {
1070  nasl_perror (lexic, "leave_multicast_group: missing parameter\n");
1071  return NULL;
1072  }
1073  if (!inet_aton (a, &ia))
1074  {
1075  nasl_perror (lexic, "leave_multicast_group: invalid parameter '%s'\n", a);
1076  return NULL;
1077  }
1078 
1079  for (i = 0; i < jmg_max; i++)
1080  if (jmg_desc[i].count > 0 && jmg_desc[i].in.s_addr == ia.s_addr)
1081  {
1082  if (--jmg_desc[i].count <= 0)
1083  close (jmg_desc[i].s);
1084  return FAKE_CELL;
1085  }
1086 
1087  nasl_perror (lexic, "leave_multicast_group: never joined group %s\n", a);
1088  return NULL;
1089 }
#define FAKE_CELL
Definition: nasl_tree.h:120
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
char * get_str_var_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1248
Here is the call graph for this function:

◆ nasl_open_priv_sock_tcp()

tree_cell* nasl_open_priv_sock_tcp ( lex_ctxt lexic)

Definition at line 411 of file nasl_socket.c.

412 {
413  return nasl_open_privileged_socket (lexic, IPPROTO_TCP);
414 }

◆ nasl_open_priv_sock_udp()

tree_cell* nasl_open_priv_sock_udp ( lex_ctxt lexic)

Definition at line 417 of file nasl_socket.c.

418 {
419  return nasl_open_privileged_socket (lexic, IPPROTO_UDP);
420 }

◆ nasl_open_sock_tcp()

tree_cell* nasl_open_sock_tcp ( lex_ctxt lexic)

Open a TCP socket to the target host.

NASL Function: open_sock_tcp

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:
  • A non-negative integer with the TCP port number.
NASL Named Parameters:
  • 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: A positive integer as a NASL socket, 0 on connection error or
NULL on other errors.
Parameters
[in]lexicLexical context of the NASL interpreter.
Returns
A tree cell.

Definition at line 527 of file nasl_socket.c.

References nasl_open_sock_tcp_bufsz().

528 {
529  return nasl_open_sock_tcp_bufsz (lexic, -1);
530 }
tree_cell * nasl_open_sock_tcp_bufsz(lex_ctxt *lexic, int bufsz)
Definition: nasl_socket.c:426
Here is the call graph for this function:

◆ nasl_open_sock_tcp_bufsz()

tree_cell* nasl_open_sock_tcp_bufsz ( lex_ctxt lexic,
int  bufsz 
)

Definition at line 426 of file nasl_socket.c.

References get_int_local_var_by_name(), get_int_var_by_num(), get_local_var_type_by_name(), get_str_local_var_by_name(), OPENVAS_ENCAPS_TLScustom, struct_lex_ctxt::recv_timeout, struct_lex_ctxt::script_infos, arglist::type, VAR2_DATA, and VAR2_STRING.

Referenced by http_open_socket(), and nasl_open_sock_tcp().

427 {
428  int soc = -1;
429  struct arglist *script_infos = lexic->script_infos;
430  int to, port;
431  int transport = -1;
432  const char *priority;
433  tree_cell *retc;
434 
435  to = get_int_local_var_by_name (lexic, "timeout", lexic->recv_timeout * 2);
436  if (to < 0)
437  to = 10;
438 
439  transport = get_int_local_var_by_name (lexic, "transport", -1);
440 
441  if (transport == OPENVAS_ENCAPS_TLScustom)
442  {
443  int type;
444  priority = get_str_local_var_by_name (lexic, "priority");
445  if (!priority)
446  priority = NULL;
447  type = get_local_var_type_by_name (lexic, "priority");
448  if (type != VAR2_STRING && type != VAR2_DATA)
449  priority = NULL;
450  }
451  else
452  priority = NULL;
453 
454  if (bufsz < 0)
455  bufsz = get_int_local_var_by_name (lexic, "bufsz", 0);
456 
457  port = get_int_var_by_num (lexic, 0, -1);
458  if (port < 0)
459  return NULL;
460 
461  wait_before_next_probe ();
462 
463  /* If "transport" has not been given, use auto detection if enabled
464  in the KB. if "transport" has been given with a value of 0 force
465  autodetection reagardless of what the KB tells. */
466  if (transport < 0)
467  soc = open_stream_auto_encaps_ext (script_infos, port, to, 0);
468  else if (transport == 0)
469  soc = open_stream_auto_encaps_ext (script_infos, port, to, 1);
470  else
471  soc = open_stream_connection_ext (script_infos, port, transport, to,
472  priority);
473  if (bufsz > 0 && soc >= 0)
474  {
475  if (stream_set_buffer (soc, bufsz) < 0)
476  nasl_perror (lexic, "stream_set_buffer: soc=%d,bufsz=%d\n", soc, bufsz);
477  }
478 
479  retc = alloc_tree_cell (0, NULL);
480  retc->type = CONST_INT;
481  retc->x.i_val = soc < 0 ? 0 : soc;
482 
483  return retc;
484 }
int open_stream_connection_ext(struct arglist *args, unsigned int port, int transport, int timeout, const char *priority)
Definition: network.c:1004
short type
Definition: nasl_tree.h:107
int open_stream_auto_encaps_ext(struct arglist *args, unsigned int port, int timeout, int force)
Definition: network.c:1127
int stream_set_buffer(int fd, int sz)
Definition: network.c:2163
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
char * get_str_local_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1262
union TC::@7 x
int type
Definition: arglists.h:34
Definition: nasl_tree.h:105
int get_local_var_type_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1322
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition: nasl_var.c:1226
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
struct arglist * script_infos
Definition: nasl_lex_ctxt.h:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nasl_open_sock_udp()

tree_cell* nasl_open_sock_udp ( lex_ctxt lexic)

Definition at line 539 of file nasl_socket.c.

References alloc_tree_cell(), CONST_INT, get_int_var_by_num(), TC::i_val, lowest_socket, openvas_source_set_socket(), plug_get_host_ip(), struct_lex_ctxt::script_infos, TC::type, and TC::x.

540 {
541  int soc;
542  tree_cell *retc;
543  int port;
544  struct sockaddr_in soca;
545  struct sockaddr_in6 soca6;
546  struct arglist *script_infos = lexic->script_infos;
547  struct in6_addr *ia;
548 
549  port = get_int_var_by_num (lexic, 0, -1);
550  if (port < 0)
551  return NULL;
552 
553  ia = plug_get_host_ip (script_infos);
554  if (ia == NULL)
555  return NULL;
556  if (IN6_IS_ADDR_V4MAPPED (ia))
557  {
558  bzero (&soca, sizeof (soca));
559  soca.sin_addr.s_addr = ia->s6_addr32[3];
560  soca.sin_port = htons (port);
561  soca.sin_family = AF_INET;
562 
563  soc = socket (AF_INET, SOCK_DGRAM, 0);
564  openvas_source_set_socket (soc, 0, AF_INET);
565  connect (soc, (struct sockaddr *) &soca, sizeof (soca));
566  }
567  else
568  {
569  bzero (&soca6, sizeof (soca6));
570  memcpy (&soca6.sin6_addr, ia, sizeof (struct in6_addr));
571  soca6.sin6_port = htons (port);
572  soca6.sin6_family = AF_INET6;
573 
574  soc = socket (AF_INET6, SOCK_DGRAM, 0);
575  openvas_source_set_socket (soc, 0, AF_INET6);
576  connect (soc, (struct sockaddr *) &soca6, sizeof (soca6));
577  }
578 
579  if (soc > 0 && lowest_socket == 0)
580  lowest_socket = soc;
581 
582  retc = alloc_tree_cell (0, NULL);
583  retc->type = CONST_INT;
584  retc->x.i_val = soc < 0 ? 0 : soc;
585  return retc;
586 }
short type
Definition: nasl_tree.h:107
union TC::@7 x
int lowest_socket
Definition: nasl_socket.c:223
Definition: nasl_tree.h:105
struct in6_addr * plug_get_host_ip(struct arglist *desc)
Definition: plugutils.c:216
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition: nasl_var.c:1226
int openvas_source_set_socket(int socket, int port, int family)
Binds a socket to use the global source address.
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
struct arglist * script_infos
Definition: nasl_lex_ctxt.h:39
Here is the call graph for this function:

◆ nasl_recv()

tree_cell* nasl_recv ( lex_ctxt lexic)

Definition at line 726 of file nasl_socket.c.

References fd_is_stream(), get_int_local_var_by_name(), struct_lex_ctxt::recv_timeout, and timeval().

727 {
728  char *data;
729  int len = get_int_local_var_by_name (lexic, "length", -1);
730  int min_len = get_int_local_var_by_name (lexic, "min", -1);
731  int soc = get_int_local_var_by_name (lexic, "socket", 0);
732  int to = get_int_local_var_by_name (lexic, "timeout", lexic->recv_timeout);
733  fd_set rd;
734  struct timeval tv;
735  int new_len = 0;
736  int type = -1;
737  unsigned int opt_len = sizeof (type);
738  int e;
739 
740  if (len <= 0 || soc <= 0)
741  return NULL;
742 
743  tv.tv_sec = to;
744  tv.tv_usec = 0;
745 
746  data = g_malloc0 (len);
747  if (!fd_is_stream (soc))
748  e = getsockopt (soc, SOL_SOCKET, SO_TYPE, &type, &opt_len);
749  else
750  e = -1;
751 
752  if (e == 0 && type == SOCK_DGRAM)
753  {
754  /* As UDP packets may be lost, we retry up to 5 times */
755  int retries = 5;
756  int i;
757 
758  tv.tv_sec = to / retries;
759  tv.tv_usec = (to % retries) * 100000;
760 
761  for (i = 0; i < retries; i++)
762  {
763  FD_ZERO (&rd);
764  FD_SET (soc, &rd);
765 
766  if (select (soc + 1, &rd, NULL, NULL, &tv) > 0)
767  {
768  int e;
769  e = recv (soc, data + new_len, len - new_len, 0);
770 
771  if (e <= 0)
772  {
773  if (!new_len)
774  {
775  g_free (data);
776  return NULL;
777  }
778  else
779  break;
780  }
781  else
782  new_len += e;
783 
784  if (new_len >= len)
785  break;
786 
787  break; /* UDP data is never fragmented */
788  }
789  else
790  {
791  /* The packet may have been lost en route - we resend it */
792  char *data;
793  int len;
794 
795  data = get_udp_data (lexic->script_infos, soc, &len);
796  if (data != NULL)
797  send (soc, data, len, 0);
798  tv.tv_sec = to / retries;
799  tv.tv_usec = (to % retries) * 100000;
800  }
801  }
802  }
803  else
804  {
805  int old = stream_set_timeout (soc, tv.tv_sec);
806  new_len = read_stream_connection_min (soc, data, min_len, len);
807  stream_set_timeout (soc, old);
808  }
809  if (new_len > 0)
810  {
811  tree_cell *retc = alloc_tree_cell (0, NULL);
812  retc->type = CONST_DATA;
813  retc->x.str_val = g_memdup (data, new_len);
814  retc->size = new_len;
815  g_free (data);
816  return retc;
817  }
818  else
819  {
820  g_free (data);
821  return NULL;
822  }
823 }
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
union TC::@7 x
int fd_is_stream(int fd)
Definition: network.c:2146
int read_stream_connection_min(int fd, void *buf0, int min_len, int max_len)
Definition: network.c:1360
Definition: nasl_tree.h:105
struct timeval timeval(unsigned long val)
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
struct arglist * script_infos
Definition: nasl_lex_ctxt.h:39
int stream_set_timeout(int fd, int timeout)
Definition: network.c:1158
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ nasl_recv_line()

tree_cell* nasl_recv_line ( lex_ctxt lexic)

Definition at line 828 of file nasl_socket.c.

References alloc_tree_cell(), CONST_DATA, fd_is_stream(), get_int_local_var_by_name(), nasl_perror(), read_stream_connection_min(), TC::size, TC::str_val, stream_get_buffer_sz(), stream_set_buffer(), TC::type, and TC::x.

829 {
830  int len = get_int_local_var_by_name (lexic, "length", -1);
831  int soc = get_int_local_var_by_name (lexic, "socket", 0);
832  int timeout = get_int_local_var_by_name (lexic, "timeout", -1);
833  char *data;
834  int new_len = 0;
835  int n = 0;
836  tree_cell *retc;
837  time_t t1 = 0;
838 
839  if (len == -1 || soc <= 0)
840  {
841  nasl_perror (lexic, "recv_line: missing or undefined parameter"
842  " length or socket\n");
843  return NULL;
844  }
845 
846  if (timeout >= 0) /* sycalls are much more expensive than simple tests */
847  t1 = time (NULL);
848 
849  if (fd_is_stream (soc) != 0)
850  {
851  int bufsz = stream_get_buffer_sz (soc);
852  if (bufsz <= 0)
853  stream_set_buffer (soc, len + 1);
854  }
855 
856  data = g_malloc0 (len + 1);
857  for (;;)
858  {
859  int e = read_stream_connection_min (soc, data + n, 1, 1);
860  if (e < 0)
861  break;
862  if (e == 0)
863  {
864  if (timeout >= 0 && time (NULL) - t1 < timeout)
865  continue;
866  else
867  break;
868  }
869  n++;
870  if ((data[n - 1] == '\n') || (n >= len))
871  break;
872  }
873 
874 
875 
876  if (n <= 0)
877  {
878  g_free (data);
879  return NULL;
880  }
881 
882  new_len = n;
883 
884 
885 
886  retc = alloc_tree_cell (0, NULL);
887  retc->type = CONST_DATA;
888  retc->size = new_len;
889  retc->x.str_val = g_memdup (data, new_len + 1);
890 
891  g_free (data);
892 
893  return retc;
894 }
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
int stream_set_buffer(int fd, int sz)
Definition: network.c:2163
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
union TC::@7 x
int fd_is_stream(int fd)
Definition: network.c:2146
int read_stream_connection_min(int fd, void *buf0, int min_len, int max_len)
Definition: network.c:1360
Definition: nasl_tree.h:105
int stream_get_buffer_sz(int fd)
Definition: network.c:2153
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ nasl_send()

tree_cell* nasl_send ( lex_ctxt lexic)

Definition at line 899 of file nasl_socket.c.

References fd_is_stream(), get_int_local_var_by_name(), get_str_local_var_by_name(), get_var_size_by_name(), nasl_perror(), and option.

Referenced by nasl_send_capture().

900 {
901  int soc = get_int_local_var_by_name (lexic, "socket", 0);
902  char *data = get_str_local_var_by_name (lexic, "data");
903  int option = get_int_local_var_by_name (lexic, "option", 0);
904  int length = get_int_local_var_by_name (lexic, "length", 0);
905  int data_length = get_var_size_by_name (lexic, "data");
906  int n;
907  tree_cell *retc;
908  int type;
909  unsigned int type_len = sizeof (type);
910 
911 
912  if (soc <= 0 || data == NULL)
913  {
914  nasl_perror (lexic, "Syntax error with the send() function\n");
915  nasl_perror (lexic,
916  "Correct syntax is : send(socket:<soc>, data:<data>\n");
917  return NULL;
918  }
919 
920  if (length <= 0 || length > data_length)
921  length = data_length;
922 
923 
924  if (!fd_is_stream (soc)
925  && getsockopt (soc, SOL_SOCKET, SO_TYPE, &type, &type_len) == 0
926  && type == SOCK_DGRAM)
927  {
928  n = send (soc, data, length, option);
929  add_udp_data (lexic->script_infos, soc, data, length);
930  }
931  else
932  {
933  wait_before_next_probe ();
934  n = nsend (soc, data, length, option);
935  }
936 
937  retc = alloc_tree_cell (0, NULL);
938  retc->type = CONST_INT;
939  retc->x.i_val = n;
940 
941  return retc;
942 }
short type
Definition: nasl_tree.h:107
#define option
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
char * get_str_local_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1262
union TC::@7 x
int fd_is_stream(int fd)
Definition: network.c:2146
int nsend(int fd, void *data, int length, int i_opt)
Definition: network.c:1577
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
struct arglist * script_infos
Definition: nasl_lex_ctxt.h:39
int get_var_size_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1291
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nasl_socket_get_cert()

tree_cell* nasl_socket_get_cert ( lex_ctxt lexic)

Definition at line 623 of file nasl_socket.c.

References alloc_tree_cell(), CONST_DATA, get_int_local_var_by_name(), nasl_perror(), TC::size, socket_get_cert(), TC::str_val, TC::type, and TC::x.

624 {
625  int soc, cert_len = 0;
626  tree_cell *retc;
627  void *cert;
628 
629  soc = get_int_local_var_by_name (lexic, "socket", -1);
630  if (soc < 0)
631  {
632  nasl_perror (lexic, "socket_get_cert: Erroneous socket value %d\n",
633  soc);
634  return NULL;
635  }
636  socket_get_cert (soc, &cert, &cert_len);
637  if (cert_len <= 0)
638  return NULL;
639  retc = alloc_tree_cell (0, NULL);
640  retc->type = CONST_DATA;
641  retc->x.str_val = cert;
642  retc->size = cert_len;
643  return retc;
644 }
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
union TC::@7 x
void socket_get_cert(int fd, void **cert, int *certlen)
Definition: network.c:813
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ nasl_socket_get_error()

tree_cell* nasl_socket_get_error ( lex_ctxt lexic)

Definition at line 1137 of file nasl_socket.c.

References alloc_typed_cell(), CONST_INT, err, fd_is_stream(), get_int_var_by_num(), TC::i_val, log_legacy_write(), NASL_ERR_ECONNRESET, NASL_ERR_ETIMEDOUT, NASL_ERR_EUNREACH, NASL_ERR_NOERR, stream_get_err(), and TC::x.

1138 {
1139  int soc = get_int_var_by_num (lexic, 0, -1);
1140  tree_cell *retc;
1141  int err;
1142 
1143  if (soc < 0 || !fd_is_stream (soc))
1144  return NULL;
1145 
1146  err = stream_get_err (soc);
1147  retc = alloc_typed_cell (CONST_INT);
1148 
1149  switch (err)
1150  {
1151  case 0:
1152  retc->x.i_val = NASL_ERR_NOERR;
1153  break;
1154  case ETIMEDOUT:
1155  retc->x.i_val = NASL_ERR_ETIMEDOUT;
1156  break;
1157  case EBADF:
1158  case EPIPE:
1159  case ECONNRESET:
1160  case ENOTSOCK:
1161  retc->x.i_val = NASL_ERR_ECONNRESET;
1162  break;
1163 
1164  case ENETUNREACH:
1165  case EHOSTUNREACH:
1166  retc->x.i_val = NASL_ERR_EUNREACH;
1167  break;
1168 
1169  default:
1170  log_legacy_write ("Unknown error %d %s\n", err, strerror (err));
1171  }
1172 
1173  return retc;
1174 }
#define err(x)
#define NASL_ERR_ETIMEDOUT
Definition: nasl.h:68
#define NASL_ERR_ECONNRESET
Definition: nasl.h:69
#define NASL_ERR_NOERR
Definition: nasl.h:67
#define NASL_ERR_EUNREACH
Definition: nasl.h:70
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
union TC::@7 x
int fd_is_stream(int fd)
Definition: network.c:2146
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:53
Definition: nasl_tree.h:105
int stream_get_err(int fd)
Definition: network.c:161
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition: nasl_var.c:1226
long int i_val
Definition: nasl_tree.h:114
Here is the call graph for this function:

◆ nasl_socket_get_ssl_ciphersuite()

tree_cell* nasl_socket_get_ssl_ciphersuite ( lex_ctxt lexic)

Definition at line 708 of file nasl_socket.c.

References alloc_tree_cell(), CONST_INT, get_int_local_var_by_name(), TC::i_val, socket_get_ssl_ciphersuite(), TC::type, and TC::x.

709 {
710  int soc, result;
711  tree_cell *retc;
712 
713  soc = get_int_local_var_by_name (lexic, "socket", -1);
714  result = socket_get_ssl_ciphersuite (soc);
715  if (result < 0)
716  return NULL;
717  retc = alloc_tree_cell (0, NULL);
718  retc->type = CONST_INT;
719  retc->x.i_val = result;
720  return retc;
721 }
short type
Definition: nasl_tree.h:107
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
union TC::@7 x
Definition: nasl_tree.h:105
int socket_get_ssl_ciphersuite(int fd)
Definition: network.c:965
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
Here is the call graph for this function:

◆ nasl_socket_get_ssl_compression()

tree_cell* nasl_socket_get_ssl_compression ( lex_ctxt lexic)

Definition at line 672 of file nasl_socket.c.

References alloc_tree_cell(), CONST_INT, get_int_local_var_by_name(), TC::i_val, nasl_perror(), socket_get_ssl_compression(), TC::type, and TC::x.

673 {
674  int soc;
675  tree_cell *retc;
676 
677  soc = get_int_local_var_by_name (lexic, "socket", -1);
678  if (soc < 0)
679  {
680  nasl_perror (lexic, "socket_get_cert: Erroneous socket value %d\n",
681  soc);
682  return NULL;
683  }
684  retc = alloc_tree_cell (0, NULL);
685  retc->type = CONST_INT;
686  retc->x.i_val = socket_get_ssl_compression (soc);
687  return retc;
688 }
short type
Definition: nasl_tree.h:107
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
union TC::@7 x
int socket_get_ssl_compression(int fd)
Definition: network.c:930
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
Here is the call graph for this function:

◆ nasl_socket_get_ssl_session_id()

tree_cell* nasl_socket_get_ssl_session_id ( lex_ctxt lexic)

Definition at line 647 of file nasl_socket.c.

References alloc_tree_cell(), CONST_DATA, get_int_local_var_by_name(), nasl_perror(), TC::size, socket_get_ssl_session_id(), TC::str_val, TC::type, and TC::x.

648 {
649  int soc;
650  size_t sid_len = 0;
651  tree_cell *retc;
652  void *sid;
653 
654  soc = get_int_local_var_by_name (lexic, "socket", -1);
655  if (soc < 0)
656  {
657  nasl_perror (lexic, "socket_get_cert: Erroneous socket value %d\n",
658  soc);
659  return NULL;
660  }
661  socket_get_ssl_session_id (soc, &sid, &sid_len);
662  if (sid == NULL || sid_len == 0)
663  return NULL;
664  retc = alloc_tree_cell (0, NULL);
665  retc->type = CONST_DATA;
666  retc->x.str_val = sid;
667  retc->size = sid_len;
668  return retc;
669 }
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
union TC::@7 x
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
void socket_get_ssl_session_id(int fd, void **sid, size_t *ssize)
Definition: network.c:890
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ nasl_socket_get_ssl_version()

tree_cell* nasl_socket_get_ssl_version ( lex_ctxt lexic)

Definition at line 691 of file nasl_socket.c.

References alloc_tree_cell(), CONST_INT, get_int_local_var_by_name(), TC::i_val, socket_get_ssl_version(), TC::type, and TC::x.

692 {
693  int soc;
694  int version;
695  tree_cell *retc;
696 
697  soc = get_int_local_var_by_name (lexic, "socket", -1);
698  version = socket_get_ssl_version (soc);
699  if (version < 0)
700  return NULL;
701  retc = alloc_tree_cell (0, NULL);
702  retc->type = CONST_INT;
703  retc->x.i_val = version;
704  return retc;
705 }
short type
Definition: nasl_tree.h:107
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
union TC::@7 x
int socket_get_ssl_version(int fd)
Definition: network.c:849
Definition: nasl_tree.h:105
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
Here is the call graph for this function:

◆ nasl_socket_negotiate_ssl()

tree_cell* nasl_socket_negotiate_ssl ( lex_ctxt lexic)

Definition at line 589 of file nasl_socket.c.

References alloc_tree_cell(), CONST_INT, get_int_local_var_by_name(), TC::i_val, IS_ENCAPS_SSL, nasl_perror(), OPENVAS_ENCAPS_TLScustom, struct_lex_ctxt::script_infos, socket_negotiate_ssl(), TC::type, and TC::x.

590 {
591  int soc, transport, ret;
592  tree_cell *retc;
593 
594 
595  soc = get_int_local_var_by_name (lexic, "socket", -1);
596  transport = get_int_local_var_by_name (lexic, "transport",
598  if (soc < 0)
599  {
600  nasl_perror (lexic, "socket_ssl_negotiate: Erroneous socket value %d\n",
601  soc);
602  return NULL;
603  }
604  if (transport == -1)
605  transport = OPENVAS_ENCAPS_TLScustom;
606  else if (!IS_ENCAPS_SSL (transport))
607  {
608  nasl_perror (lexic, "socket_ssl_negotiate: Erroneous transport value %d\n",
609  transport);
610  return NULL;
611  }
612  ret = socket_negotiate_ssl (soc, transport, lexic->script_infos);
613  if (ret < 0)
614  return NULL;
615 
616  retc = alloc_tree_cell (0, NULL);
617  retc->type = CONST_INT;
618  retc->x.i_val = ret;
619  return retc;
620 }
short type
Definition: nasl_tree.h:107
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
union TC::@7 x
#define IS_ENCAPS_SSL(x)
Definition: network.h:64
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
int socket_negotiate_ssl(int fd, openvas_encaps_t transport, struct arglist *args)
Definition: network.c:771
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
struct arglist * script_infos
Definition: nasl_lex_ctxt.h:39
Here is the call graph for this function:

Variable Documentation

◆ lowest_socket

int lowest_socket = 0

Definition at line 223 of file nasl_socket.c.

Referenced by nasl_open_sock_udp().