level 1 test updated (completely rewritten)
authorJan Pospíšil <honik@ntc.zcu.cz>
Tue, 29 Jul 2008 19:58:58 +0000 (19:58 +0000)
committerJan Pospíšil <honik@ntc.zcu.cz>
Tue, 29 Jul 2008 19:58:58 +0000 (19:58 +0000)
org.glite.testsuites.ctb/LB/Readme.txt
org.glite.testsuites.ctb/LB/lb-common.sh [new file with mode: 0755]
org.glite.testsuites.ctb/LB/lb-l1.sh
org.glite.testsuites.ctb/LB/test-common.sh [new file with mode: 0644]
org.glite.testsuites.ctb/LB/testSocket.c

index 1a7033f..424e322 100644 (file)
@@ -1,53 +1,48 @@
-
-
-Readme file for lb1 v1.0*************************************
-Date: 19.03.2007                                       *               
-Author:                                                        *
-*************************************************************
+$Header$
+Readme file for lb1 v1.0
 
 lb-l1.sh
 ********
 
 Script for testing of LB services 
 
-* Prerequisities: All services running (user does not have to get any credentials)
+* Prerequisities: 
+   - All services running (user does not have to get any credentials)
+   - the following environment variables set:
 
-* Basic test:  PING
-                               check LB binaries
-                               check running services
-* Options:
- -h | --help                   Show this help message.
- -m | --m lb_host
- -g | --log 'logfile'          Redirect all output to the 'logfile'.
-* The name of the bkserver has to be specified everytime
+     GLITE_WMS_LOG_DESTINATION - address of local logger, in form 'host:port'
+     GLITE_WMS_QUERY_SERVER - address of LB server, in form 'host:port'
+
+* Basic test:
+   PING
+   check LB binaries
+   check running services
+
+Usage: lb-l1.sh [OPTIONS] host
+Options:
+ -h | --help            Show this help message.
+ -o | --output 'file'   Redirect all output to the 'file' (stdout by default).
+ -t | --text            Format output as plain ASCII text.
+ -c | --color           Format output as text with ANSI colours (autodetected by default).
+ -x | --html            Format output as html.
+
+* The name of the bkserver host has to be specified everytime
  
  
 Examples
 ********
 
-[ui] /home/fmunster> ./lb-l1.sh -g log
-USAGE: TCPecho <server_ip> <port>
-
-[ui] /home/fmunster> ./lb-l1.sh -g log -m gliterb.iihe.ac.be
-
-[ui] /home/fmunster> cat log
-
-Basic services test......
-Checking binary glite-lb-job_reg ?      OK
-Checking binary glite-lb-job_log ?      OK
-Checking binary glite-lb-logevent ?     OK
-Checking binary glite-lb-user_jobs ?    OK
-Checking binary glite-lb-job_status ?   OK
-Checking binary glite-lb-change_acl ?   OK
-Checking binary glite-lb-lbmon          OK
-Listening to locallogger port (9002)
-Connecting a socket with : 193.190.246.245,9002 [OK]
-glite-lb-logd running ? -                         [OK]
-Listening to interlogger ports (9000-9001-9003)
-Connecting a socket with : 193.190.246.245,9000 [OK]
-Connecting a socket with : 193.190.246.245,9001 [OK]
-Connecting a socket with : 193.190.246.245,9003 [OK]
-Interlogd running ? -               [OK]
-
+$ ./lb-l1.sh -o log scientific.civ.zcu.cz
+
+Jul 29 21:57:24 scientific lb-l1.sh:                                 start 
+Testing ping to LB server sci.civ.zcu.cz                             done
+Testing LB binaries:
+  checking binary glite-lb-logevent                                  done
+  checking binary glite-lb-job_log                                   done
+  checking binary glite-lb-job_reg                                   done
+  checking binary glite-lb-user_jobs                                 done
+  checking binary glite-lb-job_status                                done
+  checking binary glite-lb-change_acl                                done
+Testing LB services                                                  skipped
+Jul 29 21:57:26 scientific lb-l1.sh:                                 end 
 
