mirror of
git://git.savannah.gnu.org/guix/dhcp.git
synced 2023-12-14 05:22:52 +01:00
56 lines
1.5 KiB
Scheme
56 lines
1.5 KiB
Scheme
#!/usr/local/bin/guile \
|
|
-e main -s
|
|
coding: utf-8
|
|
!#
|
|
|
|
(add-to-load-path (string-append (dirname (current-filename))
|
|
"/.."))
|
|
|
|
; DHCP client module
|
|
(define-module (dhcp client))
|
|
|
|
(use-modules (dhcp dhcp)
|
|
(ice-9 getopt-long)
|
|
(dhcp messages))
|
|
|
|
(define *help-message* "\
|
|
dhcp-client [options]
|
|
-v, --version Display version
|
|
-h, --help Display this help
|
|
")
|
|
|
|
(define (main args)
|
|
"Process command-line arguments and run the client"
|
|
(let* ((option-spec '((version (value #f))
|
|
(help (single-char #\h))
|
|
(four (single-char #\4) (value #t))
|
|
(six (single-char #\6))
|
|
(verbose)
|
|
(release)
|
|
(foreground (single-char #\d))
|
|
(continue-running (single-char #\w))
|
|
(no-wait)
|
|
(stop (single-char #\x))
|
|
(port (single-char #\p) (value #t))
|
|
(server-addr (single-char #\s) (value #t))))
|
|
(options (getopt-long args option-spec))
|
|
(help-wanted (option-ref options 'help #f))
|
|
(version-wanted (option-ref options 'version #f)))
|
|
(if (or version-wanted help-wanted)
|
|
(begin
|
|
(if version-wanted
|
|
(display "dhcp-client version 0.1\n"))
|
|
(if help-wanted
|
|
(display *help-message*)))
|
|
(begin
|
|
(display "Hello, World!") (newline)))))
|
|
|
|
; Seed the random state.
|
|
(set! *random-state* (random-state-from-platform))
|
|
|
|
(define (generate-xid)
|
|
"Generate a random 32-bit number to be used as a transaction id."
|
|
(random (expt 2 32)))
|
|
|
|
; Generate initial transaction id.
|
|
(define xid (generate-xid))
|