#!/bin/bash
# Author: Steven Shiau <steven _at_ clonezilla org>
# License: GPL
# This script is used in DRBL client to show the port of client which is connected to DRBL server. It can be used for more than one NIC or alias IP addresses.

# Load DRBL setting and functions
DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"

. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions

#
if [ -f /etc/diskless-image/config ]; then
   # Load config file
   . /etc/diskless-image/config
else
   exit 1
fi
   
PORT_LISTS="$(get-nic-devs)"

IP_link_2_srv="$(get-ip-link-2-drbl-srv)"
for i in $PORT_LISTS; do
  ip="$(drbl-get-ipadd $i)"
  if [ "$ip" = "$IP_link_2_srv" ]; then
    echo "$i"
    break
  fi
done