diff --git a/org.glite.testsuites.ctb/LB/lb-common.sh b/org.glite.testsuites.ctb/LB/lb-common.sh
new file mode 100755 (executable)
index 0000000..12ccce5
--- /dev/null
@@ -0,0 +1,128 @@
+# $Header$
+# ------------------------------------------------------------------------------
+# Definitions of functions and variables common to LB test scripts
+#
+#   ping_host()
+#   check_exec()
+#   check_binaries()
+#
+# ------------------------------------------------------------------------------
+
+# read common definitions and functions
+TEST_COMMON=test-common.sh
+if [ ! -r ${TEST_COMMON} ]; then
+       printf "Common definitions '${TEST_COMMON}' not found!\n"
+       exit 2  
+fi
+. ${TEST_COMMON}
+
+# define variables
+GLITE_LOCATION=${GLITE_LOCATION:-/opt/glite}
+PATH=$GLITE_LOCATION/bin:$GLITE_LOCATION/examples:$PATH
+export PATH
+
+LBLOGEVENT=glite-lb-logevent
+LBJOBLOG=glite-lb-job_log
+LBJOBREG=glite-lb-job_reg
+LBUSERJOBS=glite-lb-user_jobs
+LBJOBSTATUS=glite-lb-job_status
+LBPURGE=glite-lb-purge
+LBCHANGEACL=glite-lb-change_acl
+LBMON=glite-lb-lbmon
+
+LB_LOGD=glite-lb-logd 
+LB_INTERLOGD=glite-lb-interlogd
+LB_SERVER=glite-lb-bkserverd
+
+TEST_SOCKET=$SAME_SENSOR_HOME/tests/testSocket
+
+DEBUG=2
+
+# ping host
+function ping_host()
+{
+       if [ -z $1 ]; then
+               print_newline
+               print_error "No host to ping"
+               return $TEST_ERROR
+       fi
+       PING_HOST=$1
+       # XXX: there might be a better way to test the network reachability
+       result=`ping -c 3 $PING_HOST 2>/dev/null | grep " 0% packet loss"| wc -l`
+       if [ $result -gt 0 ]; then
+               return $TEST_OK
+       else 
+               return $TEST_ERROR
+       fi
+}
+
+
+# check the binaries
+function check_exec()
+{
+       if [ -z $1 ]; then
+               print_newline
+               print_error "No binary to check"
+               return $TEST_ERROR
+       fi
+       # XXX: maybe use bash's command type?
+       local ret=`which $1`
+       if [ $? -eq 0 ] && [ -x $ret ]; then 
+               return $TEST_OK
+       else
+               return $TEST_ERROR
+       fi
+}
+
+function check_binaries()
+{
+       local err=0
+       for file in $LBLOGEVENT $LBJOBLOG $LBJOBREG $LBUSERJOBS $LBJOBSTATUS $LBCHANGEACL
+       do      
+               printf "  checking binary %s" "$file"
+               check_exec $file 
+               if [ $? -eq 0 ]; then
+                       test_done
+               else
+                       test_failed
+                       print_error "file $file not found"
+                       err=1
+               fi
+       done
+       if [ $err -eq 0 ];  then 
+               return $TEST_OK
+       else
+               return $TEST_ERROR
+       fi
+}
+
+# check the services
+check_services()
+{
+       echo "${newline:-}Listening to locallogger port (9002)" >> $logfile
+       $TEST_SOCKET $LB_HOST 9002 >> $logfile
+       if [ $? -eq 0 ]; then
+               echo "${newline:-}logd running ? -                         [OK]" >> $logfile
+       else 
+               echo "${newline:-}logd running ? -                      [FAILED]" >> $logfile
+               exit $TEST_ERROR
+       fi
+       echo "${newline:-}Listening to LB server ports (9000-9001)${linebreak:-}" >> $logfile
+       $TEST_SOCKET $LB_HOST 9000 >> $logfile &&
+       $TEST_SOCKET $LB_HOST 9001 >> $logfile 
+       if [ $? -eq 0 ]; then
+               echo "${newline:-}LB server running ? -               [OK]" >> $logfile
+       else 
+               echo "${newline:-}LB server running ? -            [FAILED]" >> $logfile
+               exit $TEST_ERROR
+       fi
+       echo "${newline:-}Listening to LB server WS port (9003)${linebreak:-}" >> $logfile
+       $TEST_SOCKET $LB_HOST 9003 >> $logfile 
+       if [ $? -eq 0 ]; then
+               echo "${newline:-}LB server running with WS ? -               [OK]" >> $logfile
+       else 
+               echo "${newline:-}LB server running with WS ? -            [FAILED]" >> $logfile
+               exit $TEST_ERROR
+       fi
+}
+
index 699e500..5d78935 100755 (executable)
 #!/bin/bash
