(module host-serial mzscheme
        (require "mac.scm")
        (provide host-primary-serial-number
        ;;=head1 Host bound Serial Numbers
        ;;This module provides a host based serial number. The serial numbers are
        ;;generated from hardware serial numbers. E.g. mac addresses or harddisk
        ;;serial numbers. No assumptions can be made about the serial numbers, although
        ;;they may currently look suspiciously like mac adresses ;-).
        ;;Host Serial Numbers stay the same while the hardware stays the same.
        ;;There can be several host serial numbers at the same time, which can
        ;;be retrieved through C<(host-possible-serial-numbers>.
        ;;=head2 API
        ;;=head3 C<(host-primary-serial-number) : string>
        ;;Returns the current primary serial number for this host, or
        ;;#f is no serial number can be determined.
        ;;=head3 C<(host-serial-number . previous) : string>
        ;;Returns C<(previous)>, if C<(previous)> is part
        ;;of the possible serial numbers.
        ;;Returns C<(host-primary-serial-number)> if previous has not
        ;;been given.
        ;;Returns C<(host-primary-serial-number)> if previous cannot
        ;;be found in the possible serial numbers.
        ;;=head3 C<(valid-serial-number-for-this-host? N) : boolean>
        ;;Returns #t, if the given number N is part of the possible
        ;;serial numbers for this host; #f otherwise.
        ;;=head3 C<(host-possible-serial-numbers) : list of string>
        ;;Returns all possible serial numbers of this host, or the
        ;;empty list if no serial numbers can be determined.
        (define (host-primary-serial-number)
        (define (host-serial-number . previous)
          (if (null? previous)
              (letrec ((f (lambda (N)
                            (if (null? N) 
                                (if (string-ci=? (car previous) (car N))
                                    (car previous)
                                    (f (cdr N)))))))
                (f (host-possible-serial-numbers)))))
        (define (host-possible-serial-numbers)
        (define (valid-serial-number-for-this-host? N)
          (mac-address-of-this-host? (format "~a" N)))