Skip to content

Commit

Permalink
Merge pull request #145 from emartinez-dev/fix-#144
Browse files Browse the repository at this point in the history
bugfix #144: make exam06 compatible with MacOS
  • Loading branch information
JCluzet authored Dec 26, 2023
2 parents bbfb668 + bc18c47 commit a6233ca
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
1 change: 0 additions & 1 deletion .subjects/STUD_PART/exam_06/0/mini_serv/catchmsg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# close fd before init
exec 6<&-
nc localhost $1
exec 6</dev/tcp/localhost/"$1"

while read -r <&6
Expand Down
10 changes: 8 additions & 2 deletions .subjects/STUD_PART/exam_06/0/mini_serv/findport.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ if [ -z "$last_port" ]
then
last_port=9999
fi
function scanner

if [ $(uname) == "Darwin" ]; then
checkport_tool='lsof -i -n -P'
else
checkport_tool='ss -tuln'
fi

function scanner
{
for ((port="$first_port"; port<="$last_port"; port++))
do
checkport=`ss -tuln | grep $port`
checkport=`eval $checkport_tool | grep $port`
if [ -z "$checkport" ]; then
goodport=$port
break
Expand Down
8 changes: 7 additions & 1 deletion .subjects/STUD_PART/exam_06/0/mini_serv/test_eof.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
if [ $(uname) == "Darwin" ]; then
nc_command="nc localhost $1"
else
nc_command="nc -q 0 localhost $1"
fi

for x in `cat eof_test`; do
printf $x
sleep 0.1
done | nc -q 0 localhost $1
done | eval $nc_command
24 changes: 15 additions & 9 deletions .subjects/STUD_PART/exam_06/0/mini_serv/test_miniserv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ if [ -e final ]; then

sleep 1

PORTOPEN=`ss -tuln | grep "$1"`
if [ $(uname) == "Darwin" ]; then
PORTOPEN=`lsof -i -n -P | grep "$1"`
nc_command="nc localhost $1"
else
PORTOPEN=`ss -tuln | grep "$1"`
nc_command="nc -q 0 localhost $1"
fi

# if it's open, then we can test the program
if [ -z "$PORTOPEN" ]; then
Expand All @@ -40,27 +46,27 @@ bash catchmsg.sh $1 >> bim &

sleep 1

echo "Si vous ne voyez QUE ce message, c'est mauvais signe." | nc -q 0 localhost $1
echo "Si vous ne voyez QUE ce message, c'est mauvais signe." | eval $nc_command
sleep 0.2
echo "Bienvenue sur le test de votre miniserv" | nc -q 0 localhost $1
echo "Bienvenue sur le test de votre miniserv" | eval $nc_command
sleep 0.2
echo "Ceci est un message" | nc -q 0 localhost $1
echo "Ceci est un message" | eval $nc_command
sleep 0.2
printf "Voici un texte sans retour a la ligne" | nc -q 0 localhost $1
printf "Voici un texte sans retour a la ligne" | eval $nc_command
sleep 0.2
echo -n "This is a text without backline at the end" | nc -q 0 localhost $1
echo -n "This is a text without backline at the end" | eval $nc_command
sleep 0.4
printf "Et voici un texte avec plusieurs\nretours\na\nla\nligne\n" | nc -q 0 localhost $1
printf "Et voici un texte avec plusieurs\nretours\na\nla\nligne\n" | eval $nc_command
sleep 0.2

bash test_eof.sh $1
sleep 1

cat very_long_msg.txt | nc -q 0 localhost $1
cat very_long_msg.txt | eval $nc_command

sleep 1

cat other_long_msg.txt | nc -q 0 localhost $1
cat other_long_msg.txt | eval $nc_command

sleep 2

Expand Down

0 comments on commit a6233ca

Please sign in to comment.