-##########################################################################################
-# Script for testing of LB services 
-# Basic test: PING
-#             check LB binaries
-#             check running services with sockets
-#####################################################################################
-#                                                              #
-# Returned values:                                             #
-#                                                              #
-#                 Exit  TEST_OK: Test Passed                   #
-#                 Exit  TEST_ERROR: Test Failed                #
-#                 Exit  2: Wrong Input                         #
-#                                                              #
-# Authors: Shkelzen Rugovac, Frederic Munster, Othmane Bouhali #
-################################################################
+# $Header$
+# ------------------------------------------------------------------------------
+# Script for testing the LB services 
+#
+# Basic test: 
+#     PING
+#     check LB binaries
+#     check running services with sockets
+#
+# Returned values:
+#     Exit TEST_OK: Test Passed
+#     Exit TEST_ERROR: Test Failed
+#     Exit 2: Wrong Input
+#
+# ------------------------------------------------------------------------------
                                                                                 
-##
-# defining variables
-########################"
-PATH=/opt/glite/examples:$PATH
-#echo $PATH
-LBLOGEV=${LBLOGEV:-glite-lb-logevent}
-LBJOBLOG=${LBJOBLOG:-glite-lb-job_log}
-LBJOBREG=${LBJOBREG:-glite-lb-job_reg}
-LBUSERJOBS=${LBUSERJOBS:-glite-lb-user_jobs}
-LBJOBSTAT=${LBJOBSTAT:-glite-lb-job_status}
-LBPURGE=${LBPURGE:-glite-lb-purge}
-LBCHANGEACL=${LBCHANGEACL:-glite-lb-change_acl}
-LBMON=${LBMON:-glite-lb-lbmon}
-LB_INTERLOGD=glite-lb-interlogd
-LB_LOGD=glite-lb-logd 
+# read common definitions and functions
+COMMON=lb-common.sh
+if [ ! -r ${COMMON} ]; then
+       printf "Common definitions '${COMMON}' missing!"
+       exit 2
+fi
+source ${COMMON}
+
 DEBUG=2
-##
+
 # show help and usage
-######################"
+progname=`basename $0`
 showHelp()
 {
-       echo  "Usage: $0 [OPTIONS] "
-       echo  "Options:"
-       echo  " -h | --help                   Show this help message."
-        echo  " -m | --m lb_host              hostName or IPV4 adress "
-       echo  " -g | --log 'logfile'          Redirect all output to the 'logfile'."
-       echo "-html | --html                  Format output for html."
-       echo  ""
-#      echo  "For proper operation check your grid-proxy-info"
-#      grid-proxy-info
+       echo "Usage: $progname [OPTIONS] host"
+       echo "Options:"
+       echo " -h | --help            Show this help message."
+       echo " -o | --output 'file'   Redirect all output to the 'file' (stdout by default)."
+       echo " -t | --text            Format output as plain ASCII text."
+       echo " -c | --color           Format output as text with ANSI colours (autodetected by default)."
+       echo " -x | --html            Format output as html."
+       echo ""
 }
 if [ -z "$1" ]; then
-  showHelp
-  exit 2
+       showHelp
+       exit 2
 fi
