#!/bin/sh

# Checking if IPv6 is supported.

. $(dirname $0)/../test_library

start() {
  ../../src/stunnel -fd 0 <<EOT
  debug = debug
  syslog = no
  pid = ${result_path}/stunnel.pid
  output = ${result_path}/stunnel.log

  [client]
  client = yes
  accept = 127.0.0.1:${http1}
  connect = ::1:${https1}

  [server]
  accept = ::1:${https1}
  connect = 127.0.0.1:${http_nc}
  cert = ${script_path}/certs/server_cert.pem
EOT
}

# nc does not support IPv6
if grep -q "IPv6" "results.log" && \
   (([ -n "$(command -v ip)" ] && PATH="${PATH}:/sbin:/usr/sbin" ip address | grep -q "inet6") || \
   ([ -n "$(command -v ifconfig)" ] && PATH="${PATH}:/sbin:/usr/sbin" ifconfig | grep -q "inet6"))
  then
    test_log_for "020_IPv6" "success" "0" "$1" "$2" "$3" 2>> "stderr.log"
    exit $?
  else
    exit_logs "020_IPv6" "skipped"
    clean_logs
    exit 125
  fi
