guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

advice needed: ping and guile


From: David Pirotte
Subject: advice needed: ping and guile
Date: Sat, 15 Sep 2001 03:10:37 +0200

Hi,

I need to know if a portable computer is connected to the network
(if it can reach a host for which I know both the name and the IP)

not being very knowledgeable with respect to network and not knowing
yet all guile resources, I have written the following simple piece of
code:

        ;; #!/usr/local/bin/guile -s
        ;; !#
        
        (define-module (alto net gping)
          ;; from distribution
          :use-module (ice-9 format)
          :use-module (ice-9 rdelim)
          :use-module (ice-9 popen)
          :use-module (srfi srfi-13)
          ;; from alto
          )
        
        (export gping)
        
        (define (gping host)
          (let ((p (open-input-pipe
                    (format #f "ping -c 1 -w 1 ~A" host))))
            (do ((line (read-line p)))
                ((eof-object? line))
              (format #t "~S~%" (string-tokenize line #\Space))
              (set! line (read-line p)))
            (close-pipe p)
            ))

I notice that the gping returns 0 if ping could reach the host and 256
if not. I was going to analyse packets sent and packets received to
detect, but :

        - is this code ok or do we have any builtin better (faster)
          way to detect wether we can reach another host?

        - if I have to proceed with my code, is my ping command ok?
        - can I rely on the integer returned:

                (if (= (gping <host>) 0) #t #f)

        - can I get the return code 'reliably', binding it in a let
          and use it in the function gping, how?

Many thanks for some advice
David



reply via email to

[Prev in Thread] Current Thread [Next in Thread]