-logfile=output.log
+logfile=$$.tmp
 flag=0
 while test -n "$1"
 do
        case "$1" in
-       "-h" | "--help") showHelp && exit 2 ;;
-       "-m" | "--bkserver") shift ; LB_HOST=$1 ;;
-       "-g" | "--log") shift ; logfile=$1 flag=1 ;;
-        "-html" | "--html") newline="<br>" ;;
-       *) echo "Unrecognized option $1 try -h for help"; exit 2 ;;
-
+               "-h" | "--help") showHelp && exit 2 ;;
+               "-o" | "--output") shift ; logfile=$1 flag=1 ;;
+               "-t" | "--text")  setOutputASCII ;;
+               "-c" | "--color") setOutputColor ;;
+               "-x" | "--html")  setOutputHTML ;;
+               *) LB_HOST=$1 ;;
        esac
        shift
 done
 
+# redirecting all output to $logfile
+touch $logfile
+if [ ! -w $logfile ]; then
+       echo "Cannot write to output file $logfile"
+       exit $TEST_ERROR
+fi
 
 ##
-# Ping the LB_HOST
-######################
+#  Starting the test
+#####################
 
-function ping_host
 {
-  echo  "${newline:-} Testing ping to $LB_HOST " >> $logfile
-         result=`ping -c 5 $LB_HOST 2>/dev/null |  grep "0% packet loss"| wc -l`
-  if [ $result -gt 0 ]; then
-       echo "${newline:-}Pinging $LB_HOST                        OK$ " >> $logfile
-  else 
-    echo "${newline:-}" >> $logfile
-    echo "${newline:-}Ping failed: The $LB_HOST is not accessible! "  >> $logfile
-    echo "${newline:-}" >> $logfile
-    echo "${newline:-} LB Basic Test:                      Failed. " >> $logfile
-    exit $TEST_ERROR
-  fi
-#  echo "<font color="green"> - OK </font>"
-}
+test_start
 
-check_exec()
-{
-        [ $DEBUG -gt 0 ] && [ -n "$2" ] && echo -n -e "$2\t" >> $logfile || echo -n -e "$1\t" >> $logfile
-        eval $1
-        RV=$?
-        [ $DEBUG -gt 0 ] && [ $RV -eq 0 ] && echo "${newline:-}OK" >> $logfile || echo "${newline:-}FAILED" >> $logfile
-        return $RV
-}
+# ping_host:
+printf "Testing ping to LB server ${LB_HOST}"
+ping_host ${LB_HOST}
+if [ $? -gt 0 ]; then
+       test_failed
+       print_error "Destination host might be unreachable"
+else
+       test_done
+fi
+# check_binaries
+printf "Testing LB binaries:${lf}"
+check_binaries
 
-#
-# check the binaries
-#########################
-check_binaries()
-{
- check_exec 'LBJOBREG=`which $LBJOBREG`' "${newline:-}Checking binary $LBJOBREG ? " || exit 1
- check_exec 'LBJOBLOG=`which $LBJOBLOG`' "${newline:-}Checking binary $LBJOBLOG ? " || exit 1
- check_exec 'LBLOGEV=`which $LBLOGEV`' "${newline:-}Checking binary $LBLOGEV ?" || exit 1
- check_exec 'LBUSERJOBS=`which $LBUSERJOBS`' "${newline:-}Checking binary $LBUSERJOBS ?" || exit 1
- check_exec 'LBJOBSTAT=`which $LBJOBSTAT`' "${newline:-}Checking binary $LBJOBSTAT ? " || exit 1
- check_exec 'LBCHANGEACL=`which $LBCHANGEACL`' "${newline:-}Checking binary $LBCHANGEACL ?" || exit 1
- check_exec 'LBMON=`which $LBMON`' "${newline:-}Checking binary $LBMON " || exit 1
-}
-#
-# check the services
-##################"
-check_services()
-{
-echo "${newline:-}Listening to locallogger port (9002)" >> $logfile
-$SAME_SENSOR_HOME/tests/testSocket $LB_HOST 9002 >> $logfile
-if [ $? -eq 0 ]; then
- echo "${newline:-}logd running ? -                         [OK]" >> $logfile
- else 
-    echo "${newline:-}logd running ? -                      [FAILED]" >> $logfile
-    exit $TEST_ERROR
-  fi
-echo "${newline:-}Listening to interlogger ports (9000-9001-9003)${linebreak:-}" >> $logfile
-$SAME_SENSOR_HOME/tests/testSocket $LB_HOST 9000 >> $logfile &&
-$SAME_SENSOR_HOME/tests/testSocket $LB_HOST 9001 >> $logfile &&
-$SAME_SENSOR_HOME/tests/testSocket $LB_HOST 9003 >> $logfile 
-if [ $? -eq 0 ]; then
- echo "${newline:-}Interlogd running ? -               [OK]" >> $logfile
- else 
-    echo "${newline:-}interlogd running ? -            [FAILED]" >> $logfile
-    exit $TEST_ERROR
-  fi
-}
+# check_services
+printf "Testing LB services"
+#check_services
+test_skipped
 
-#####################
-#  Starting the test
-#####################
-ping_host
-check_binaries
-check_services
-if [ $flag -ne 1 ];then
-       cat $logfile
-       rm $logfile
+test_end
+} &> $logfile
+
+if [ $flag -ne 1 ]; then
+       cat $logfile
+       rm $logfile
 fi
 exit $TEST_OK
+
diff --git a/org.glite.testsuites.ctb/LB/test-common.sh b/org.glite.testsuites.ctb/LB/test-common.sh
new file mode 100644 (file)
index 0000000..a269bfc
--- /dev/null
@@ -0,0 +1,203 @@
+# $Header$
+# ------------------------------------------------------------------------------
+# Definition of test script return messages
+#
+#   The test scripts should use the variables test_done and test_failed to
+#   report whether they failed or succeeded. 
+#
+#   The variable test_reset is used to turn off all attributes and switch 
+#   to the standard character set.
+#
+#    \033          ascii ESCape
+#    \033[<NUM>G   move to column <NUM> (linux console, xterm, not vt100)
+#    \033[<NUM>C   move <NUM> columns forward but only upto last column
+#    \033[<NUM>D   move <NUM> columns backward but only upto first column
+#    \033[<NUM>A   move <NUM> rows up
+#    \033[<NUM>B   move <NUM> rows down
+#    \033[1m       switch on bold
+#    \033[31m      switch on red
+#    \033[32m      switch on green
+#    \033[33m      switch on yellow
+#    \033[m        switch off color/bold
+#    \017          exit alternate mode (xterm, vt100, linux console)
+#    \033[10m      exit alternate mode (linux console)
+#    \015          carriage return (without newline)
+#
+#   See also United Linux or OpenSUSE /etc/rc.status script
+#
+# ------------------------------------------------------------------------------
+
+# Do _not_ be fooled by non POSIX locale
+LC_ALL=POSIX
+export LC_ALL
+
+# Seek for terminal size and, if needed, set default size
+if [ -z "${LINES}" -o -z "${COLUMNS}" ]; then
+       stty_size=`stty size`
+       LINES=`echo ${stty_size} | awk '{print $1}'`
+       COLUMNS=`echo ${stty_size} | awk '{print $2}'`
+fi
+if [ ! $LINES -ge 0 ]; then LINES=24; fi
+if [ ! $COLUMNS -ge 0 ]; then COLUMNS=80; fi
+export LINES COLUMNS
+
+# default return values
+TEST_ERROR=1
+TEST_OK=0
+
+function set_test()
+{
+test_done="${spacefill}${begin_green}done${end_green}"
+test_running="${spacefill}${begin_green}running${end_green}"
+test_failed="${spacefill}${begin_red}failed${end_red}"
+test_missed="${spacefill}${begin_red}missing${end_red}"
+test_skipped="${spacefill}${begin_yellow}skipped${end_yellow}"
+test_dead="${spacefill}${begin_red}dead${end_red}"
+test_unused="${spacefill}${begin_bold}unused${end_bold}"
+test_unknown="${spacefill}${begin_yellow}unknown${end_yellow}"
+
+test_start="${spacefill}${begin_green}start${end_green}"
+test_end="${spacefill}${begin_green}end${end_green}"
+}
+
+function test_done()   { printf "${test_done}${lf}"; }
+function test_running()        { printf "${test_running}${lf}"; }
+function test_failed() { printf "${test_failed}${lf}"; }
+function test_missed() { printf "${test_missed}${lf}"; }
+function test_skipped()        { printf "${test_skipped}${lf}"; }
+function test_dead()   { printf "${test_dead}${lf}"; }
+function test_unused() { printf "${test_unused}${lf}"; }
+function test_unknown  { printf "${test_unknown}${lf}"; }
+function test_start()  { syslog "${test_start}"; }
+function test_end()    { syslog "${test_end}"; }
+
+# set output to ASCII (without colors)
+function setOutputASCII()
+{
+lf="\n"
+spacefill="..."
+
+begin_bold=""
+begin_black=""
+begin_red=""
+begin_green=""
+begin_yellow=""
+begin_blue=""
+begin_magenta=""
+begin_cyan=""
+begin_white=""
+
+end_bold=""
+end_black=""
+end_red=""
+end_green=""
+end_yellow=""
+end_blue=""
+end_magenta=""
+end_cyan=""
+end_white=""
+
+set_test
+}
+
+# set output to ASCII with ANSI colors
+function setOutputColor()
+{
+local esc=`echo -en "\033"`
+local normal="${esc}[0m" # unsets color to term's fg color
+lf="\n"
+spacefill=`echo -en "\015${esc}[${COLUMNS}C${esc}[10D"`
+
+begin_bold="${esc}[0;1m"
+begin_black="${esc}[0;30m"
+begin_red="${esc}[0;31m"
+begin_green="${esc}[0;32m"
+begin_yellow="${esc}[0;33m"
+begin_blue="${esc}[0;34m"
+begin_magenta="${esc}[0;35m"
+begin_cyan="${esc}[0;36m"
+begin_white="${esc}[0;37m"
+
+end_bold="$normal"
+end_black="$normal"
+end_red="$normal"
+end_green="$normal"
+end_yellow="$normal"
+end_blue="$normal"
+end_magenta="$normal"
+end_cyan="$normal"
+end_white="$normal"
+
+set_test
+}
+
+# set output to HTML
+function setOutputHTML()
+{
+local ENDFONT="</font>"
+lf="<br />\n"
+spacefill="&nbsp;&nbsp;&nbsp;"
+is_html=1
+
+begin_bold="<b>"
+begin_black="<font color=\"black\">"
+begin_red="<font color=\"red\">"
+begin_green="<font color=\"green\">"
+begin_yellow="<font color=\"yellow\">"
+begin_blue="<font color=\"blue\">"
+begin_magenta="<font color=\"magenta\">"
+begin_cyan="<font color=\"cyan\">"
+begin_white="<font color=\"white\">"
+
+end_bold="</b>"
+end_black="$ENDFONT"
+end_red="$ENDFONT"
+end_green="$ENDFONT"
+end_yellow="$ENDFONT"
+end_blue="$ENDFONT"
+end_magenta="$ENDFONT"
+end_cyan="$ENDFONT"
+end_white="$ENDFONT"
+
+set_test
+}
+
+function print_error()
+{
+       printf "${begin_red}Error${end_red}: %s ${lf}" "$*"
+}
+
+function print_warning()
+{
+       printf "${begin_magenta}Warning${end_magenta}: %s ${lf}" "$*"
+}
+
+function print_info()
+{
+       printf "${begin_blue}Info${end_blue}: %s ${lf}" "$*"
+}
+
+function print_newline()
+{
+       printf "${lf}"
+}
+
+function syslog() 
+{
+        local tmp="`date +'%b %d %H:%M:%S'` `hostname` $progname"
+       printf "${begin_bold}${tmp}${end_bold}: %s ${lf}" "$*"
+}
+
+function dprintf()
+{
+       if [ $DEBUG -gt 0 ]; then 
+               printf "%s${lf}" "$*"
+       fi
+}
+
+# by default set output to color if possible
+if test -t 1 -a "$TERM" != "raw" -a "$TERM" != "dumb" && stty size <&1 > /dev/null 2>&1 ; then
+       setOutputColor
+else
+       setOutputASCII
+fi
index cf1adc8..434b88c 100755 (executable)
@@ -1,3 +1,5 @@
+#ident "$Header$
+
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netdb.h>
 
 #define BUFFSIZE 32
-void Die(char *mess) {
-perror(mess); 
-exit(1); }
-int main(int argc, char *argv[]) {
-int sock;
-struct hostent *hip;
-char *adrIPp;
-struct in_addr adrIP;
-struct sockaddr_in echoserver;
-char buffer[BUFFSIZE];
-unsigned int echolen;
-int received = 0;
-if (argc != 3) {
-           fprintf(stderr, "USAGE: TCPecho <server_ip> <port>\n");
-           exit(1);
-            }
-//conversion from DNS to IPv4
-if((hip=gethostbyname(argv[1]))==NULL)
+void
+Die (char *mess)
 {
-printf("Erreur avec gethostbyname\n");
-//           exit(1);
+  perror (mess);
+  exit (1);
 }
-adrIP.s_addr=*(int *)hip->h_addr;
-adrIPp =(char *)inet_ntoa(adrIP);
+
+int
+main (int argc, char *argv[])
+{
+  int sock;
+  struct hostent *hip;
+  char *adrIPp;
+  struct in_addr adrIP;
+  struct sockaddr_in echoserver;
+  char buffer[BUFFSIZE];
+  unsigned int echolen;
+  int received = 0;
+  if (argc != 3)
+    {
+      fprintf (stderr, "USAGE: TCPecho <server_ip> <port>\n");
+      exit (1);
+    }
+//conversion from DNS to IPv4
+  if ((hip = gethostbyname (argv[1])) == NULL)
+    {
+      printf ("Erreur avec gethostbyname\n");
+//           exit(1);
+    }
+  adrIP.s_addr = *(int *) hip->h_addr;
+  adrIPp = (char *) inet_ntoa (adrIP);
 /* Create the TCP socket */
-if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
-              Die("Failed to create socket");
-            }
+  if ((sock = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
+    {
+      Die ("Failed to create socket");
+    }
 /* Construct the server sockaddr_in structure */
-memset(&echoserver, 0, sizeof(echoserver));       /* Clear struct */
-echoserver.sin_family = AF_INET;                  /* Internet/IP */
-echoserver.sin_addr.s_addr = inet_addr(adrIPp);  /* IP address */
-echoserver.sin_port = htons(atoi(argv[2]));       /* server port */
-printf("Connecting a socket with : %s,%s", adrIPp,argv[2]);
+  memset (&echoserver, 0, sizeof (echoserver));        /* Clear struct */
+  echoserver.sin_family = AF_INET;     /* Internet/IP */
+  echoserver.sin_addr.s_addr = inet_addr (adrIPp);     /* IP address */
+  echoserver.sin_port = htons (atoi (argv[2]));        /* server port */
+  printf ("Connecting to: %s:%s\n", adrIPp, argv[2]);
 /* Establish connection */
-if (connect(sock,
-           (struct sockaddr *) &echoserver,
-            sizeof(echoserver)) < 0) {
-              Die("Failed to connect with server");
-            }
-else 
-       {
-       shutdown(sock,2);
-       printf(" [OK]\n");
-       exit(0);
-       }
+  if (connect (sock,
+              (struct sockaddr *) &echoserver, sizeof (echoserver)) < 0)
+    {
+      Die ("Failed to connect with server");
+    }
+  else
+    {
+      shutdown (sock, 2);
+      printf (" [OK]\n");
+      exit (0);
+    }
 }